kution 发表于 2018-10-28 13:08:52

Hadoop回收站及fs.trash参数详解

$ pwd  /opt/software/hadoop-2.8.1/etc/hadoop
  # 增加fs.trash参数配置 开启trash(进程不需重启)
  $ vi core-site.xml
  
  fs.trash.interval
  1440
  
  
  fs.trash.checkpoint.interval
  1440
  
  # 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
  $ hdfs dfs -put test.log /
  $ 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 注意提示的不同
  $ 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
  # 发现删除的文件在回收站里
  $ 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
  # 恢复误删除的文件
  $ hdfs dfs -mv /user/hadoop/.Trash/Current/test.log /test.log
  $ 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

页: [1]
查看完整版本: Hadoop回收站及fs.trash参数详解