恢复linuxext4分区上误删除的⽂件。
我是使⽤  Xmanager Enterprise 4 来连接CentOS Linux 6.4 的。
可恶的XManager有⼀个恶⼼的bug,时不时的出现焦点问题:
2012年10⽉15⽇星期⼀,14:44:01
==============================================
温馨提⽰: Xmanager有个⽑病
就是时不时的出现窗⼝之间焦点的切换必须点击菜单栏上⾯的 title 才可以,⽽且不能⽤alt拖动窗⼝了.有时⼜可以..
解决⽅法:打开后,按住 win+D  再win+D
焦点的切换就会发⽣变化了...可以点击内容切换
⽽且,也可以使⽤alt 移动窗⼝了....
2013年5⽉25⽇今天,14:09:40
==============================================
键盘上按p键也会失效。
需要win+D 多次才会解决这个问题
不知道有⼈遇到过这个问题没,使⽤ XMing 来连接xdmcp 倒是没问题,⽽且xmanager⽆法hook快捷键,⽤起来快捷键使⽤起来不⽅便,这个就不说了,但是上⾯的我确认是⼀个 BUG。很恶⼼。
这次我要删除⼀个桌⾯的⽂件,点击后,shift+del 回车,快速删除,⼀看⽂件,没删除,难道。。。看看另⼀个nautilus 窗⼝,正在浏览⾃⼰的ftp服务,缺少了⼀个⽂件夹,我勒个去啊。。。。。。。。。。
如果是ntfs分区,windows下的,我可以diskgenius + winhex 速度恢复⽂件。但是ext4分区下,我真没⼲过这种事情啊。
搜索⼀下,
my.oschina/Qunero/blog/8607
今天⼀时⼿快 rm -rf .* ,删除了⼀个重要邮件⽬录,幸好通过extundelete恢复了。
记下操作流程:
1.准备⼯作
主要通过 extundelete 0.2.0完成恢复
sourceforge/projects/extundelete/files/latest/download
需要依赖两个包
sudo aptitude install e2fsprogs e2fslibs-dev
下载页⾯extundelete.sourceforge/
快速下载: download extundelete
编译三部曲
./configure
make
sudo make install
2.如果分区已经挂载,先umount,并且在将要恢复的地⽅查看空间⼤⼩
df -h ./
如果你要恢复的是根⽬录或者系统⽬录就只有拿硬盘挂到另外⼀台电脑上操作了。
3.恢复制定分区下所有删除⽂件,默认恢复到执⾏命令的⽬录下,⽂件夹名字为RECOVERED_FILES,使⽤详情请参考:extundelete --help 运⾏的结果
sudo extundelete /dev/sda8 --restore-all
---------------------------------------------
$ extundelete --help
Usage: extundelete [options] [--] device-file
Options:
--version, -[vV]      Print version and exit successfully.
--help,                Print this help and exit successfully.
--superblock          Print contents of superblock in addition to the rest.
If no action is specified then this option is implied.
--journal              Show content of journal.
--after dtime          Only process entries deleted on or after 'dtime'.
--before dtime        Only process entries deleted before 'dtime'.
Actions:
--inode ino            Show info on inode 'ino'.
--block blk            Show info on block 'blk'.
--restore-inode ino[,ino,...]
Restore the file(s) with known inode number 'ino'.
The restored files are created in ./RESTORED_FILES
with their inode number as extension (ie, file.12345).
--restore-file 'path'  Will restore file 'path'. 'path'is relative to root
of the partition and does not start with a '/' (it
must be one of the paths returned by --dump-names).
The restored file is created in the current
directory as'RECOVERED_FILES/path'.
--restore-files 'path' Will restore files which are listed in the file 'path'.
Each filename should be in the same format as an option
to --restore-file, and there should be one per line.
-
-restore-all          Attempts to restore everything.
-j journal            Reads an external journal from the named file.
-b blocknumber        Uses the backup superblock at blocknumber when opening
the file system.
-B blocksize          Uses blocksize as the block size when opening the file
system.  The number should be the number of bytes.
搞定。恢复的⽂件在当前⽬录下的  RECOVERED_FILES ⽂件夹内。
再送⼀篇⽂章,我反正没成功,因为是在vsftpd下删除的⽂件,可能和 rm -rf 删除机制不太⼀样??
系统管理:恢复误删除的Linux⽂件全攻略2008-08-01 20:18
作为⼀个多⽤户、多任务的操作系统,Linux下的⽂件⼀旦被删除,是难以恢复的。尽管删除命令只是在⽂件节点中作删除标记,并不真正清除⽂件内容,但是其他⽤户和⼀些有写盘动作的进程会很快覆盖这些数据。不过,对于家庭单机使⽤的Linux 1、Ext2⽂件系统结构的简单介绍
在Linux所⽤的Ext2⽂件系统中,⽂件是以块为单位存储的,默认情况下每个块的⼤⼩是1K,不同的块以块号区分。每个⽂件还有⼀个节点,节点中包含有⽂件所有者,读写权限,⽂件类型等信息。对于⼀个⼩于12个块的⽂件,在节点中直接存储⽂2、恢复被误删⽂件的⽅法
linux命令查看文件夹大小⼤多数Linux发⾏版都提供⼀个debugfs⼯具,可以⽤来对Ext2⽂件系统进⾏编辑操作。不过在使⽤这个⼯具之前,还有⼀些⼯作要做。
⾸先以只读⽅式重新挂载被误删的⽂件所在分区。使⽤如下命令:(假设⽂件在/usr分区)
mount –r –n –o remount /usr -r表⽰只读⽅式挂载;-n表⽰不写⼊/etc/mtab,如果是恢复/etc上的⽂件,就加上这个参数。如果系统说xxx partion busy,可以⽤fuser命令查看⼀下是哪些进程使⽤这个分区上的⽂件:
fuser –v –m /usr
如果没有什么重要的进程,⽤以下命令停掉它们:
fuser -k –v –m /usr
然后就可以重新挂载这些⽂件系统了。
如果是把所有的⽂件统⼀安装在⼀个⼤的/分区当中,可以在boot提⽰符下⽤linux single进⼊单⽤户模式,尽量减少系统进程向硬盘写⼊数据的机会,要不⼲脆把硬盘挂在别的机器上。另外,恢复出来的数据不要写到/上⾯,避免破坏那些有⽤的数据。mount –r –n /dev/hda1 /mnt/had
然后就可以执⾏debugfs:(假设Linux在 /dev/hda5)
#debugfs /dev/hda5
就会出现debugfs提⽰符debugfs:
使⽤lsdel命令可以列出很多被删除的⽂件的信息:
debugfs:lsdel
debugfs: 2692 deleted inodes found.
Inode Owner Mode Size Blocks Time deleted
164821 0 100600 8192 1/ 1 Sun May 13 19:22:46 2001
…………………………………………………………
36137 0 100644 4 1/ 1 Tue Apr 24 10:11:15 2001
196829 0 100644 149500 38/ 38 Mon May 27 13:52:04 2001
debugfs:
列出的⽂件有很多(这⾥到2692个),第⼀字段是⽂件节点号,第⼆字段是⽂件所有者,第三字段是读写权限,接下来是⽂件⼤⼩,占⽤块数,删除时间。
然后就可以根据⽂件⼤⼩和删除⽇期判断那些是我们需要的。⽐如我们要恢复节点是196829的⽂件:
可以先看看⽂件数据状态:
debugfs:stat <196829>
Inode: 196829 Type: regular Mode: 0644 Flags: 0x0 Version: 1
User: 0 Group: 0 Size: 149500
File ACL: 0 Directory ACL: 0
Links: 0 Blockcount: 38
Fragment: Address: 0 Number: 0 Size: 0
ctime: 0x31a9a574 -- Mon May 27 13:52:04 2001
atime: 0x31a21dd1 -- Tue May 21 20:47:29 2001
mtime: 0x313bf4d7 -- Tue Mar 5 08:01:27 2001
dtime: 0x31a9a574 -- Mon May 27 13:52:04 2001
BLOCKS:
594810 594811 594814 594815 594816 594817 ………………………………….
TOTAL: 38
然后就可以⽤dump指令恢复⽂件:
debugfs:dump <196829> /mnt/hda/01.sav
这样就把⽂件恢复出来了。退出debugfs:
debugfs:quit
另⼀种⽅法是⼿⼯编辑inode:
debugfs:mi <196829>
Mode [0100644]
User ID [0]
Group ID [0]
Size [149500]
Creation time [0x31a9a574]
Modification time [0x31a9a574]
Access time [0x31a21dd1]
Deletion time [0x31a9a574] 0
Link count [0] 1
Block count [38]
File flags [0x0]
Reserved1 [0]
File acl [0]
Directory acl [0]
Fragment address [0]
Fragment number [0]
Fragment size [0]
Direct Block #0 [594810]
…………………………….
Triple Indirect Block [0]
使⽤mi指令后每次显⽰⼀⾏信息以供编辑,其它⾏可以直接按回车表⽰确认,把deletion time改成0(未删除),Link count改成1。改好后退出debugfs:debugfs:quit
然后⽤fsck检查/dev/hda5
fsck /dev/hda5
程序会说到丢失的数据块,放在lost+found⾥⾯。这个⽬录⾥的⽂件就是我们要的东东。
View Code

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。