gywtzh0 2019-06-27
前言:
[hadoop@hadoop000 ~]$ hdfs dfs -put test.log / [hadoop@hadoop000 ~]$ hdfs dfs -ls / Found 3 items -rw-r--r-- 1 hadoop supergroup 34 2018-05-23 16:49 /test.log drwx------ - hadoop supergroup 0 2018-05-19 15:48 /tmp drwxr-xr-x - hadoop supergroup 0 2018-05-19 15:48 /user # 删除test.log 注意提示 [hadoop@hadoop000 ~]$ hdfs dfs -rm -r /test.log Deleted /test.log # 重新查看 发现test.log被删除 [hadoop@hadoop000 ~]$ hdfs dfs -ls / Found 2 items drwx------ - hadoop supergroup 0 2018-05-19 15:48 /tmp drwxr-xr-x - hadoop supergroup 0 2018-05-19 15:48 /user
[hadoop@hadoop000 hadoop]$ pwd /opt/software/hadoop-2.8.1/etc/hadoop # 增加fs.trash参数配置 开启trash(进程不需重启) [hadoop@hadoop000 hadoop]$ vi core-site.xml <property> <name>fs.trash.interval</name> <value>1440</value> </property> <property> <name>fs.trash.checkpoint.interval</name> <value>1440</value> </property> # fs.trash.interval是在指在这个回收周期之内,文件实际上是被移动到trash的这个目录下面,而不是马上把数据删除掉。等到回收周期真正到了以后,hdfs才会将数据真正删除。默认的单位是分钟,1440分钟=60*24,刚好是一天;fs.trash.checkpoint.interval则是指垃圾回收的检查间隔,应该是小于或者等于fs.trash.interval。 # 参考官方文档:http://hadoop.apache.org/docs/r2.8.4/hadoop-project-dist/hadoop-common/core-default.xml [hadoop@hadoop000 ~]$ hdfs dfs -put test.log / [hadoop@hadoop000 ~]$ hdfs dfs -ls / Found 3 items -rw-r--r-- 1 hadoop supergroup 34 2018-05-23 16:54 /test.log drwx------ - hadoop supergroup 0 2018-05-19 15:48 /tmp drwxr-xr-x - hadoop supergroup 0 2018-05-19 15:48 /user # 删除test.log 注意提示的不同 [hadoop@hadoop000 ~]$ hdfs dfs -rm -r /test.log 18/05/23 16:54:55 INFO fs.TrashPolicyDefault: Moved: 'hdfs://192.168.6.217:9000/test.log' to trash at: hdfs://192.168.6.217:9000/user/hadoop/.Trash/Current/test.log # 发现删除的文件在回收站里 [hadoop@hadoop000 ~]$ hdfs dfs -ls /user/hadoop/.Trash/Current Found 1 items -rw-r--r-- 1 hadoop supergroup 34 2018-05-23 16:54 /user/hadoop/.Trash/Current/test.log # 恢复误删除的文件 [hadoop@hadoop000 ~]$ hdfs dfs -mv /user/hadoop/.Trash/Current/test.log /test.log [hadoop@hadoop000 ~]$ hdfs dfs -ls / Found 3 items -rw-r--r-- 1 hadoop supergroup 34 2018-05-23 16:54 /test.log drwx------ - hadoop supergroup 0 2018-05-19 15:48 /tmp drwxr-xr-x - hadoop supergroup 0 2018-05-19 15:48 /user