ps: 红字字体为重要部分, 仔细看node
当意识到误删除文件后,切忌千万不要再频繁写入了,不然你的数据恢复的数量将会不多。 而咱们要作的是,第一时间把服务器上的服务所有停掉,直接killall 进程名 或者 kill -9 pid 。 而后把误删除文件所在分区,从新挂载成ro,只读的 (mount -o ro /dev/sdb2 /data/)。bash
1、 利用系统工具debugfs恢复误删除文件服务器
1. 首先建立一个目录及文件;app
[root@Centos1 ~]# mkdir ceshi [root@Centos1 ~]# echo 111 > ceshi/1.txt
2. 删除ceshi目录下的全部文件;ide
[root@Centos1 ~]# rm -rf ceshi/*
3. 利用系统自带还原工具debugfs来修复;工具
[root@Centos1 ~]# debugfs debugfs 1.41.12 (17-May-2010) debugfs: open /dev/mapper/VolGroup-lv_root
4. 用ls -d参数显示刚刚删除文件的所在目录;字体
debugfs: ls -d /root/ceshi/ 144661 (12) . 128522 (4084) .. <128531> (4072) 1.txt
5. 显示<>尖括号的就是咱们要找的文件inode号;spa
debugfs: logdump -i <131458>
6. 执行完后, 显示了一屏信息, 咱们须要的是这一行, 而且记住后面的值(即标注红色部分);.net
Blocks: (0+1): 127754 (2+1): 1768711539 (3+1): 7894382 (TIND): 1953724787
7. 退出debugfs, 执行如下命令;debug
debugfs: q [root@Centos1 ~]# dd if=/dev/mapper/VolGroup-lv_root of=/root/ceshi/1.txt.bak bs=4096 count=1 skip=30 # if=输入的设备 # of=输出的社保 # bs=指定一个block的大小 # count=多少个block须要dump # skip= Blocks: (0+1):后的值
8. 查看/root/ceshi/目录下是否生成1.txt.bak文件;
[root@Centos1 ~]# cat /root/ceshi/1.txt.bak 111
2、利用extundelete恢复误删文件
1. 利用yum安装依赖包;
[root@Centos1 ~]# yum -y install e2fsprogs* [root@Centos1 ~]# yum -y install gcc* #extundelete编译时须要gcc环境
2. 下载并安装extundelete;
[root@Centos1 ~]# wget http://nchc.dl.sourceforge.net/project/extundelete/extundelete/0.2.4/extundelete-0.2.4.tar.bz2
3. 解包、配置、编译及安装;
[root@Centos1 ~]# tar -jxvf extundelete-0.2.4.tar.bz2 [root@Centos1 ~]# cd extundelete-0.2.4 [root@Centos1 extundelete-0.2.4]# ./configure --prefix=/usr/local/extundelete [root@Centos1 extundelete-0.2.4]# make && make install
4. 检验是否安装成功;
[root@Centos1 extundelete-0.2.4]# cd /usr/local/extundelete/bin [root@Centos1 bin]# ./extundelete -v extundelete version 0.2.4 libext2fs version 1.41.12 Processor is little endian.
5. 扫描LVM分区误删的文件;
[root@Centos1 bin]# /usr/local/extundelete/bin/extundelete /dev/mapper/VolGroup-lv_root --inode 2
6. 恢复aaa.txt文件;
[root@Centos1 bin]# /usr/local/extundelete/bin/extundelete --restore-file aaaa.txt /dev/mapper/VolGroup-lv_root [root@Centos1 bin]# /usr/local/extundelete/bin/extundelete --restore-all /dev/sdb2 #恢复分区
7. 查看恢复文件;
[root@Centos1 bin]# ls -l RECOVERED_FILES/ 恢复后的文件也是在 ./RECOVERED_FILES/ 下,可否恢复就看你的运气好很差了。