第一種情況:當前系統有多個用戶,其中一個用戶對文件進行修改,另一個用戶對文件進行刪除操作,那么,這時候該然后進行操作?
操作演示
[root@datanode3 fd]# cat >>/tmp/isues
123qeqweqw
dfsadfasdfasdf
sfdasfdasfdasfdr
在另一個終端刪除這個文件
[root@datanode3 tmp]# rm -rf isues
解決方法:
通過文件打開的PID和打開文件的句柄來恢復
[root@datanode3 tmp]# lsof |grep -i delete
cat 2729 root 1w REG 8,1 220 6867845 /tmp/isues (deleted)
[root@datanode3 tmp]# cd /proc/2729/fd
[root@datanode3 fd]# ls
0 1 2
[root@datanode3 fd]# cp 1 /tmp/isues
這樣就恢復了。
第二種情況:當前的系統只有一個用戶在登錄,對文件進行了誤刪除的操作,那么,這個時候然后恢復呢。
注意事項
-
停止對當前分區做任何操作
-
通過dd命令把當前分區進行備份,防止恢復數據時造成的在度數據丟失。
dd if=/path/filename of=/dev/sdb1
3.通過umount命令把當前的設備分區卸載
umount /dev/sdb1
4 下載第三方的開源軟件工具
wget http://nchc.dl.sourceforge.net/project/extundelete/extundelete/0.2.4/extundelete-0.2.4.tar.bz2
編譯安裝的時候如果報錯
[root@datanode3 extundelete-0.2.4]# ./configure
Configuring extundelete 0.2.4
configure: error: Can't find ext2fs library
需要安裝針對ext2fs 的庫
[root@datanode3 extundelete-0.2.4]# yum list |grep e2fs
e2fsprogs.x86_64 1.39-33.el5 installed
e2fsprogs-libs.i386 1.39-33.el5 installed
e2fsprogs-libs.x86_64 1.39-33.el5 installed
e2fsprogs-devel.i386 1.39-33.el5 Server
e2fsprogs-devel.x86_64 1.39-33.el5 Server
[root@datanode3 extundelete-0.2.4]# yum install e2fsprogs* -y
主要的命令是
-
extundelete --inode 2 /dev/sdb1
-
extundelete --restore-inode inlde /dev/sdb1
-
extundelete --restore-all /deb/sdb1
-
基於文件,目錄,時間 extundelete -help
[root@datanode3 extundelete-0.2.4]# 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 ./RECOVERED_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 '/'
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-directory 'path'
Will restore directory 'path'. 'path' is relative to th e
root directory of the file system. The restored
directory is created in the output directory as 'path'.
--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.
--log 0 Make the program silent.
--log filename Logs all messages to filename.
--log D1=0,D2=filename Custom control of log messages with comma-separated
Examples below: list of options. Dn must be one of info, warn, or
--log info,error error. Omission of the '=name' results in messages
--log warn=0 with the specified level to be logged to the console.
--log error=filename If the parameter is '=0', logging for the specified
level will be turned off. If the parameter is
'=filename', messages with that level will be written
to filename.
-o directory Save the recovered files to the named directory.
The restored files are created in a directory
named 'RECOVERED_FILES/' by default.
記得恢復的目錄在你執行的路徑下面 RECOVERED_FILES目錄。