Hadoop2.6.5测试
1、新建文件
-rw-r--r-- 1 hadoop supergroup 23 2017-11-29 10:19 /test/a.log
-rw-r--r-- 1 hadoop supergroup 25 2017-11-29 10:25 /test/b.log
2、未开启删除自动转移到垃圾箱
[hadoop@spark1 ~]$ hadoop fs -rm -r /test/a.log
17/11/29 10:37:01 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 0 minutes, Emptier interval = 0 minutes.
Deleted /test/a.log
直接删除,不可找回。
3、开启删除自动转移到垃圾箱功能,core-site.xml设置参数:
fs.trash.interval
10
4、删除文件测试 (不会释放空间)
[hadoop@spark1 hadoop-2.6.5]$ hadoop fs -rm -r /test/b.log
17/11/29 11:05:19 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 10 minutes, Emptier interval = 0 minutes.
Moved: 'hdfs://spark1:9000/test/b.log' to trash at: hdfs://spark1:9000/user/hadoop/.Trash/Current
[hadoop@spark1 hadoop-2.6.5]$ hadoop fs -ls /user/hadoop/.Trash/Current/test
Found 1 items
-rw-r--r-- 1 hadoop supergroup 25 2017-11-29 10:25 /user/hadoop/.Trash/Current/test/b.log
文件找回:
[hadoop@spark1 hadoop-2.6.5]$ hadoop fs -mv /user/hadoop/.Trash/Current/test/b.log /test/
[hadoop@spark1 hadoop-2.6.5]$ hadoop fs -mv /user/hadoop/.Trash/Current/test/b.log /test/
[hadoop@spark1 hadoop-2.6.5]$ hadoop fs -ls /test
Found 1 items
-rw-r--r-- 1 hadoop supergroup 25 2017-11-29 10:25 /test/b.log
删除文件夹:
[hadoop@spark1 hadoop-2.6.5]$ hadoop fs -rm -r /input
Moved: 'hdfs://spark1:9000/input' to trash at: hdfs://spark1:9000/user/hadoop/.Trash/Current
[hadoop@spark1 hadoop-2.6.5]$ hadoop fs -ls /user/hadoop/.Trash/Current/input
Found 1 items
-rw-r--r-- 1 hadoop supergroup 6 2017-11-29 13:41 /user/hadoop/.Trash/Current/input/a.txt
文件夹找回:
[hadoop@spark1 hadoop-2.6.5]$ hadoop fs -mv /user/hadoop/.Trash/Current/input /
[hadoop@spark1 hadoop-2.6.5]$ hadoop fs -ls /input
Found 1 items
-rw-r--r-- 1 hadoop supergroup 6 2017-11-29 13:41 /input/a.txt
5、直接删除文件测试
hadoop fs -rm -r /user/hadoop/.Trash/Current/test/b.log
hadoop fs -rm -r -skipTrash /test/b.log
[hadoop@spark1 hadoop-2.6.5]$ hadoop fs -ls /user/hadoop/.Trash/171129111000/test
没有内容,文件删除,不可恢复,hdfs空间释放.
Hadoop2.4.0测试
1、建文件目录
[hadoop@spark1 hadoop2.4]$ hadoop fs -mkdir /input
[hadoop@spark1 hadoop2.4]$ hadoop fs -copyFromLocal test.txt /input
[hadoop@spark1 hadoop2.4]$ hadoop fs -copyFromLocal test.txt /input
Found 1 items
-rw-r--r-- 1 hadoop supergroup 12 2017-11-29 11:46 /input/test.txt
开启删除自动转移到垃圾箱功能,core-site.xml设置参数:
fs.trash.interval
10
2,连文件夹一块删除测试
[hadoop@spark1 hadoop2.4]$ hadoop fs -rm -r /input
17/11/29 11:47:54 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 10 minutes, Emptier interval = 0 minutes.
Moved: 'hdfs://spark1:9000/input' to trash at: hdfs://spark1:9000/user/hadoop/.Trash/Current
文件找回:
[hadoop@spark1 hadoop2.4]$ hadoop fs -ls /user/hadoop/.Trash/171129115000/input
-rw-r--r-- 1 hadoop supergroup 12 2017-11-29 11:46 /user/hadoop/.Trash/171129115000/input/test.txt
[hadoop@spark1 hadoop2.4]$ hadoop fs -mv /user/hadoop/.Trash/171129115000/input/test.txt /input
[hadoop@spark1 hadoop2.4]$ hadoop fs -ls /input
-rw-r--r-- 1 hadoop supergroup 12 2017-11-29 11:46 /input/test.txt
3,只删除文件
[hadoop@spark1 hadoop2.4]$ hadoop fs -rm -r /input/test.txt
[hadoop@spark1 hadoop2.4]$ hadoop fs -ls /user/hadoop/.Trash/Current
Found 1 items
drwx------ - hadoop supergroup 0 2017-11-29 11:59 /user/hadoop/.Trash/Current/input
文件找回:
[hadoop@spark1 hadoop2.4]$ hadoop fs -mv /user/hadoop/.Trash/Current/input/test.txt /input
4,彻底删除,文件无法找回,HDFS空间释放出来。
[hadoop@spark1 hadoop2.4]$ hadoop fs -rm -r -skipTrash /input/test.txt
[hadoop@spark1 hadoop2.4]$ hadoop fs -ls /user/hadoop/.Trash
返回空
综上所述:
1,hadoop2.4,2.6均支持开启删除自动转移到垃圾箱功能
2,若未设置和 -skipTrash则是完全彻底删除,文件不可恢复
3,hadoop2.4删除文件夹的时候会在垃圾站生成当天的一个时间戳文件夹,而2.6没有
4,在设置的时间里面可以找回已经删除的文件,时间过后文件不可恢复
5,文件删除不释放空间,除非彻底删除。
网友评论