开启回收站功能,可以将删除的文件在不超时的情况下,恢复原书记,起到防止误删除、备份等作用。 一.开启回收站功能参数说明 1、默认值fs.trash.interval=0,0表示禁用回收站;其他值表示设置文件的存活时间。 2、默认值fs.trash.checkpoint.interval=0,检查回收站的间隔时间。如果该值为0,则该值设置和fs.trash.interval的参数值相等。 3、要求fs.trash.checkpoint.interval<=fs.trash.interval。 回收站工作机制:

启用回收站 修改 core-site.xml,配置垃圾回收时间为 1 分钟。 fs.trash.interval 1 查看回收站 回收站在集群中的路径:/user/local/.Trash/…. 修改访问垃圾回收站用户名称 进入垃圾回收站用户名称,默认是 dr.who,修改为 atguigu 用户 [core-site.xml] hadoop.http.staticuser.user atguigu 通过程序删除的文件不会经过回收站,需要调用 moveToTrash()才进入回收站 Trash trash = New Trash(conf); trash.moveToTrash(path); 恢复回收站数据 [hadoop@hb hadoop-2.7.2]$ hadoop fs -mv /user/atguigu/.Trash/Current/user/local/input /user/local/input 清空回收站 [hadoop@hb hadoop-2.7.2]$ hadoop fs -expunge