尚硅谷大数据技术之Hadoop(HDFS)第7章 HDFS 2.X新特性

7.3 回收站

开启回收站功能,可以将删除的文件在不超时的情况下,恢复原数据,起到防止误删除、备份等作用。

1.回收站参数设置及工作机制

2.启用回收站

修改core-site.xml,配置垃圾回收时间为1分钟。

<property>

   <name>fs.trash.interval</name>

<value>1</value>

</property>

3.查看回收站

回收站在集群中的路径:/user/atguigu/.Trash/….

4.修改访问垃圾回收站用户名称

进入垃圾回收站用户名称,默认是dr.who,修改为atguigu用户

[core-site.xml]

<property>

  <name>hadoop.http.staticuser.user</name>

  <value>atguigu</value>

</property>

  1. 5. 通过程序删除的文件不会经过回收站,需要调用moveToTrash()才进入回收站

Trash trash = New Trash(conf);

trash.moveToTrash(path);

  1. 恢复回收站数据

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -mv

/user/atguigu/.Trash/Current/user/atguigu/input    /user/atguigu/input

  1. 清空回收站

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -expunge