误删除文件处理
程序员文章站
2022-03-09 14:26:31
...
简介:
extundelete的文件恢复工具,支持ext3/ext4双格式分区恢复。
1、extundelete的文件恢复工具,该工具最给力的一点就是支持ext3/ext4双格式分区恢复。
2.、在实际线上恢复过程中,切勿将extundelete安装到你误删的文件所在硬盘,这样会有一定几率将需要恢复的数据彻底覆盖。
3.、extundelete还是有很大的不完整性,基于整个磁盘的恢复功能较为强大,基于目录和文件的恢复还不够强大。
4.、extundelete执行完毕后在当前目录生产一个RECOVERED_FILES目录,里面即是恢复出来的文件,还包括文件夹。
5、任何的文件恢复工具,在使用前,均要将要恢复的分区卸载或挂载为只读,防止数据被覆盖使用。
安装extundelete:
上传安装包:
[aaa@qq.com ~]# ls
anaconda-ks.cfg install.log 公共的 视频 文档 音乐
extundelete-0.2.4.tar.bz2 install.log.syslog 模板 图片 下载 桌面
[aaa@qq.com ~]#
网址安装:
wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/server/extundelete-0.2.4.tar.bz2
extundelete需要依赖e2fsprogs和e2fslibs:
[aaa@qq.com ~]# yum -y install e2fsprogs-devel e2fsprogs gcc gcc-c++
解压安装包并进入目录:
[aaa@qq.com ~]# tar xjf extundelete-0.2.4.tar.bz2
[aaa@qq.com ~]# ls
anaconda-ks.cfg extundelete-0.2.4.tar.bz2 install.log.syslog 模板 图片 下载 桌面
extundelete-0.2.4 install.log 公共的 视频 文档 音乐
[aaa@qq.com ~]# cd extundelete-0.2.4
[aaa@qq.com extundelete-0.2.4]#
检查环境:
[aaa@qq.com extundelete-0.2.4]# ./configure
Configuring extundelete 0.2.4
Writing generated files to disk
[aaa@qq.com extundelete-0.2.4]# echo $?
0
[aaa@qq.com extundelete-0.2.4]#
编译安装:
[aaa@qq.com extundelete-0.2.4]# make && make install
make -s all-recursive
Making all in src
extundelete.cc:571: 警告:未使用的参数‘flags’
Making install in src
/usr/bin/install -c extundelete '/usr/local/bin'
[aaa@qq.com extundelete-0.2.4]# echo $?
0
[aaa@qq.com extundelete-0.2.4]#
在/tmp/sdb1/目录下创建目录或文件等等:
[aaa@qq.com extundelete-0.2.4]# cd
[aaa@qq.com ~]# mkdir /tmp/sdb1
[aaa@qq.com ~]# cd /tmp/sdb1/
[aaa@qq.com sdb1]# ls
lost+found
[aaa@qq.com sdb1]# cp /etc/passwd /tmp/sdb1/
[aaa@qq.com sdb1]# cp /etc/hosts /tmp/sdb1/
[aaa@qq.com sdb1]# echo "wecome wg" >> a.txt
[aaa@qq.com sdb1]# cat a.txt
wecome wg
[aaa@qq.com sdb1]# mkdir aaa
[aaa@qq.com sdb1]# cd aaa/
[aaa@qq.com aaa]# echo "wecome wg" >> a.txt
[aaa@qq.com aaa]# touch b.txt
[aaa@qq.com aaa]# ls
a.txt b.txt
[aaa@qq.com aaa]#
删除文件:
[aaa@qq.com sdb1]# rm -rf ./*
[aaa@qq.com sdb1]# ls
[aaa@qq.com sdb1]#
取消挂载:
[aaa@qq.com ~]# umount /tmp/sdb1/
[aaa@qq.com ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 12G 3.8G 7.4G 34% /
tmpfs 491M 80K 491M 1% /dev/shm
/dev/sda1 190M 34M 147M 19% /boot
/dev/sda2 4.7G 9.9M 4.5G 1% /home
/dev/sr0 3.7G 3.7G 0 100% /media/CentOS_6.8_Final
[aaa@qq.com ~]#
删除数据查找:
因为我的数据路径比较深,所以我们需要一步步查找,可以先从根分区 inode 查找
File name | Inode number | Deleted status
. 2
.. 2
lost+found 11 Deleted
passwd 12 Deleted
hosts 13 Deleted
a.txt 14 Deleted
aaa 296593 Deleted
[aaa@qq.com sdb1]# extundelete /dev/sdb1 --inode 2
这里我们会看到被删除文件的相应的的inode。
我们可以看到标称的 Deleted,这些数据就是我们要进行恢复的数据。
数据恢复:
用inode恢复:
[aaa@qq.com ~]# extundelete /dev/sdb1 --restore-inode 12
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 81 groups loaded.
Loading journal descriptors ... 53 descriptors loaded.
[aaa@qq.com ~]# ls
anaconda-ks.cfg extundelete-0.2.4.tar.bz2 install.log.syslog 公共的 视频 文档 音乐
extundelete-0.2.4 install.log RECOVERED_FILES 模板 图片 下载 桌面
[aaa@qq.com ~]# cd RECOVERED_FILES/
[aaa@qq.com RECOVERED_FILES]# ls
file.12
[aaa@qq.com RECOVERED_FILES]# cat file.12
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
用名字恢复:
方法一:
[aaa@qq.com ~]# extundelete /dev/sdb1 --restore-file passwd
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 81 groups loaded.
Loading journal descriptors ... 53 descriptors loaded.
Successfully restored file passwd
[aaa@qq.com ~]# ls
anaconda-ks.cfg extundelete-0.2.4.tar.bz2 install.log.syslog 公共的 视频 文档 音乐
extundelete-0.2.4 install.log RECOVERED_FILES 模板 图片 下载 桌面
[aaa@qq.com ~]# cd RECOVERED_FILES/
[aaa@qq.com RECOVERED_FILES]# ls
passwd
[aaa@qq.com RECOVERED_FILES]#
方法二:
[aaa@qq.com ~]# extundelete /dev/sdb1 --restore-directory aaa
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 81 groups loaded.
Loading journal descriptors ... 53 descriptors loaded.
Searching for recoverable inodes in directory aaa ...
6 recoverable inodes found.
Looking through the directory structure for deleted files ...
5 recoverable inodes still lost.
[aaa@qq.com ~]# ls
anaconda-ks.cfg extundelete-0.2.4.tar.bz2 install.log.syslog 公共的 视频 文档 音乐
extundelete-0.2.4 install.log RECOVERED_FILES 模板 图片 下载 桌面
[aaa@qq.com ~]# cd RECOVERED_FILES/
[aaa@qq.com RECOVERED_FILES]# ls
aaa
[aaa@qq.com RECOVERED_FILES]#
恢复全部数据可以使用命令:
[aaa@qq.com ~]# extundelete /dev/sdb1 --restore-all
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 81 groups loaded.
Loading journal descriptors ... 53 descriptors loaded.
Searching for recoverable inodes in directory / ...
6 recoverable inodes found.
Looking through the directory structure for deleted files ...
0 recoverable inodes still lost.
[aaa@qq.com ~]# cd RECOVERED_FILES/
[aaa@qq.com RECOVERED_FILES]# ls
aaa a.txt hosts passwd
[aaa@qq.com RECOVERED_FILES]# tree
.
├── aaa
│ └── a.txt
├── a.txt
├── hosts
└── passwd
1 directory, 4 files
[aaa@qq.com RECOVERED_FILES]#