恢復Linux下被誤刪除的文件
[root@xuegod63 ~]# mount /dev/cdrom /mnt/
分一個區:sda4
查找:extundelete
分一個區:sda4
[root@localhost ~]# mkdir /tmp/sda4
[root@localhost ~]# mkfs.ext4 /dev/sda4 格式化
[root@xuegod63 Desktop]# echo $?
0
[root@localhost ~]# mount /dev/sda4 /tmp/sda4/
[root@localhost ~]# df -Th #查看磁盤相關信息
[root@xuegod63 Desktop]# mount /dev/sda4 /tmp/sda4
[root@xuegod63 Desktop]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.7G 3.8G 5.5G 41% /
tmpfs 569M 264K 569M 1% /dev/shm
/dev/sda1 194M 28M 157M 15% /boot
/dev/sr0 3.4G 3.4G 0 100% /mnt
/dev/sda4 1012M 34M 928M 4% /tmp/sda4
復制一些用於測試刪除的文件:
[root@localhost ~]# cp /etc/passwd /tmp/sda4/
[root@localhost ~]# cp /etc/hosts /tmp/sda4/
[root@localhost ~]# vim /tmp/sda4/a.txt #vim編輯a.txt 隨便寫入一些數據。
[root@localhost ~]# mkdir -p /tmp/sda4/a/b/c
[root@localhost ~]# cp /tmp/sda4/a.txt /tmp/sda4/a
[root@localhost ~]# cp /tmp/sda4/a.txt /tmp/sda4/a/b/
刪除:
[root@xuegod63 ~]# mkdir /tmp/back
[root@xuegod63 ~]# cp -r /tmp/sda4/* /tmp/back
[root@xuegod63 ~]# cd /tmp/sda4/
[root@localhost ~]# rm -rf passwd hosts a a.txt
[root@localhost ~]# ls /tmp/sda4/
lost+found
卸載需要恢復文件的分區: inode
[root@xuegod63 sda4]# cd
[root@xuegod63 ~]# umount /tmp/sda4/
安裝軟件 extundelete
[root@xuegod63 ~]# tar jxvf extundelete-0.2.4.tar.bz2
[root@xuegod63 ~]# cd extundelete-0.2.4
[root@xuegod63 extundelete-0.2.4]# ./configure
Configuring extundelete 0.2.4
configure: error: Can't find ext2fs library #報錯
[root@xuegod63 ~]# mount /dev/cdrom /mnt/
[root@xuegod63 extundelete-0.2.4]# rpm -ivh /mnt/Packages/e2fsprogs-devel-1.41.12-11.el6.x86_64.rpm
[root@xuegod63 extundelete-0.2.4]#
[root@xuegod63 extundelete-0.2.4]# ./configure #檢查安裝環境並生成Makefile
[root@xuegod63 extundelete-0.2.4]# make #編譯
[root@xuegod63 extundelete-0.2.4]# make install #安裝
查找博客:http://www.cnblogs.com/jjzd/p/5785851.html
安裝e2fsprogs-devel-1.41.12-14.el6.x86_64.rpm
開始恢復:
方法1:
通過inode結點查看被刪除的文件名字:
[root@xuegod63 ~]# mkdir test
[root@xuegod63 ~]# cd test/
[root@localhost ~]# extundelete /dev/sda4 --inode 2
。。。
lost+found 11
passwd 12 Deleted
hosts 13 Deleted
a 8193 Deleted
a.txt 15 Deleted
通過inode節點來恢復:
[root@localhost ~]# extundelete /dev/sda4 --restore-inode 12
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 16 groups loaded.
Loading journal descriptors ... 32 descriptors loaded.
[root@localhost ~]# ls RECOVERED_FILES/ #恢復成功
file.12
[root@xuegod63 test]# diff /etc/passwd /root/test/RECOVERED_FILES/file.12
方法二,通過文件名恢復
方法二,通過文件名恢復
恢復某個文件:
[root@xuegod63 test]# rm -rf RECOVERED_FILES/
[root@localhost ~]# extundelete /dev/sda4 --restore-file passwd
恢復某個目錄,如目錄a下的所有文件:
[root@localhost ~]# extundelete /dev/sda4 --restore-directory a #恢復目錄a ,不用
恢復所有的文件
[root@localhost ~]# extundelete /dev/sda4 --restore-all
使用心得:
空目錄或空文件恢復不成功。