介紹:
Hadoop回收站trash,默認是關閉的。?
和Linux系統的回收站設計一樣,HDFS會為每一個用戶創建一個回收站目錄:/user/用戶名/.Trash/,每一個被用戶通過Shell刪除的文件/目錄,在系統回收站中都一個周期,也就是當系統回收站中的文件/目錄在一段時間之后沒有被用戶回復的話,HDFS就會自動的把這個文件/目錄徹底刪除,之后,用戶就永遠也找不回這個文件/目錄了。
開啟方式:
配置:在每個節點(不僅僅是主節點)上添加配置 core-site.xml,增加如下內容
<property>
? ? <name>fs.trash.interval</name>
? ? <value>1440</value>
</property>
注解:
1、1440=24小時*60分鐘,一天。一天后刪除回收站里的文件。
2、重啟hdfs生效,建議第一次配置時就配置好
演示:
1、新建文件夾:
[hadoop@hello110 ~]$ hdfs dfs -ls /testdata
drwxr-xr-x ? - hadoop supergroup ? ? ? ? ?0 2016-08-14 22:40 /testdata/a123
[hadoop@hello110 ~]$ hdfs dfs -mkdir /testdata/b1112
[hadoop@hello110 ~]$ hdfs dfs -ls /testdata
drwxr-xr-x ? - hadoop supergroup ? ? ? ? ?0 2016-08-14 22:40 /testdata/a123
drwxr-xr-x ? - hadoop supergroup ? ? ? ? ?0 2016-08-14 23:50 /testdata/b1112
drwxr-xr-x ? - hadoop supergroup ? ? ? ? ?0 2016-08-14 23:50 /testdata/b1112
2、刪除剛建的文件夾:
[hadoop@hello110 ~]$ hdfs dfs -rm -r /testdata/b1112
Moved: 'hdfs://hello110:9000/testdata/b1112' to trash at: hdfs://hello110:9000/user/hadoop/.Trash/Current
3、查看垃圾回收站:
[hadoop@hello110 ~]$ hdfs dfs -ls -R /user/hadoop/.Trash/Current
drwx------ ? - hadoop supergroup ? ? ? ? ?0 2016-08-14 23:52 /user/hadoop/.Trash/Current/testdata
drwxr-xr-x ? - hadoop supergroup ? ? ? ? ?0 2016-08-14 23:50 /user/hadoop/.Trash/Current/testdata/b1112
drwxr-xr-x ? - hadoop supergroup ? ? ? ? ?0 2016-08-14 23:50 /user/hadoop/.Trash/Current/testdata/b1112
4、恢復剛刪除的文件夾:
[hadoop@hello110 ~]$ hdfs dfs -mv ?/user/hadoop/.Trash/Current/testdata/b1112 /testdata/b1112
5、查看恢復的文件夾:
[hadoop@hello110 ~]$ hdfs dfs -ls /testdata
drwxr-xr-x ? - hadoop supergroup ? ? ? ? ?0 2016-08-14 22:40 /testdata/a123
drwxr-xr-x ? - hadoop supergroup ? ? ? ? ?0 2016-08-14 23:50 /testdata/b1112
drwxr-xr-x ? - hadoop supergroup ? ? ? ? ?0 2016-08-14 23:50 /testdata/b1112
6、清空回收站:
[hadoop@hello110 ~]$ hdfs dfs -rm -r /user/hadoop/.Trash/
Deleted /user/hadoop/.Trash
Deleted /user/hadoop/.Trash