Extundelete 數據恢復
“rm -rf /*” 是我們經常使用的命令,操作不慎全盤接蹦,從刪庫到跑路,身為過來人的我們都經歷過rm帶來的痛苦。
不要慌,當我們有了Extundelete就可以解決一系列誤刪除操作問題。下面我會詳細介紹一下這款救命工具。
介紹
常見的開源恢復工具有:debugfs、R-Linux、ext3grep、extundelete
- ext3grep:只支持 ext3 文件系統
- extundelete:支持 ext3 和 ext4 文件系統
實現原理:通過分析文件系統日志,解析出所有文件的 inode 信息,利用 inode 去查找所在 block ,利用 dd 備份出以刪除的數據。
搭建
- 包名:extundelete-0.2.4.tar.bz2
- 可靠的下載地址:https://pan.baidu.com/s/1WQ8Ns6_sz9yZmkUGVs7ZyA
- 更可靠的密碼:5c6a
1、安裝依賴包
yum -y install e2fsprogs-devel gcc
2、解壓工具包
tar jxf extundelete-0.2.4.tar.bz2
3、指定安裝目錄、編譯、編譯安裝
./configure ; make ; make install
使用
常用參數:
--after dtime 時間參數,表示在某段時間之后被刪除的文件或目錄 --before dtime 時間參數,表示在某段時間之前被刪除的文件或目錄 --inode ino 顯示節點 ino 的信息 --block blk 顯示數據塊 blk 的信息 --restore-inode ino 表示恢復節點 ino 的文件,用來恢復單個文件 --restore-file path 表示恢復指定路徑下的文件,用來恢復目錄下所有文件 --restore-all 表示恢復所有被刪除的目錄跟文件
開啟恢復流程:
1、查找被刪除文件所在目錄 id
ls -id /xxx/xxx/
注:輸出最左側為ID號。
2、查看被刪除的上層目錄 inode
# extundelete 所在分區名稱 --inode ID號 extundelete /dev/sdb1 --inode 130619

# 可以看到被刪除的目錄 package 狀態為 Deleted ,inode 為 137256 File name | Inode number | Deleted status . 130619 .. 130587 package 137256 Deleted apr-1.5.1 140038 apr-util-1.5.4 535002 httpd-2.4.10 535320 pcre-8.30 656184 siege-3.0.8 656483 libmcrypt-2.5.8 144383 package.xml 146709 mysql-5.6.4-m7 140588 memcache-2.2.7 146712 php-5.4.13 667097 redis-2.2.5 269016 memcached-1.4.15 146806 libevent-master 539531 Deleted
3、恢復數據、恢復指定目錄下所有刪除的數據
# extundelete 數據所在分區名稱 --restore-directory 恢復數據的目錄 extundelete /dev/sdb1 --restore-directory /xxx/xxx/xxx/

NOTICE: Extended attributes are not restored. WARNING: EXT3_FEATURE_INCOMPAT_RECOVER is set. The partition should be unmounted to undelete any files without further data loss. If the partition is not currently mounted, this message indicates it was improperly unmounted, and you should run fsck before continuing. If you decide to continue, extundelete may overwrite some of the deleted files and make recovering those files impossible. You should unmount the file system and check it with fsck before using extundelete. Would you like to continue? (y/n) y Loading filesystem metadata ... 151 groups loaded. Loading journal descriptors ... 22517 descriptors loaded. Searching for recoverable inodes in directory /usr/local/src/package ... 1679 recoverable inodes found. Looking through the directory structure for deleted files ... Block 578312 is allocated. Unable to restore inode 146713 (usr/local/src/package/redis-2.2.5.tgz): Space has been reallocated. Unable to restore inode 539531 (usr/local/src/package/libevent-master): Space has been reallocated. 1670 recoverable inodes still lost.
4、完成恢復后續工作
# 恢復數據后,會把恢復數據送到當前路徑的RECOVERED_FILES/內,再把恢復的數據拿回原處 cp RECOVERED_FILES/xxx/xxx/* /xxx/xxx/xxx/
結束..