在linux系統中,相信都有誤刪文件的經歷,rm -rf 可刪除一切文件。當刪除了一些重要數據,應該如何找回呢?node
extundelete是一款強大的linux數據恢復工具,可恢復ext3和ext4文件系統中的文件。linux
誤刪文件後千萬不要慌,第一件要作的事就是卸載分區或以只讀方式從新掛載分區。c++
安裝extundelete vim
# yum install gcc-c++ e2fsprogs-develbash
# cd extundelete-0.2.4ide
# make工具
# make installui
查看sdb1分區有哪些內容this
# lsspa
wan wanyu xiaoming #wan爲文件,wanyu和xiaoming爲目錄
模擬誤刪
# rm /back/* -rf
以只讀方式從新掛載sdb1分區
# mount -o remount,ro /dev/sdb1
以當前分區第二個inode號開始查找被刪除的文件
# extundelete --inode 2 /dev/sdb1
NOTICE:Extended attributes are not restored. Loading filesystem metadata ... 160 groupsloaded. Group: 0 Contents of inode 2: 0000 | ed 41 00 00 00 10 00 00 07 a7 a2 5531 a7 a2 55 | .A.........U1..U 0010 | 31 a7 a2 55 00 00 00 00 00 00 02 0008 00 00 00 | 1..U............ 0020 | 00 00 00 00 1f 00 00 00 21 24 00 0000 00 00 00 | ........!$...... 0030 | 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 | ................ 0040 | 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 | ................ 0050 | 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 | ................ 0060 | 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 | ................ 0070 | 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 | ................ 0080 | 1c 00 00 00 fc 53 e0 b0 fc 53 e0 b05c e7 9e 3a | .....S...S..\..: 0090 | fc a2 a2 55 00 00 00 00 00 00 00 0000 00 00 00 | ...U............ 00a0 | 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 | ................ 00b0 | 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 | ................ 00c0 | 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 | ................ 00d0 | 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 | ................ 00e0 | 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 | ................ 00f0 | 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 | ................ Inode is Allocated File mode: 16877 Low 16 bits of Owner Uid: 0 Size in bytes: 4096 Access time: 1436722951 Creation time: 1436722993 Modification time: 1436722993 Deletion Time: 0 Low 16 bits of Group Id: 0 Links count: 2 Blocks count: 8 File flags: 0 File version (for NFS): 0 File ACL: 0 Directory ACL: 0 Fragment address: 0 Direct blocks: 9249, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0 Indirect block: 0 Double indirect block: 0 Triple indirect block: 0 File name | Inodenumber | Deleted status . 2 .. 2 wanyu 1048577 Deleted xiaoming 786433 Deleted wan 11 Deleted
恢復單個文件
# extundelete /dev/sdb1 --restore-file wan
# ls RECOVERED_FILES/
Wan
恢復單個目錄
# extundelete /dev/sdb1 --restore-directory/wanyu
# ls RECOVERED_FILES/wanyu/
inittab wan xiaoming yu
恢復inode號對應的文件
# extundelete /dev/sdb1 --restore-inode 11
# ls RECOVERED_FILES/
file.11 wan wanyu
恢復res_file中顯示的文件
# vim res_file
wan
# extundelete /dev/sdb1 --restore-files res_file
NOTICE: Extended attributes are notrestored. WARNING: EXT3_FEATURE_INCOMPAT_RECOVER isset. The partition should be unmounted toundelete any files without further data loss. If the partition is not currently mounted,this message indicates it was improperly unmounted, and you shouldrun fsck before continuing. If you decide to continue, extundelete mayoverwrite some of the deleted files and make recovering those filesimpossible. You should unmount the file system and check it with fsck beforeusing extundelete. Would you like to continue? (y/n) y Loading filesystem metadata ... 160 groupsloaded. Loading journal descriptors ... 172descriptors loaded. Successfully restored file wan
恢復全部文件
# extundelete /dev/sdb1 --restore-all