【HDFS】hdfs如何打开回收站机制trash,恢复删除的文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://xxlcube.blog.csdn.net/article/details/44081977

在hdfs中,默认的文件删除保留的时间是0,也就是没有保留删除的文件,删除即丢失


那么如果你想启用hdfs的回收站机制,在删除文件后,希望多久之后,文件才消失,因为这个过程中万一你想来恢复文件呢


<property>
          <name>fs.trash.interval</name>
          <value>1440</value>
    </property>

将以上配置添加到core-site.xml中即可,1440表示删除的文件保存1440分钟,在这个期间你都可以恢复你的文件


[root@com22 bin]# sh hdfs dfs -ls -R /flume/events/2015/01/28/15/55
-rw-r--r--   3 root supergroup      12207 2015-01-28 15:56 /flume/events/2015/01/28/15/55/cmcc.1422431701282
[root@com22 bin]# sh hdfs dfs -rm /flume/events/2015/01/28/15/55/cmcc.1422431701282
15/03/05 14:28:00 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 1440 minutes, Emptier interval = 0 minutes.
Moved: 'hdfs://com22.authentication:9000/flume/events/2015/01/28/15/55/cmcc.1422431701282' to trash at: hdfs://com22.authentication:9000/user/root/.Trash/Current
[root@com22 bin]# 

入上图所示,设置回收站之后,每当你删除文件时,都会打印该文件被删除后放到哪里去了,如果你想恢复,mv就可以了

整个过程如下:

[root@com22 bin]# sh hdfs dfs -ls -R /flume/events/2015/01/28/15/55
[root@com22 bin]# sh hdfs dfs -ls -R /user/root/.Trash/Current
drwx------   - root supergroup          0 2015-03-05 14:28 /user/root/.Trash/Current/flume
drwx------   - root supergroup          0 2015-03-05 14:28 /user/root/.Trash/Current/flume/events
drwx------   - root supergroup          0 2015-03-05 14:28 /user/root/.Trash/Current/flume/events/2015
drwx------   - root supergroup          0 2015-03-05 14:28 /user/root/.Trash/Current/flume/events/2015/01
drwx------   - root supergroup          0 2015-03-05 14:28 /user/root/.Trash/Current/flume/events/2015/01/28
drwx------   - root supergroup          0 2015-03-05 14:28 /user/root/.Trash/Current/flume/events/2015/01/28/15
drwx------   - root supergroup          0 2015-03-05 14:28 /user/root/.Trash/Current/flume/events/2015/01/28/15/55
-rw-r--r--   3 root supergroup      12207 2015-01-28 15:56 /user/root/.Trash/Current/flume/events/2015/01/28/15/55/cmcc.1422431701282
[root@com22 bin]# sh hdfs dfs -mv /user/root/.Trash/Current/flume/events/2015/01/28/15/55/cmcc.1422431701282 /flume/events/2015/01/28/15/55
[root@com22 bin]# sh hdfs dfs -ls -R /user/root/.Trash/Current
drwx------   - root supergroup          0 2015-03-05 14:28 /user/root/.Trash/Current/flume
drwx------   - root supergroup          0 2015-03-05 14:28 /user/root/.Trash/Current/flume/events
drwx------   - root supergroup          0 2015-03-05 14:28 /user/root/.Trash/Current/flume/events/2015
drwx------   - root supergroup          0 2015-03-05 14:28 /user/root/.Trash/Current/flume/events/2015/01
drwx------   - root supergroup          0 2015-03-05 14:28 /user/root/.Trash/Current/flume/events/2015/01/28
drwx------   - root supergroup          0 2015-03-05 14:28 /user/root/.Trash/Current/flume/events/2015/01/28/15
drwx------   - root supergroup          0 2015-03-05 14:31 /user/root/.Trash/Current/flume/events/2015/01/28/15/55
[root@com22 bin]# sh hdfs dfs -ls -R /flume/events/2015/01/28/15/55
-rw-r--r--   3 root supergroup      12207 2015-01-28 15:56 /flume/events/2015/01/28/15/55/cmcc.1422431701282
[root@com22 bin]# 


展开阅读全文

没有更多推荐了,返回首页