恢复误删除的数据
一、debugfs
1.查看删除的数据在哪个分区
df -Th
2.使用debugfs打开分区
open /dev/vda1
3.查看当前文件夹下可以恢复的所有文件列表
ls -d /root
显示
24578 (12) . 2 (12) .. 29250 (12) .ssh 27141 (16) .lftp
31245 (52) .viminfo <31380> (36) 1.txt <31250> (20) .1.txt.swp
18425 (20) .bash_logout 18426 (24) .bash_profile 18427 (16) .bashrc
18428 (16) .cshrc 18429 (16) .tcshrc 18785 (12) .pki
31360 (3888) .bash_history <31245> (3864) .viminfo.tmp
4.找到对应的参数带入命令
logdump -i <31380>
显示
Inode 31380 is at group 3, block 1909, offset 2432
Journal starts at block 5819, transaction 2114
No magic number at block 435: end of journal.
5.退出debugfs,开始恢复文件
dd if=/dev/vda1 of=/root/1.txt bs=2432 count=1 skip=1909
查看/root/1.txt文件发现里面是乱码。所以找另一种恢复方法。
二、extundelete
1.简介
(1)extundelete的文件恢复工具,该工具最给力的一点就是支持ext3/ext4双格式分区恢复。
(2)在实际线上恢复过程中,切勿将extundelete安装到你误删的文件所在硬盘,这样会有一定几率将需要恢复的数据彻底覆盖。
(3)extundelete还是有很大的不完整性,基于整个磁盘的恢复功能较为强大,基于目录和文件的恢复还不够强大。(4)extundelete执行完毕后在当前目录生产一个RECOVERED_FILES目录,里面即是恢复出来的文件,还包括文件夹。
(5)任何的文件恢复工具,在使用前,均要将要恢复的分区卸载或挂载为只读,防止数据被覆盖使用。
umount /dev/vda1
mount -o remount,ro /dev/vda1
(6)保持良好的习惯,绝对比恢复数据要更简单。
2.安装
下载解压
cd /opt
wget http://nchc.dl.sourceforge.net/project/extundelete/extundelete/0.2.4/extundelete-0.2.4.tar.bz2
tar jxvf extundelete-0.2.4.tar.bz2
编译安装
cd extundelete-0.2.4
./configure
make
make install
Error-1
configure: error: C++ compiler cannot create executables
yum install gcc gcc-c++ gcc-g77
Error-2
configure: error: Can't find ext2fs library
yum list | grep e2fs
yum install e2fsprogs-devel.x86_64 -y
3.恢复文件
extundelete /dev/vda1 --restore-file qqq.txt
显示验证
Loading filesystem metadata ... 16 groups loaded.
Loading journal descriptors ... 6508 descriptors loaded.
Successfully restored file qqq.txt
cat /root/qqq.txt
命令参数
--superblock 打印指定分区的超级块信息
--journal 显示块的日志信息
--after 恢复此时间后删除的所有文件
--before 恢复此时间前删除的所有文件
--inode 显示某分区inode为x的信息,一般是查看该分区下所有的文件
--restore-inode 恢复一个或多个指定inode号的文件
--restore-file 恢复指定的文件
--restore-directory 恢复指定的目录