[root@localhost disk]# ls
2.卸载磁盘分区
执行以下命令卸载磁盘分区:
[root@localhost disk]# cd /opt/ #切换到/opt目录下
[root@localhost opt]# umount /disk/ #卸载模拟磁盘分区
3.查询恢复数据信息
执行如下命令,查询需要恢复的数据信息:
[root@localhost opt]# ext3grep /data0/disk1 --ls --inode 2
执行该命令后,ext3grep就开始搜索可以恢复的数据文件信息,如下输出结果所示。
Running ext3grep version 0.10.2
WARNING: I don't know what EXT3_FEATURE_COMPAT_EXT_ATTR is.
Number of groups: 7
Loading group metadata... done
Minimum / maximum journal block: 16616 / 20729
Loading journal descriptors... sorting... done
The oldest inode block that is still in the journal, appears to be from 1380011783 = Tue Sep 24 16:36:23 2013
Number of descriptors in journal: 67; min / max sequence numbers: 2 / 12
Inode is Allocated
Finding all blocks that might be directories.
D: block containing directory start, d: block containing more directory entries.
Each plus represents a directory start that references the same inode as a directory start that we found previously.
Searching group 0: DD
Searching group 1:
Searching group 2: +++++
Searching group 3:
Searching group 4:
Searching group 5:
Searching group 6:
Writing analysis so far to 'disk1.ext3grep.stage1'. Delete that file if you want to do this stage again.
Result of stage one:
2 inodes are referenced by one or more directory blocks, 1 of those inodes is still allocated.
1 inodes are referenced by more than one directory block, 1 of those inodes is still allocated.
0 blocks contain an extended directory.
Result of stage two:
1 of those inodes could be resolved because it is still allocated.
All directory inodes are accounted for!
Writing analysis so far to 'disk1.ext3grep.stage2'. Delete that file if you want to do this stage again.
The first block of the directory is 433.
Inode 2 is directory "".
Directory block 433:
.-- File type in dir_entry (r=regular file, d=directory, l=symlink)
| .-- D: Deleted ; R: Reallocated
Indx Next | Inode | Deletion time Mode File name
==========+==========+----------------data-from-inode------+-----------+=========
0 1 d 2 drwxr-xr-x .
1 end d 2 drwxr-xr-x ..
2 3 d 11 D 1380011904 Tue Sep 24 16:38:24 2013 drwx------ lost+found
3 end r 12 D 1380011904 Tue Sep 24 16:38:24 2013 rrw-r--r-- profile
4 end r 13 D 1380011904 Tue Sep 24 16:38:24 2013 rrw------- initrd-2.6.32-358.el6.i686kdump.img
5 end r 14 D 1380011904 Tue Sep 24 16:38:24 2013 rrw-r--r-- ext3grep.txt
6 end r 15 D 1380011904 Tue Sep 24 16:38:24 2013 rrw-r--r-- ext3grep
“ext3grep /data0/disk1 --ls --inode 2”主要用于扫描当前文件系统下所有文件的信息,包括存在的和已经删除的文件,其中含有D标识的就是已被删除的文件,如果不记得被删除的文件的名称,可以通过这种方式来获取要恢复的文件的名称。
通过下面的方式可以获取文件要恢复的路径信息。
[root@localhost opt]# ext3grep /data0/disk1 --dump-names
Running ext3grep version 0.10.2
WARNING: I don't know what EXT3_FEATURE_COMPAT_EXT_ATTR is.
Number of groups: 7
Minimum / maximum journal block: 16616 / 20729
Loading journal descriptors... sorting... done
The oldest inode block that is still in the journal, appears to be from 1380011783 = Tue Sep 24 16:36:23 2013
Number of descriptors in journal: 67; min / max sequence numbers: 2 / 12
Loading disk1.ext3grep.stage2... done
ext3grep
ext3grep.txt
initrd-2.6.32-358.el6.i686kdump.img
lost+found
profile
4.恢复单个文件
如果要恢复被删除的某个文件,通过下面方式即可。
[root@localhost opt]# ext3grep /data0/disk1 --restore-file ext3grep.txt
Running ext3grep version 0.10.2
WARNING: I don't know what EXT3_FEATURE_COMPAT_EXT_ATTR is.
Number of groups: 7
Minimum / maximum journal block: 16616 / 20729
Loading journal descriptors... sorting... done
The oldest inode block that is still in the journal, appears to be from 1380011783 = Tue Sep 24 16:36:23 2013
Number of descriptors in journal: 67; min / max sequence numbers: 2 / 12
Writing output to directory RESTORED_FILES/
Loading disk1.ext3grep.stage2... done
Restoring ext3grep.txt
由上面的输出可知,被删除的文件ext3grep.txt已经成功恢复。那么恢复的数据放到哪里了呢?在这段操作中,在/opt目录下执行ext3grep命令,恢复的数据文件就存放在/opt/RESTORED_FILES目录下,也就是说ext3grep会在执行恢复命令的当前目录下自动创建一个RESTORED_FILES目录,这个目录专门用于存放恢复的数据。
下面是恢复指定目录下的某个文件的操作:
[root@localhost opt]# ext3grep /data0/disk1 --restore-file ext3grep
Running ext3grep version 0.10.2
WARNING: I don't know what EXT3_FEATURE_COMPAT_EXT_ATTR is.
Number of groups: 7
Minimum / maximum journal block: 16616 / 20729
Loading journal descriptors... sorting... done
The oldest inode block that is still in the journal, appears to be from 1380011783 = Tue Sep 24 16:36:23 2013
Number of descriptors in journal: 67; min / max sequence numbers: 2 / 12
Loading disk1.ext3grep.stage2... done
Restoring ext3grep
这里要注意的是,“--restore-file”后面指定的是恢复文件路径,这个路径应该是文件的相对路径,这里的相对路径指的是相对指定设备的路径,比如,设备/data0/diskl的挂载点是/disk,而ext3grep.txt文件就在/disk目录下,因此直接指定文件名就可以了。如果要恢复/disk/ext3grep/hosts文件,那么指定的参数应该是“ext3grep/hosts",也就是上面代码中所指定的形式。
通过“--restore-inode”参数,只需指定文件对应的inode值即可恢复文件。操作如下(其中inode值为12的是profile文件):
[root@localhost opt]# ext3grep /data0/disk1 --restore-inode 12
Running ext3grep version 0.10.2
WARNING: I don't know what EXT3_FEATURE_COMPAT_EXT_ATTR is.
Number of groups: 7
Minimum / maximum journal block: 16616 / 20729
Loading journal descriptors... sorting... done
The oldest inode block that is still in the journal, appears to be from 1380011783 = Tue Sep 24 16:36:23 2013
Number of descriptors in journal: 67; min / max sequence numbers: 2 / 12
Restoring inode.12
下面进入RESTORED_FILES目录,验证文件是否成功恢复。
[root@localhost opt]# cd RESTORED_FILES/
[root@localhost RESTORED_FILES]# ls
ext3grep ext3grep.txt inode.12
[root@localhost RESTORED_FILES]# md5sum ext3grep.txt
5afe55495cdb666daad667e1cd797dcb ext3grep.txt
[root@localhost RESTORED_FILES]# md5sum inode.12
1153c583b1bf1dc7779c66af2e509a2b inode.12
根据校验结果可知,这个校验码与文件被删除之前的校验码完全一致,因此,通过这个方式恢复出来的文件是完整的。
5.恢复所有已删除数据
当需要恢复的文件较少时,通过前面介绍的指定文件的方式进行逐个恢复是可行的。但是如果要恢复很多个文件,如1OOO个以上,还采取逐个指定的方式,效率是非常低下的,此时就要利用ext3grep命令的“--restore-all"参数了。具体操作如下:
[root@localhost RESTORED_FILES]# ext3grep /data0/disk1 --restore-all
Running ext3grep version 0.10.2
WARNING: I don't know what EXT3_FEATURE_COMPAT_EXT_ATTR is.
Number of groups: 7
Minimum / maximum journal block: 16616 / 20729
Loading journal descriptors... sorting... done
The oldest inode block that is still in the journal, appears to be from 1380011783 = Tue Sep 24 16:36:23 2013
Number of descriptors in journal: 67; min / max sequence numbers: 2 / 12
Writing output to directory RESTORED_FILES/
Finding all blocks that might be directories.
D: block containing directory start, d: block containing more directory entries.
Each plus represents a directory start that references the same inode as a directory start that we found previously.
Searching group 0: DD
Searching group 1:
Searching group 2: +++++
Searching group 3:
Searching group 4:
Searching group 5:
Searching group 6:
Writing analysis so far to 'disk1.ext3grep.stage1'. Delete that file if you want to do this stage again.
Result of stage one:
2 inodes are referenced by one or more directory blocks, 1 of those inodes is still allocated.
1 inodes are referenced by more than one directory block, 1 of those inodes is still allocated.
0 blocks contain an extended directory.
Result of stage two:
1 of those inodes could be resolved because it is still allocated.
All directory inodes are accounted for!
Writing analysis so far to 'disk1.ext3grep.stage2'. Delete that file if you want to do this stage again.
Restoring ext3grep
Restoring ext3grep.txt
Restoring initrd-2.6.32-358.el6.i686kdump.img
Restoring profile
[root@localhost RESTORED_FILES]# cd RESTORED_FILES/
[root@localhost RESTORED_FILES]# ls -al
总用量 3484
drwxr-xr-x. 3 root root 4096 9月 24 16:53 .
drwxr-xr-x. 3 root root 4096 9月 24 16:53 ..
-rw-r--r--. 1 root root 158 9月 24 16:37 ext3grep
-rw-r--r--. 1 root root 14 9月 24 16:36 ext3grep.txt
-rw-------. 1 root root 3542202 9月 24 16:36 initrd-2.6.32-358.el6.i686kdump.img
drwx------. 2 root root 4096 9月 24 16:38 lost+found
-rw-r--r--. 1 root root 1796 9月 24 16:36 profile
根据这个输出可知,“--restore-all”参数将指定存储设备中可以恢复的文件都恢复出来并放到了RESTORED_FILES目录中。“---restore-all”参数对恢复大量数据文件是非常有用的。