HDFS回收站功能

  • 3.1.2: https://hadoop.apache.org/docs/r3.1.2/hadoop-project-dist/hadoop-common/core-default.xml
  • 2.7.2: https://hadoop.apache.org/docs/r2.7.2/hadoop-project-dist/hadoop-common/core-default.xml

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

fs.trash.interval

0  

Number of minutes after which the checkpoint gets deleted. If zero, the trash feature is disabled. This option may be configured both on the server and the client. If trash is disabled server side then the client side configuration is checked. If trash is enabled on the server side then the value configured on the server is used and the client configuration value is ignored.

删除检查点后的分钟数。如果为零,则禁用垃圾功能。可以在服务器和客户机上配置此选项。如果禁用了垃圾桶服务器端,则检查客户端配置。如果在服务器端启用了垃圾桶,那么将使用在服务器上配置的值,并忽略客户机配置值。

fs.trash.checkpoint.interval

0

Number of minutes between trash checkpoints. Should be smaller or equal to fs.trash.interval. If zero, the value is set to the value of fs.trash.interval. Every time the checkpointer runs it creates a new checkpoint out of current and removes checkpoints created more than fs.trash.interval minutes ago.

垃圾检查点之间的分钟数。应小于或等于fs.trash.interval。如果为零,则该值设置为fs.trash.interval的值。每次检查点运行时,它都会在当前之外创建一个新的检查点,并删除几分钟前创建的超过fs.trash.interval的检查点。

fs.trash.interval是在指在这个回收周期之内,文件实际上是被移动到trash的这个目录下面,而不是马上把数据删除掉。等到回收周期真正到了以后,hdfs才会将数据真正删除。默认的单位是分钟。 
fs.trash.checkpoint.interval则是指垃圾回收的检查间隔,应该是小于或者等于fs.trash.interval。
 


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

2.启用回收站

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



   fs.trash.interval
3600

注:fs.trash.checkpoint.interval 如果为零,则将该值设置为fs.trash.interval的值。 每次检查指针运行时, 它都会从当前创建一个新的检查点,并删除比fs.trash.interval更早创建的检查点。

群发:

 [atguigu@hadoop102 hadoop]$ xsync core-site.xml 

从新启动集群:

删除文件: 

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -rm /user/atguigu/input/xiaopan.txt
19/02/21 23:50:16 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 1 minutes, Emptier interval = 0 minutes.
Moved: 'hdfs://hadoop102:9000/user/atguigu/input/xiaopan.txt' to trash at: hdfs://hadoop102:9000/user/atguigu/.Trash/Current

3.查看回收站

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

注:路径会自动创建的。

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

HDFS回收站功能_第1张图片

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



  hadoop.http.staticuser.user
  yuanyu

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

Trash trash = New Trash(conf);

trash.moveToTrash(path);

6.    恢复回收站数据

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -mv /user/atguigu/.Trash/Current/user/atguigu/input    /user/atguigu/input

7.    清空回收站(跟Windows里面的不一样,它是打包,文件名为时间戳,时间到了依然删除)

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

HDFS回收站功能_第2张图片

8.    使用skipTrash选项删除文件,该选项不会将文件发送到垃圾箱。它将从HDFS中完全删除。

[atguigu@hadoop102 hadoop-2.7.2]$  hadoop fs -rm -r -skipTrash  /...


参考:https://www.jianshu.com/p/1827431d4eb5 

你可能感兴趣的:(大数据_Hadoop)