前言:shell
[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