LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1433|回复: 3

教你如何恢复被删的文件

[复制链接]
发表于 2004-8-17 00:59:41 | 显示全部楼层 |阅读模式
我今天误删了一些文件,觉得很可惜,就萌生要恢复他们的想法。经过资料的查询,以及自己的摸索,终于找到成功恢复被删文件的方法。原来如此简单。

1:赶紧umount你删文件所在的设备。千万不要在写任何东西进去,以免覆盖。
2:以我的情况为例,因我的文件是在/dev/hda7被删的。所以debugfs /dev/hda7
3:输入指令:lsdel查看被删的文件inode。
debugfs:  lsdel
Inode  Owner  Mode    Size    Blocks   Time deleted
    12      0 100644 17076307 4176/4176 Mon Aug 16 23:43:34 2004
    13      0 100644   8740    3/   3 Mon Aug 16 23:43:34 2004
    14      0 100644 85471819 20890/20890 Mon Aug 16 23:43:34 2004
    15      0 100644 180271   46/  46 Mon Aug 16 23:43:34 2004

4:显示你需要恢复文件的inode的信息。
debugfs:  stat <12>
Inode: 12   Type: regular    Mode:  0644   Flags: 0x0   Generation: 9997
User:     0   Group:     0   Size: 17076307
File ACL: 0    Directory ACL: 0
Links: 0   Blockcount: 33408
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x4120d626 -- Mon Aug 16 23:43:34 2004
atime: 0x4120d580 -- Mon Aug 16 23:40:48 2004
mtime: 0x4120d4ca -- Mon Aug 16 23:37:46 2004
dtime: 0x4120d626 -- Mon Aug 16 23:43:34 2004
BLOCKS:
(0-11):520-531, (IND):532, (12-1035):533-1556, (DIND):1557, (IND):1558, (1036-2059):1559-2582, (
IND):2583, (2060-3083):2584-3607, (IND):3608, (3084-4107):3609-4632, (IND):4633, (4108-4169):463
4-4695
TOTAL: 4176

5:dump inode所有块(block)的内容到文件中。
debugfs:  dump <12> /tmp/recover

6:quit

完了。/tmp/recover就是你要恢复的文件了。赶紧cd /tmp
root@lfs:tmp# file recover。
recover: bzip2 compressed data, block size = 900k
成功了。tar xvfj recover试试看。呵呵!
这种方法屡试屡爽。真的很好用。大家可以试试。
发表于 2004-8-17 03:21:13 | 显示全部楼层
你用的是什么文件系统,ext2, ext3, reiserfs?
发表于 2004-8-17 08:06:49 | 显示全部楼层
这个经验好啊!
是什么文件系统呢?
 楼主| 发表于 2004-8-17 13:01:27 | 显示全部楼层
我当时试的是ext2。非常不幸,这种方法不支持ext3。
ext3的数据结构不支持任何undelete的方法。
所以我建议大家有重要的备份资料最好用ext2文件系统。

Q: How can I recover (undelete) deleted files from my ext3 partition?
Actually, you can't! This is what one of the developers, Andreas Dilger, said about it:

In order to ensure that ext3 can safely resume an unlink after a crash, it actually zeros out the block pointers in the inode, whereas
ext2 just marks these blocks as unused in the block bitmaps and marks the inode as "deleted" and leaves the block pointers alone.

Your only hope is to "grep" for parts of your files that have been deleted and hope for the best.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表