通过 extundelete 尝试数据恢复
下文以 CentOS 6.8 ext4 文件系统为实验环境,工具为 extundelete。
在实际线上恢复过程中,切勿将 extundelete 安装到误删的文件所在磁盘,这样会有一定几率将需要恢复的数据彻底覆盖。建议加装一块磁盘将 extundelete 安装到此磁盘,再做以下操作。因为后续恢复删除文件的操作要执行 umount 设备分区的操作,所以此方法并不适合删除系统盘分区中的文件。
环境准备:
在本地虚拟机进行测试为了方便检测我临时增加了一块10G 的硬盘分成2个分区 分区格式为ext4 /dev/sdb1 挂载到/data 目录,里面用于存放数据
/dev/sdb2 挂载到/e2sf 目录 ,用于存放安装软件
1.检查系统依赖包
[root@caosm03 e2fs]# rpm -qa | grep e2fsprogs
e2fsprogs-libs-1.41.12-23.el6.x86_64
e2fsprogs-1.41.12-23.el6.x86_64
[root@caosm03 e2fs]# yum install -y e2fsprogs-dev
2.下载软件进行安装
[root@caosm03 e2fs]# yum install -y e2fsprogs-devel
[root@caosm03 e2fs]# tar -jxvf extundelete-0.2.4.tar.bz2 # 对文件进行解压
[root@caosm03 extundelete-0.2.4]# ./configure && make && make install # 对文件进行安装
提示错误信息:
configure: error: in `/e2fs/extundelete-0.2.4':
configure: error: C++ compiler cannot create executables
经查看是由于缺少C++ 依赖包进行安装
[root@caosm03 extundelete-0.2.4]# yum install gcc-c++ -y # 安装即可
[root@caosm03 extundelete-0.2.4]# ./configure && make && make install #重新编译安装
3.效验文件安装是否正确
[root@caosm03 extundelete-0.2.4]# extundelete -v
extundelete version 0.2.4
libext2fs version 1.41.12
Processor is little endian.
4.对需要进行测试的文件进行MD5值效验
[root@caosm03 data]# md5sum 222.log
24deb4b21ea98cb75f1b21a73e2dc283 222.log
5.对里面的日志进行部分删除进行测试,查看前需要卸载该磁盘分区
[root@caosm03 data]# umount /dev/sdb1
umount: /data: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@caosm03 ~]#fuser -km /dev/sdb1
[root@caosm03 ~]# umount /dev/sdb1
[root@caosm03 ~]# extundelete /dev/sdb1 --inode 2
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 41 groups loaded.
...
File name | Inode number | Deleted status
. 2
.. 2
lost+found 11
222.log 14
.222.log.swp 12 Deleted
222.log~ 13 Deleted
.111.log.swx 2021094190 Deleted
GET93396120171028_nginx232.log~ 14 Deleted
[root@caosm03 e2fs]# extundelete --restore-all /dev/sdb1
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 41 groups loaded.
Loading journal descriptors ... 81 descriptors loaded.
Searching for recoverable inodes in directory / ...
3 recoverable inodes found.
Looking through the directory structure for deleted files ...
Block 33792 is allocated
默认被删文件会恢复到当前目录下的 RECOVERED_FILES 目录中去
[root@caosm03 RECOVERED_FILES]# ll
total 5344
-rw-r--r-- 1 root root 5471632 Dec 15 12:31 222.log~
[root@caosm03 RECOVERED_FILES]# md5sum 222.log~
24deb4b21ea98cb75f1b21a73e2dc283 222.log~
经对比 这个MD5效验值与之前的md5效验值一致,说明文件已经被彻底恢复。