delete partitions folders in hdfs older than N days

隐身守侯 提交于 2019-12-04 06:10:01

问题


I want to delete the partition folders which are older than N days.

The below command gives the folders which are exactly 50 days ago. I want the list of all folders which are less than 50 days

hadoop fs -ls /data/publish/DMPD/VMCP/staging/tvmcpr_usr_prof/chgdt=`date --date '50 days ago' +\%Y-\%m-\%d`

回答1:


You can try with solr hdfsfindtool:

hadoop jar /opt/cloudera/parcels/CDH/lib/solr/contrib/mr/search-mr-job.jar org.apache.solr.hadoop.HdfsFindTool -find /data/publish/DMPD/VMCP/staging/tvmcpr_usr_prof -mtime +50 | xargs hdfs dfs -rm -r -skipTrash



回答2:


It can be done with a bash script

today=`date +'%s'`
hdfs dfs -ls /data/publish/DMPD/VMCP/staging/tvmcpr_usr_prof/ | grep "^d" | while read line ; do 
dir_date=$(echo ${line} | awk '{print $6}')
difference=$(( ( ${today} - $(date -d ${dir_date} +%s) ) / ( 24*60*60 ) ))
filePath=$(echo ${line} | awk '{print $8}')

if [ ${difference} -lt 50 ]; then
    echo "${filepath}"
fi
done


来源:https://stackoverflow.com/questions/43889792/delete-partitions-folders-in-hdfs-older-than-n-days

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!