查看文件块数命令:hdfs fsck / -blocks
HDFS垃圾回收站, 默认是0,单位是分钟,实验设置为1天即1440.
core-site.xml
<property>
<name>fs.trash.interval</name>
<value>1440</value>
</property>
在线上把垃圾回收站的时间调大到7天
定时执行脚本,shell开发删除回收站
清理垃圾回收站:
hdfs dfs -ls /user/root/.Trash
hdfs dfs -rm -r /user/root/.Trash/190815070000
恢复数据:
实验:
#删除一个文件夹
[root@oldboy-node101 ~]# hdfs dfs -rm -r /tmp/logs/root/logs/logs
19/06/17 20:29:08 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 1440 minutes, Emptier interval = 0 minutes.
Moved: 'hdfs://oldboy-node101:9000/tmp/logs/root/logs/logs' to trash at: hdfs://oldboy-node101:9000/user/root/.Trash/Current
#查看是否已经在回收站
[root@oldboy-node101 ~]# hdfs dfs -ls /user/root/.Trash/Current/tmp/logs/root/logs
Found 1 items
drwx------ - root supergroup 0 2019-06-17 19:34 /user/root/.Trash/Current/tmp/logs/root/logs/logs
#恢复,移动回原位置即可
hdfs dfs -mv /user/root/.Trash/Current/tmp/logs/root/logs /tmp/logs/root/logs
#手动永久删除
hdfs dfs -rm -r /user/root/.Trash/Current/tmp/logs/root/logs/logs