免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2301 | 回复: 2
打印 上一主题 下一主题

ext3grep恢复ext3文件系统下误删的文件 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-02-05 14:21 |只看该作者 |倒序浏览

环境说明:
OS:Centos5.2 文件系统为ext3   
1.首先模拟一个分区:

mkdir /home/store
cd /home/store
dd if=/dev/zero of=file count=102400
mkfs.ext3 file
mount -o loop /home/store/file /mnt/
可以看到已经挂上去了
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       13G 4.7G 7.5G 39% /
/dev/hda1 99M 18M 77M 19% /boot
tmpfs 107M 0 107M 0% /dev/shm
/home/store/file 49M 4.9M 42M 11% /mnt

了实验我们把/boot整个copy到/mnt里面
cp -r /boot /mnt/
cd /mnt/boot

ls
System.map-2.6.18-92.1.17.el5 lost+found
System.map-2.6.18-92.el5 message
config-2.6.18-92.1.17.el5 symvers-2.6.18-92.1.17.el5.gz
config-2.6.18-92.el5 symvers-2.6.18-92.el5.gz
grub vmlinuz-2.6.18-92.1.17.el5
initrd-2.6.18-92.1.17.el5.img vmlinuz-2.6.18-92.el5
initrd-2.6.18-92.el5.img
以上是boot里面的内容
现在删除/mnt/boot
rm -rf /mnt/boot
ls -al /mnt/
total 21
drwxr-xr-x 3 root root 1024 Feb 1 15:15 .
drwxr-xr-x 26 root root 4096 Feb 1 14:50 ..
drwx------ 2 root root 12288 Feb 1 15:09 lost+found
boot已经被删除
2.安装ext3grep
ext3grep的源码包在这里
http://code.google.com/p/ext3grep/downloads/list
tar -zxvf ext3grep-0.10.1.tar.gz
cd ext3grep-0.10.1
./configure
make&&make install
3.开始恢复
卸载文件所在的分区也就是/home/store/file
umount /home/store/file
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       13G 4.7G 7.5G 39% /
/dev/hda1 99M 18M 77M 19% /boot
tmpfs 107M 0 107M 0% /dev/shm
查看一下已经卸载
扫描分区
ext3grep /home/store/file --ls --inode 2
Running ext3grep version 0.10.1
Number of groups: 7
Loading group metadata... done
Minimum / maximum journal block: 447 / 4561
Loading journal descriptors... sorting... done
The oldest inode block that is still in the journal, appears to be from 1233472221 = Sun Feb 1 15:10:21 2009
Number of descriptors in journal: 100; min / max sequence numbers: 2 / 9
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: DDD+DD+
Searching group 1: ++
Searching group 2: +
Searching group 3:
Searching group 4:
Searching group 5:
Searching group 6:
Writing analysis so far to 'file.ext3grep.stage1'. Delete that file if you want
to do this stage again.
Result of stage one:
  5 inodes are referenced by one or more directory blocks, 2 of those inodes are still allocated.
  4 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:
  2 of those inodes could be resolved because they are still allocated.
  3 inodes could be resolved because all refering blocks but one were journal blocks.
All directory inodes are accounted
Writing analysis so far to 'file.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 2 d 2 drwxr-xr-x ..
   2 end d 11 drwx------ lost+found
   3 end d 1833 D 1233472535 Sun Feb 1 15:15:35 2009 drwxr-xr-x boot
接下来我们来恢复boot下面的grub
ext3grep /home/store/file --restore-file boot/grub/grub.conf

Running ext3grep version 0.10.1
Number of groups: 7
Minimum / maximum journal block: 447 / 4561
Loading journal descriptors... sorting... done
The oldest inode block that is still in the journal, appears to be from 1233472221 = Sun Feb 1 15:10:21 2009
Number of descriptors in journal: 100; min / max sequence numbers: 2 / 9
Loading file.ext3grep.stage2... done
Restoring boot/grub/grub.conf
查看是否恢复成功,恢复的文件在RESTORED_FILES里面
cd RESTORED_FILES/boot/grub/
ls -l
total 4
-rw------- 1 root root 769 Feb 1 15:10 grub.conf
很显然成功了。
接下来我们恢复整个boot文件夹里面的内容
ext3grep /home/store/file --restore-all
Running ext3grep version 0.10.1
Number of groups: 7
Minimum / maximum journal block: 447 / 4561
Loading journal descriptors... sorting... done
The oldest inode block that is still in the journal, appears to be from 1233472221 = Sun Feb 1 15:10:21 2009
Number of descriptors in journal: 100; min / max sequence numbers: 2 / 9
Writing output to directory RESTORED_FILES/
Loading file.ext3grep.stage2... done
Restoring boot/System.map-2.6.18-92.1.17.el5
Restoring boot/System.map-2.6.18-92.el5
Restoring boot/config-2.6.18-92.1.17.el5
Restoring boot/config-2.6.18-92.el5
Restoring boot/grub/device.map
Restoring boot/grub/e2fs_stage1_5
Restoring boot/grub/fat_stage1_5
Restoring boot/grub/ffs_stage1_5
Restoring boot/grub/grub.conf
Restoring boot/grub/iso9660_stage1_5
Restoring boot/grub/jfs_stage1_5
WARNING: Failed to set access and modification time on RESTORED_FILES/boot/grub/menu.lst: Function not implemented
Restoring boot/grub/minix_stage1_5
Restoring boot/grub/reiserfs_stage1_5
Restoring boot/grub/splash.xpm.gz
Restoring boot/grub/stage1
Restoring boot/grub/stage2
Restoring boot/grub/ufs2_stage1_5
Restoring boot/grub/vstafs_stage1_5
Restoring boot/grub/xfs_stage1_5
Restoring boot/initrd-2.6.18-92.1.17.el5.img
Restoring boot/initrd-2.6.18-92.el5.img
Restoring boot/message
Restoring boot/symvers-2.6.18-92.1.17.el5.gz
Restoring boot/symvers-2.6.18-92.el5.gz
Restoring boot/vmlinuz-2.6.18-92.1.17.el5
Restoring boot/vmlinuz-2.6.18-92.el5
比较恢复前后两个boot文件的大小:
du -sh RESTORED_FILES/boot
12M RESTORED_FILES/boot
du -sh /boot
12M /boot

结果很明显恢复成功。


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/30312/showart_1814218.html

论坛徽章:
0
2 [报告]
发表于 2009-12-23 16:57 |只看该作者
为什么我恢复的文件,总就12kb  。。。每个文件都是。。。你碰到过吗?

[root@perl /]#  ext3grep /dev/loop1 --restore-file  session.log.2009-12-20
Running ext3grep version 0.10.1
Number of groups: 13
Minimum / maximum journal block: 522 / 4636
Loading journal descriptors... sorting... done
The oldest inode block that is still in the journal, appears to be from 1261557992 = Wed Dec 23 16:46:32 2009
Number of descriptors in journal: 19; min / max sequence numbers: 2 / 4
Loading loop1.ext3grep.stage2... done
Restoring session.log.2009-12-20
WARNING: Failed to restore session.log.2009-12-20: encountered a reused or corrupted (double/triple) indirect block!
Running iterate_over_all_blocks_of again with diagnostic messages ON:
Processing direct blocks... 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647
Processing indirect block 4648: entry 0 contains block number 1881175072, which is too large.

论坛徽章:
0
3 [报告]
发表于 2009-12-23 17:14 |只看该作者
不错不错,抽空试试。
先收藏一下。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP