HDFS垃圾回收站的配置及使用方法
本篇内容介绍了“HDFS垃圾回收站的配置及使用方法”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
HDFS会为每一个用户创建一个回收站目录:/user/用户名/.Trash/,
每一个被用户通过Shell删除的文件/目录,在系统回收站中都一个周期,也就是当系统回收站中的文件/目录在一段时间之后没有被用户恢复的话,HDFS就会自动的把这个文件/目录彻底删除,之后,用户就永远也找不回这个文件/目录了。
1. HDFS默认会关闭回收站功能。默认情况下HDFS删除文件,无法恢复。
[hadoop@hadoop002 hadoop]$ hdfs dfs -rm /gw_test.log2
Deleted /gw_test.log2
2. 启用回收站功能,需要配置core-site.xml文件
[hadoop@hadoop002 hadoop]$ vi etc/hadoop/core-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. See accompanying LICENSE file.
-->
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://hadoop002:9000</value>
</property>
<!--多长时间创建CheckPoint NameNode截点上运行的CheckPointer 从Current文件夹创建CheckPoint;默认:0 由fs.trash.interval项指定 -->
<property>
<name>fs.trash.checkpoint.interva</name>
<value>0</value>
</property>
<!--多少分钟.Trash下的CheckPoint目录会被删除,该配置服务器设置优先级大于客户端,默认:不启用 -->
<property>
<name>fs.trash.interval</name>
<value>1440</value> -- 清除周期分钟(24小时)
</property>
</configuration>
[hadoop@hadoop002 hadoop]
3. 重启hdfs服务
#停止hdfs服务
[hadoop@hadoop002 hadoop]$ sbin/stop-dfs.sh
Stopping namenodes on [hadoop002]
hadoop002: no namenode to stop
hadoop002: no datanode to stop
Stopping secondary namenodes [hadoop002]
hadoop002: no secondarynamenode to stop
#启动hdfs服务
[hadoop@hadoop002 hadoop]$ sbin/start-dfs.sh
Starting namenodes on [hadoop002]
hadoop002: starting namenode, logging to /opt/software/hadoop-2.8.1/logs/hadoop-hadoop-namenode-hadoop002.out
hadoop002: starting datanode, logging to /opt/software/hadoop-2.8.1/logs/hadoop-hadoop-datanode-hadoop002.out
Starting secondary namenodes [hadoop002]
hadoop002: starting secondarynamenode, logging to /opt/software/hadoop-2.8.1/logs/hadoop-hadoop-secondarynamenode-hadoop002.out
[hadoop@hadoop002 hadoop]$
4. HDFS删除文件,删除的文件被存放在回收站下面;/user/hadoop/.Trash/Current
#删除文件/gw_test.log3,
[hadoop@hadoop002 hadoop]$ hdfs dfs -rm /gw_test.log3
18/05/25 15:27:47 INFO fs.TrashPolicyDefault: Moved: 'hdfs://hadoop002:9000/gw_test.log3' to trash at: hdfs://hadoop002:9000/user/hadoop/.Trash/Current/gw_test.log3
#查看根目录下,gw_test.log3文件不存在
[hadoop@hadoop002 hadoop]$ hdfs dfs -ls /
Found 3 items
drwxr-xr-x - root root 0 2018-05-23 13:16 /root
drwx------ - hadoop supergroup 0 2018-05-22 11:23 /tmp
drwxr-xr-x - hadoop supergroup 0 2018-05-22 11:22 /user
[hadoop@hadoop002 hadoop]$
#查看回收站目录下的文件,
[hadoop@hadoop002 hadoop]$ hdfs dfs -ls /user/hadoop/.Trash/Current
Found 1 items
-rw-r--r-- 1 hadoop supergroup 25 2018-05-23 13:04 /user/hadoop/.Trash/Current/gw_test.log3
5. 恢复文件
#恢复文件操作
[hadoop@hadoop002 hadoop]$ hdfs dfs -mv /user/hadoop/.Trash/Current/gw_test.log3 /gw_test.log3
#查看根目录下文件是否被恢复
[hadoop@hadoop002 hadoop]$ hdfs dfs -ls /
Found 4 items
-rw-r--r-- 1 hadoop supergroup 25 2018-05-23 13:04 /gw_test.log3
drwxr-xr-x - root root 0 2018-05-23 13:16 /root
drwx------ - hadoop supergroup 0 2018-05-22 11:23 /tmp
drwxr-xr-x - hadoop supergroup 0 2018-05-22 11:22 /user
6. 删除文件跳过回收站
# -skipTrash参数表示跳过回收站
[hadoop@hadoop002 hadoop]$ hdfs dfs -rm -skipTrash /gw_test.log3
Deleted /gw_test.log3
“HDFS垃圾回收站的配置及使用方法”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注编程网网站,小编将为大家输出更多高质量的实用文章!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341