下載安裝 extundelete 以前要安裝兩個軟件包 e2fsprogs 和 e2fsprogs-libs
安裝順序:e2fsprogs --> e2fsprogs-libs --> extundelete 逐一編譯安裝
[root@crushlinux ~]# wget http://jaist.dl.sourceforge.net/project/e2fsprogs/e2fsprogs/1.41.14/e2fsprogs-1.41.14.tar.gz
[root@crushlinux ~]# wget http://jaist.dl.sourceforge.net/project/e2fsprogs/e2fsprogs/1.41.14/e2fsprogs-libs-1.41.14.tar.gz
[root@crushlinux ~]# wget http://jaist.dl.sourceforge.net/project/extundelete/extundelete/0.2.4/extundelete-0.2.4.tar.bz2
[root@crushlinux ~]# tar xf e2fsprogs-1.41.14.tar.gz -C /usr/src/
[root@crushlinux ~]# cd /usr/src/e2fsprogs-1.41.14/
[root@crushlinux e2fsprogs-1.41.14]# ./configure
[root@crushlinux e2fsprogs-1.41.14]# make && make installnode
[root@crushlinux ~]# tar xf e2fsprogs-libs-1.41.14.tar.gz -C /usr/src/
[root@crushlinux ~]# cd /usr/src/e2fsprogs-libs-1.41.14/
[root@crushlinux e2fsprogs-libs-1.41.14]# ./configure
[root@crushlinux e2fsprogs-libs-1.41.14]# make && make installlinux
[root@crushlinux ~]# tar xf extundelete-0.2.4.tar.bz2 -C /usr/src/
[root@crushlinux ~]# cd /usr/src/extundelete-0.2.4/
[root@crushlinux extundelete-0.2.4]# ./configure
[root@crushlinux extundelete-0.2.4]# make && make installvim
模擬實驗環境:
新添加一塊硬盤並對其進行分區格式化成ext4,將其掛在到/backupdata目錄上,創建測試文件和目錄。
[root@crushlinux ~]# fdisk /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +200Mide
Command (m for help): w測試
[root@crushlinux ~]# partprobe /dev/sdb
[root@crushlinux ~]# mkfs.ext4 /dev/sdb1
[root@crushlinux ~]# mkdir /backupdata/
[root@crushlinux ~]# mount /dev/sdb1 /backupdata/
[root@crushlinux ~]# mkdir /backupdata/gnutool-delete
[root@crushlinux ~]# cd /backupdata/gnutool-delete
[root@crushlinux gnutool-delete]# man 7 man > file1.txt
[root@crushlinux gnutool-delete]# man 7 man > file2.txt
[root@crushlinux gnutool-delete]# mkdir folder; cd folder; man 7 man >file1.txt
[root@crushlinux folder]# cd ../
獲取文件校驗碼
[root@crushlinux gnutool-delete]# md5sum file*
06da9233bf8c0836e4d45e28dfb2b511 file1.txt
06da9233bf8c0836e4d45e28dfb2b511 file2.txt
[root@crushlinux gnutool-delete]# md5sum folder/file1.txt
06da9233bf8c0836e4d45e28dfb2b511 folder/file1.txt
[root@crushlinux gnutool-delete]# cd ../
刪除測試文件或目錄
[root@crushlinux backupdata]# rm -rf gnutool-delete/.net
將設備卸載或者改爲只讀,防止數據被覆蓋使用
[root@crushlinux backupdata]# cd ../
[root@crushlinux /]# umount /backupdata/ 或者
[root@crushlinux ~]# mount -o remount,ro /dev/sdb1
查詢恢復數據信息,注意這裏的--inode 2 這裏會掃描分區 :
[root@crushlinux /]# extundelete /dev/sdb1 --inode 2
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 26 groups loaded.
Group: 0
Contents of inode 2:
0000 | ed 41 00 00 00 04 00 00 37 79 29 53 3a 79 29 53 | .A......7y)S:y)S
0010 | 3a 79 29 53 00 00 00 00 00 00 03 00 02 00 00 00 | :y)S............
0020 | 00 00 00 00 02 00 00 00 d3 10 00 00 00 00 00 00 | ................
0030 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0040 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0050 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0060 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0070 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................rest
Inode is Allocated
File mode: 16877
Low 16 bits of Owner Uid: 0
Size in bytes: 1024
Access time: 1395226935
Creation time: 1395226938
Modification time: 1395226938
Deletion Time: 0
Low 16 bits of Group Id: 0
Links count: 3
Blocks count: 2
File flags: 0
File version (for NFS): 0
File ACL: 0
Directory ACL: 0
Fragment address: 0
Direct blocks: 4307, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Indirect block: 0
Double indirect block: 0
Triple indirect block: 0ip
File name | Inode number | Deleted status
. 2
.. 2
lost+found 11
gnutool-delete 12 Deleted
Deleted status標記爲 Deleted 是已經刪除的文件或目錄md5
默認恢復到當前所在目錄下的 RECOVERED_FILES 目錄中去。準備一個能夠讀寫的分區,注意不要再丟失數據的分區哦!
[root@crushlinux /]# extundelete /dev/sdb1 --restore-all
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 26 groups loaded.
Loading journal descriptors ... 43 descriptors loaded.
Searching for recoverable inodes in directory / ...
5 recoverable inodes found.
Looking through the directory structure for deleted files ...
0 recoverable inodes still lost.rem
[root@crushlinux /]# cd RECOVERED_FILES/gnutool-delete/
[root@crushlinux gnutool-delete]# ls
file1.txt file2.txt folder
查看校驗碼與以前所得是否徹底一致
[root@crushlinux gnutool-delete]# md5sum file*
06da9233bf8c0836e4d45e28dfb2b511 file1.txt
06da9233bf8c0836e4d45e28dfb2b511 file2.txt
[root@crushlinux gnutool-delete]# md5sum folder/file1.txt
06da9233bf8c0836e4d45e28dfb2b511 folder/file1.txt
一、恢復全部文件
extundelete /dev/sdb1 –restore-all
二、恢復目錄
extundelete /dev/sdb1 —-restore-directory /backupdata/gnutool-delete
三、恢復文件
extundelete /dev/sdb1 —-restore-files /backupdata/gnutool-delete/file1.txt
四、恢復多個文件
建立一個空白文件,內容爲要恢復的文件列表,一個文件一行哦!
vim restore
/backupdata/gnutool-delete/file1.txt
/backupdata/gnutool-delete/file2.txt
/backupdata/gnutool-delete/folder/file1.txt
extundelete /dev/sdb1 —-restore-files 'restore'
五、根據時間恢復
假如刪除的時間大概是2014-05-04 14:30
[root@crushlinux ~]# date -d "may 04 14:30" +%s
1399185000 得出秒數
恢復此時間後刪除的全部文件
/usr/local/bin/extundelete /dev/sdb1 --after 1399185000 --restore-all
六、根據文件的inode恢復
extundelete /dev/sdb1 --restore-inode 77883
七、查看命令幫助
extundelete --help
應用總結:extundelete基於整個磁盤的恢復功能較爲強大,基於目錄和文件的恢復還不夠完善。若是誤刪除了文件,記住對磁盤不要進行任何操做,保留好現場哦!
切記:硬盤有價,數據無價!!
恢復Linux誤刪除文件系列之經過文件打開的PID和文件的句柄來恢復
環境描述:
當前系統中有多個用戶登陸,其中一個用戶對某個文件進行修改,另外一個用戶對文件執行了刪除操做。
例如經過cat命令往文件裏輸入內容
[root@rhel6 ~]# cat >> /tmp/restore
hello
hi
haha
而在另外一個終端刪除這個文件
[root@rhel6 ~]# rm -rf /tmp/restore
解決方法:
經過文件打開的PID和打開文件的句柄來恢復
[root@rhel6 ~]# lsof |grep -i delete |grep restore
cat 23308 root 1w REG 8,5 14 73 /tmp/restore (deleted)
[root@rhel6 ~]# cd /proc/23308/fd
fd/ fdinfo/
[root@rhel6 ~]# cd /proc/23308/fd
[root@rhel6 fd]# ls
0 1 2
[root@rhel6 fd]# cp 1 /tmp/restore
[root@rhel6 fd]# cat /tmp/restore
hello
hi
haha
ok文件恢復了~~
切記:硬盤有價,數據無價!!