hadoop文件误删恢复(官网自带回收站设置)

https://hadoop.apache.org/docs/r2.7.4/hadoop-project-dist/hadoop-common/core-default.xml

官网的配置释义

hadoop文件误删恢复(官网自带回收站设置)

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.

翻译:

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

配置文件/etc/hadoop/core-site.xml,在其中添加如下信息:
<property>
    <name>fs.trash.interval</name>
    <value>10080</value>
    <description>
      Number of minutes between trash checkpoints. If zero, the trash feature is disabled.
    </description>
</property>

回收站时间为一周(超过则用这个方法无法恢复)
其中10080代表分钟数,即代表删除的文件或目录在".Trash"(回收站)中保留的时间,可自行设置。保存即可。
hdfs dfs -lsr 时暂时看不到.Trash,再删除某个文件或者目录之后, 再次用lsr即可看到所在目录下的回收站.Trash已经建好:

hadoop文件误删恢复(官网自带回收站设置)

上述可以看见删除的文件

如果恢复可以找到对应删除的文件执行

hdfs dfs -mv /hdfs目录/.Trash/对应的删除文件  /hdfs恢复路径