恢复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
使用心得:
空目录或空文件恢复不成功。