针对于ext4文件系统数据恢复软件,看了网上好多都在介绍extundelete这个工具,下载最新版本实验时(在Centos5.8、Centos6.7上实验效果不是很好)。最终发现ext4magic对于ext4数据恢复支持还是非常强大的。也可以做到基于时间点、inode、指定文件恢复等等。恢复时需要卸载分区,以只读方式挂载恢复。具体软件下载地址为:
http://sourceforge.net/projects/ext4magic/
1、安装
可以参考官方INSTALL文件进行安装,如有依赖需处理好包依赖方可进行安装。系统必须安装make、file
、gcc工具。以下libmagic、libext2fs、libz、libbz2库必须安装,
# tar -xzf ext4magic-0.3.2.tar.gz
# cd ext4magic-0.3.2
# ./configure
# make
# make install
2、测试
(1)、基于时间恢复(以1970-01-01 00:00:00 UTC的秒数开始计算)
[root@jason1 ~]# mount /dev/sdb1 /media/
[root@jason1 ~]# cp -rp /boot/* /media/
[root@jason1 ~]# cd /media/
[root@jason1 media]# ll
total 34884
-rw-r--r--. 1 root root 107134 Jul 24 00:13 config-2.6.32-573.el6.x86_64
drwxr-xr-x. 3 root root 4096 Dec 10 19:20 efi
-rw-r--r--. 1 root root 166756 Jul 20 2011 elf-memtest86+-4.10
drwxr-xr-x. 2 root root 4096 Dec 10 19:33 grub
-rw-------. 1 root root 27925110 Dec 10 19:31 initramfs-2.6.32-573.el6.x86_64.img
drwx------. 2 root root 16384 Dec 10 18:17 lost+found
-rw-r--r--. 1 root root 165080 Jul 20 2011 memtest86+-4.10
-rw-r--r--. 1 root root 205998 Jul 24 00:14 symvers-2.6.32-573.el6.x86_64.gz
-rw-r--r--. 1 root root 2585052 Jul 24 00:13 System.map-2.6.32-573.el6.x86_64
-rw-r--r--. 1 root root 289193 Oct 15 2014 tboot.gz
-rw-r--r--. 1 root root 12277 Oct 15 2014 tboot-syms
-rwxr-xr-x. 1 root root 4220560 Jul 24 00:13 vmlinuz-2.6.32-573.el6.x86_64
[root@jason1 media]# date
Mon Dec 14 19:36:06 CST 2015
[root@jason1 media]# rm -rf *
[root@jason1 media]# cd
[root@jason1 ~]# umount /dev/sdb1
[root@jason1 ~]# mount -o ro /dev/sdb1 /media
[root@jason1 ~]# ext4magic /dev/sdb1 -d /home -a 1450086000 -m 3##改时间通过date命令获取当前时间秒数减去3600秒得来。
Warning: Activate magic-scan or disaster-recovery function, may be some command line options ignored
"/home" accept for recoverdir
Filesystem in use: /dev/sdb1
Using internal Journal at Inode 8
Activ Time after : Mon Dec 14 17:40:00 2015
Activ Time before : Mon Dec 14 19:44:26 2015
Inode 2 is allocated
-------- /home/config-2.6.32-573.el6.x86_64
-------- /home/efi/EFI/redhat/grub.efi
-------- /home/elf-memtest86+-4.10
-------- /home/grub/menu.lst
-------- /home/grub/reiserfs_stage1_5
-------- /home/grub/e2fs_stage1_5
-------- /home/grub/xfs_stage1_5
-------- /home/grub/fat_stage1_5
-------- /home/grub/stage1
-------- /home/grub/iso9660_stage1_5
-------- /home/grub/splash.xpm.gz
-------- /home/grub/vstafs_stage1_5
-------- /home/grub/ufs2_stage1_5
-------- /home/grub/device.map
-------- /home/grub/stage2
-------- /home/grub/ffs_stage1_5
-------- /home/grub/minix_stage1_5
-------- /home/grub/jfs_stage1_5
-------- /home/grub/grub.conf
-------- /home/initramfs-2.6.32-573.el6.x86_64.img
-------- /home/memtest86+-4.10
-------- /home/symvers-2.6.32-573.el6.x86_64.gz
-------- /home/System.map-2.6.32-573.el6.x86_64
-------- /home/tboot.gz
-------- /home/tboot-syms
-------- /home/vmlinuz-2.6.32-573.el6.x86_64
MAGIC-1 : start lost directory search
MAGIC-2 : start lost file search
MAGIC-2 : start lost in journal search
MAGIC-3 : start ext4-magic-scan search
-------- /home/MAGIC-3/text/plain/0000028685.txt
-------- /home/MAGIC-3/text/plain/0000045944.txt
ext4magic : EXIT_SUCCESS
验证是否恢复成功
[root@jason1 ~]# cd /home/
[root@jason1 home]# ll
total 34872
-rw-r--r--. 1 root root 107134 Jul 24 00:13 config-2.6.32-573.el6.x86_64
drwx------. 3 root root 4096 Dec 14 19:44 efi
-rw-r--r--. 1 root root 166756 Jul 20 2011 elf-memtest86+-4.10
drwx------. 2 root root 4096 Dec 14 19:44 grub
-rw-------. 1 root root 27925110 Dec 10 19:31 initramfs-2.6.32-573.el6.x86_64.img
drwx------. 3 root root 4096 Dec 14 19:44 MAGIC-3
-rw-r--r--. 1 root root 165080 Jul 20 2011 memtest86+-4.10
-rw-r--r--. 1 root root 205998 Jul 24 00:14 symvers-2.6.32-573.el6.x86_64.gz
-rw-r--r--. 1 root root 2585052 Jul 24 00:13 System.map-2.6.32-573.el6.x86_64
-rw-r--r--. 1 root root 289193 Oct 15 2014 tboot.gz
-rw-r--r--. 1 root root 12277 Oct 15 2014 tboot-syms
-rwxr-xr-x. 1 root root 4220560 Jul 24 00:13 vmlinuz-2.6.32-573.el6.x86_64
[root@jason1 home]#
(2)、整个文件系统恢复
[root@jason1 ~]# ext4magic /dev/sdb1 -d /home -m
Warning: Activate magic-scan or disaster-recovery function, may be some command line options ignored
"/home" accept for recoverdir
Filesystem in use: /dev/sdb1
Using internal Journal at Inode 8
Activ Time after : Mon Dec 14 19:36:37 2015
Activ Time before : Mon Dec 14 19:56:58 2015
Inode 2 is allocated
-------- /home/config-2.6.32-573.el6.x86_64
-------- /home/efi/EFI/redhat/grub.efi
-------- /home/elf-memtest86+-4.10
-------- /home/grub/menu.lst
-------- /home/grub/reiserfs_stage1_5
-------- /home/grub/e2fs_stage1_5
-------- /home/grub/xfs_stage1_5
-------- /home/grub/fat_stage1_5
-------- /home/grub/stage1
-------- /home/grub/iso9660_stage1_5
-------- /home/grub/splash.xpm.gz
-------- /home/grub/vstafs_stage1_5
-------- /home/grub/ufs2_stage1_5
-------- /home/grub/device.map
-------- /home/grub/stage2
-------- /home/grub/ffs_stage1_5
-------- /home/grub/minix_stage1_5
-------- /home/grub/jfs_stage1_5
-------- /home/grub/grub.conf
-------- /home/initramfs-2.6.32-573.el6.x86_64.img
-------- /home/memtest86+-4.10
-------- /home/symvers-2.6.32-573.el6.x86_64.gz
-------- /home/System.map-2.6.32-573.el6.x86_64
-------- /home/tboot.gz
-------- /home/tboot-syms
-------- /home/vmlinuz-2.6.32-573.el6.x86_64
MAGIC-1 : start lost directory search
MAGIC-2 : start lost file search
MAGIC-2 : start lost in journal search
MAGIC-3 : start ext4-magic-scan search
-------- /home/MAGIC-3/text/plain/0000028685.txt
ext4magic : EXIT_SUCCESS
[root@jason1 ~]#
(3)、指定文件恢复
[root@jason1 ~]# ext4magic /dev/sdb1 -r -f grub/grub.conf -d /home
"/home" accept for recoverdir
Filesystem in use: /dev/sdb1
Using internal Journal at Inode 8
Inode found "grub/grub.conf" 655377
-------- /home/grub/grub.conf
ext4magic : EXIT_SUCCESS
[root@jason1 ~]# cd /home/
[root@jason1 home]# ll
total 4
drwx------. 2 root root 4096 Dec 14 20:08 grub
[root@jason1 home]# ll grub/grub.conf
-rw-------. 1 root root 843 Dec 10 19:33 grub/grub.conf
[root@jason1 home]#
指定文件恢复时,需要注意指定恢复文件的路径书写问题。以下给出官方的示例:
An example: the mount point for this filesystem is " /home " an the filename for Linux is " /home/usr1/Document " you can use now
# ext4magic /dev/sda3 -f usr1/Document
(去掉挂在点目录指定文件目录)。
备注:更详细的恢复参数,参考系统man ext4magic帮助文档。