以下是在CentOS上恢复HDFS数据的常用方法:
利用回收站恢复
core-site.xml
中启用回收站:<property><name>fs.trash.interval</name><value>120</value></property> <property><name>fs.trash.checkpoint.interval</name><value>120</value></property>
hdfs dfs -cp /user/username/.Trash/Current/deleted_file /path/to/restore
基于快照恢复
hdfs dfsadmin -allowSnapshot /path hdfs dfs -createSnapshot /path snapshotName
hdfs dfs -cp /path/.snapshot/snapshotName/file /path/to/restore
使用Hadoop工具恢复
hdfs fsck / -files -blocks -locations
hadoop distcp source_path destination_path
手动恢复(高风险)
sudo systemctl stop hadoop-namenode hadoop-datanode
fsimage
)并重启服务(需谨慎操作)。注意:操作前需先备份数据,建议在测试环境验证恢复流程,优先使用回收站或快照等低风险方式。