EXT4中恢復使用rm命令誤刪除的文件

起因:前幾天在公司服務器上誤操作將ORACLE某表空間文件給刪除了,結果導致幾張表不能正常訪問
遂谷歌了一把發現了神器 extundelete(如果是ext3文件系統請使用ext3grep,本人未做測試),這玩意可比瘟得死下面的各種恢復工具強大多了(至少本人是這麼認爲的),下面看步驟:
一、下載及安裝軟件
extundelete 主頁:http://extundelete.sourceforge.net/
下載地址:http://nchc.dl.sourceforge.net/project/extundelete/extundelete/0.2.0/extundelete-0.2.0.tar.bz2
ubuntu用戶可直接安裝: apt-get install extundelete

[root@www ~]# wget http://nchc.dl.sourceforge.net/project/extundelete/extundelete/0.2.0/extundelete-0.2.0.tar.bz2
[root@www ~]# tar xf extundelete-0.2.0.tar.bz2
[root@www ~]# cd extundelete-0.2.0
[root@www extundelete-0.2.0]# ./configure && make && make install    # 如果提示找不到ext2fs庫,使用 yum -y install e2fsprogs* 安裝

二、執行刪除操作

[root@www ~]# df -Th
文件系統    類型      容量  已用  可用 已用%% 掛載點
/dev/mapper/VolGroup-lv_root
              ext4     38G  2.2G   34G   6% /
tmpfs        tmpfs    122M     0  122M   0% /dev/shm
/dev/sda1     ext4    485M   30M  430M   7% /boot
/dev/sdb1     ext4   1003M   18M  935M   2% /mnt/test
[root@www ~]# ls /mnt/test/
extundelete-0.2.0.tar.bz2  hosts  lost+found  resolv.conf
[root@www ~]# rm -rf /mnt/test/hosts /mnt/test/resolv.conf
[root@www ~]# ls /mnt/test/
extundelete-0.2.0.tar.bz2  lost+found

三、數據恢復

1.卸載需要恢復文件的分區

[root@www ~]# fuser -k /mnt/test/               <-- 結束使用某分區的進程樹
[root@www ~]# umount /mnt/test                  <-- 卸載分區

2.使用extundelete查看分區上存在的文件

[root@www ~]# extundelete --inode 2 /dev/sdb1    # --inode 爲查找某i節點中的內容,使用2則說明爲搜索,如果需要進入目錄搜索,只須要指定目錄I節點即可

上圖中紅框內容可以看出,被刪除的兩個文件已經被找到,狀態爲已經刪除,接下來就將它們恢復出來

[root@www ~]# extundelete --restore-inode 13 /dev/sdb1    # --restore-inode 恢復指定的I節點文件,默認全將恢復出來的文件放在當前路徑 RECOVERED_FILES/ 目錄下,文件名爲 file.I節點號
WARNING: Extended attributes are not restored.
Loading filesystem metadata ... 8 groups loaded.
Loading journal descriptors ... 21 descriptors loaded.
Writing output to directory RECOVERED_FILES/
Restored inode 13 to file RECOVERED_FILES/file.13
[root@www ~]# extundelete --restore-inode 14 /dev/sdb1
WARNING: Extended attributes are not restored.
Loading filesystem metadata ... 8 groups loaded.
Loading journal descriptors ... 21 descriptors loaded.
Restored inode 14 to file RECOVERED_FILES/file.14
[root@www ~]# ls RECOVERED_FILES/
file.13  file.14
[root@www ~]# mount /dev/sdb1 /mnt/test/
[root@www ~]# mv RECOVERED_FILES/file.13 /mnt/test/resolv.conf
[root@www ~]# mv RECOVERED_FILES/file.14 /mnt/test/hosts
[root@www ~]# cat /mnt/test/hosts            # 查看被恢復出來的文件 是否與源文件一致
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.250   www.skyelek.com www
192.168.1.250   svn.skkelek.com svn
[root@www ~]# cat /mnt/test/resolv.conf
; generated by /sbin/dhclient-script
search www.skyelek.com skyelek.com
nameserver 192.168.1.200

轉自http://www.linuxyunwei.com/2012/08/ext4

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章