欲哭无泪,痛定思痛

肠子都悔青了才来研究这些东西。。。

希望大家不要像我这样,一定要:
1。备份
2。不要轻易使用rm命令
3。恢复尽量用文件系统自带的恢复命令而不是恢复软件如testdisk和pho×ec。testdisk只能恢复误删的分区,而pho×ec只能恢复特定的80几种格式的文件,连文件名、目录名统统丢失,还有不少错误(如文件类型之类),只能说是下下策。

这可是血的教训阿,大家切记!切记!

下面是我恢复reiserfs分区下误删文件的过程。

因为我有专门一个分区装ubuntu最新测试版的,所以省了不少事情,当然如果你有live cd,那也一样方便。
********************************************
-1。最优先的事项:用dd命令或clonezilla对该分区进行备份,以免恢复失败把原来还在的文件都给删没了。推荐clonezilla。

0。误删文件后,千万千万什么都别干,直接重启机器,进入live cd或其他linux系统。

1。进入非误删文件的系统,,打开终端或直接进控制台。

2。输入

代码:
sudo umount /dev/xxx

xxx是你误删文件所在的分区名,一般是sdax或hdax等等。

3。输入

代码:
sudo reiserfsck –rebuild-tree -S -l undelete.log /dev/xxx

重建文件系统。提示输入“Yes”,注意Y是大写的,否则不行。也不能直接输入”y”,那根本没用。

4。等待直到一切都结束,你的误删的文件应该回来了,或许有一些丢失或错误。
过程应该是这样的(这个不是我的):

代码:
reiserfsck 3.6.19 (2003 www.namesys.com)
*************************************************************
** Do not run the program with –rebuild-tree unless **
** something is broken and MAKE A BACKUP before using it. **
** If you have bad sec×s on a drive it is usually a bad **
** idea to continue using it. Then you probably should get **
** a working hard drive, copy the file system from the bad **
** drive to the good one — dd_rescue is a good tool for **
** that — and only then run this program. **
** If you are using the latest reiserfsprogs and it fails **
** please email bug reports to reiserfs-list@namesys.com, **
** providing as much information as possible — your **
** hardware, kernel, patches, settings, all reiserfsck **
** messages (including version), the reiserfsck logfile, **
** check the syslog file for any related information. **
** If you would like advice on using this program, support **
** is available for $25 at www.namesys.com/support.html. **
*************************************************************
Will rebuild the filesystem (/dev/loop0) tree
Will put log info to ‘undelete.log’
Do you want to run this program?[N/Yes] (note need to type Yes if you do): Yes

Replaying journal..
Reiserfs journal ‘/dev/loop0′ in blocks [18..8211]: 0 transactions replayed
###########
reiserfsck –rebuild-tree started at Thu Dec 1 21:01:53 2005
###########
Pass 0:
The whole partition (251984 blocks) is to be scanned
Skipping 8218 blocks (super block, journal, bitmaps) 243766 blocks will be read
0%….20%….40%….60%….80%….100% left 0, 6588 /sec
“r5″ hash is selected
Flushing..finished
Read blocks (but not data blocks) 243766
Leaves among those 56
Objectids found 77
Pass 1 (will try to insert 56 leaves):
Looking for allocable blocks .. finished
0%….20%….40%….60%….80%….100% left 0, 56 /sec
Flushing..finished
56 leaves read
45 inserted
11 not inserted
non-unique pointers in indirect items (zeroed) 633
Pass 2:
0%….20%….40%….60%….80%….100% left 0, 0 /sec
Flushing..finished
Leaves inserted item by item 11
Pass 3 (semantic):
Flushing..finished
Files found: 42
Direc×ies found: 12
Pass 3a (looking for lost dir/files):
Looking for lost direc×ies:
Looking for lost files:0 /sec
Flushing..finished 48, 0 /sec
Objects without names 16
Dirs linked to /lost+found: 1
Files linked to /lost+found 15
Pass 4 - finished done 44, 0 /sec
Flushing..finished
Syncing..finished
###########
reiserfsck finished at Thu Dec 1 21:02:31 2005
###########

5。修复完毕,所有恢复记录都在你的undelete.log下。你可以一个一个对照着恢复。接下来就是挂载你开始卸下的分区

代码:
sudo mount -a

看到你删掉的文件了么?如果没有,一般就只会在lost+found目录里面,需要root权限才可以进去。奇怪的是用root 不行,只能gksu nautilus进去,当然你也可以把权限改掉。
哈哈,你手快删掉的东西都在吧?如果你在删掉之后还干了一些事情,那么恐怕就不能保证都在了。
*********************************************

好了,这是一个教训,写本文是为了忘却的纪念和备份恢复方法,同时“以儆效尤”。

至于其他文件系统,我想应该也差不多,看看你们文件系统相关操作或搜一下狗狗即可。

后记

因为开始没有想到这么做,做了不少无法挽回的事情,包括把这个区又进行了大量的文件操作,但幸运的是居然还有不少死都不能丢的数据给找回来了,不幸中之大幸。希望大家碰到这种情况时,切莫惊慌,照我说的做就ok了。

Leave a Reply