因为ext3grep只支持ext3文件系统,碰到ext4就不行了。
extundelete只支持ext3和ext4两种,xfs什么的还不支持。
下载地址: http://extundelete.sourceforge.net/
测试环境: vmware centos6 ext4文件系统
挂载个单独磁盘:
创建磁盘略…
[root@localhost ~]# mkfs.ext4 /dev/sdb1
[root@localhost ~]# mkdir /mnt/sdb1
[root@localhost ~]# mount /dev/sdb1 /mnt/sdb1/
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 77G 2.8G 71G 4% /
tmpfs 116M 0 116M 0% /dev/shm
/dev/sdb1 20G 172M 19G 1% /mnt/sdb1
创建测试文件夹及文件:
[root@localhost ~]# cd /mnt/sdb1/
[root@localhost sdb1]# mkdir test
[root@localhost sdb1]# cd test/
[root@localhost test]# echo aaa > a.txt
[root@localhost test]# ll
总用量 4
-rw-r–r– 1 root root 4 11月 28 18:47 a.txt
[root@localhost test]# mkdir test2
[root@localhost test]# ll
总用量 8
-rw-r–r– 1 root root 4 11月 28 18:47 a.txt
drwxr-xr-x 2 root root 4096 11月 28 18:47 test2
[root@localhost test]# cd test2/
[root@localhost test2]# echo bbb > b.txt
安装extundelete:
[root@localhost extundelete-0.2.4]# ./configure
Configuring extundelete 0.2.4
configure: error: Can’t find ext2fs library
[root@localhost extundelete-0.2.4]# yum install -y e2fsprogs-devel
#缺少库文件
[root@localhost extundelete-0.2.4]# ./configure
Configuring extundelete 0.2.4
Writing generated files to disk
[root@localhost extundelete-0.2.4]# make
make -s all-recursive
Making all in src
extundelete.cc:571: warning: unused parameter ‘flags’
[root@localhost extundelete-0.2.4]# make install
Making install in src
/usr/bin/install -c extundelete ‘/usr/local/bin’
[root@localhost extundelete-0.2.4]#
删除单个文件:
[root@localhost ~]# rm -f /mnt/sdb1/test/a.txt
卸载数据所在磁盘:
[root@localhost ~]# umount /dev/sdb1 [root@localhost ~]# extundelete /dev/sdb1 --restore-file test/a.txt
#这个地方需要注意,是分区挂载点开始的目录,比如挂载到/mnt/sdb1,其下有test文件夹,从这个文件夹开始恢复文件。
NOTICE: Extended attributes are not restored.
Loading filesystem metadata … 160 groups loaded.
Loading journal descriptors … 46 descriptors loaded.
Successfully restored file test/a.txt
[root@localhost ~]# ll
总用量 664
-rw-r–r– 1 root root 228121 10月 31 05:41 0.8.14.tar.gz
-rw-r–r– 1 root root 321920 10月 31 05:40 0.9.3.tar.gz
drwxr-xr-x 3 1000 1000 4096 11月 28 18:33 extundelete-0.2.4
-rw-r–r– 1 root root 108472 11月 28 18:25 extundelete-0.2.4.tar.bz2
drwxrwxr-x 11 root root 4096 10月 31 06:06 fail2ban-0.8.14
drwxrwxr-x 8 root root 4096 10月 31 06:13 fail2ban-0.9.3
drwxr-xr-x 3 root root 4096 11月 28 19:08 RECOVERED_FILES
[root@localhost ~]# cat RECOVERED_FILES/test/a.txt
/sdb1/aaa
默认恢复出来的数据会存放在命令执行时的当前目录,可以通过 -o 参数指定路径
[root@localhost ~]# extundelete /dev/sdb1 --restore-file test/test2/b.txt 恢复子目录下的文件 恢复整个目录: [root@localhost ~]# extundelete /dev/sdb1 --restore-directory test 恢复整个磁盘: [root@localhost test2]# extundelete /dev/sdb1 --restore-all
注意恢复的时候先卸载分区,否则会提示下面信息:
The partition should be unmounted to undelete any files without further data loss.
注意 extundelete 不能恢复空文件夹。
原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/3480.html