歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> extundelete:Linux下基於開源的數據恢復工具

extundelete:Linux下基於開源的數據恢復工具

日期:2017/2/28 13:54:54   编辑:Linux教程

在Linux下,基於開源的數據恢復工具有很多,常見的有debugfs、R-Linux、ext3grep、extundelete等,比較常用的有ext3grep和extundelete,這兩個工具的恢復原理基本一樣,只是extundelete功能更加強大,本文重點介紹

**************************************************
* lsof 方式恢復 *
**************************************************
lsof
文件剛剛被刪除,想要恢復,先嘗試lsof.
#lsof |grep data.file1
# cp /proc/xxx/xxx/xx /dir/data.file1

或者ps -ef

**************************************************
* extundelete 方式恢復 *
**************************************************

第一時間要做的就是卸載被刪除數據所在的分區,如果是根分區的數據遭到誤刪


yum install gcc gcc++
yum install gcc gcc-c++ gcc-g77

yum install e2fsprogs e2fsprogs-libs e2fsprogs-devel
[root@dg extundelete-0.2.4]# ./configure
Configuring extundelete 0.2.4
Writing generated files to disk

tar xjf extundelete-0.2.4.tar.bz2
cd extundelete-0.2.4
./configure
make && make install

[root@dg extundelete-0.2.4]# make
make -s all-recursive
Making all in src
extundelete.cc:571: 警告:未使用的參數‘flags’
[root@dg extundelete-0.2.4]# make install
Making install in src
/usr/bin/install -c extundelete '/usr/local/bin'

---查看幫助
root@dg extundelete-0.2.4]# make install
Making install in src
/usr/bin/install -c extundelete '/usr/local/bin'
[root@dg 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 the
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.

中參數(options)有:
--version, -[vV],顯示軟件版本號。
--help,顯示軟件幫助信息。
--superblock,顯示超級塊信息。
--journal,顯示日志信息。
--after dtime,時間參數,表示在某段時間之後被刪的文件或目錄。
--before dtime,時間參數,表示在某段時間之前被刪的文件或目錄。

動作(action)有:
--inode ino,顯示節點“ino”的信息。
--block blk,顯示數據塊“blk”的信息。
--restore-inode ino[,ino,...],恢復命令參數,表示恢復節點“ino”的文件,恢復的文件會自動放在當前目錄下的RESTORED_FILES文件夾中,使用節點編號作為擴展名。
--restore-file 'path',恢復命令參數,表示將恢復指定路徑的文件,並把恢復的文件放在當前目錄下的RECOVERED_FILES目錄中。
--restore-files 'path',恢復命令參數,表示將恢復在路徑中已列出的所有文件。
--restore-all,恢復命令參數,表示將嘗試恢復所有目錄和文件。
-j journal,表示從已經命名的文件中讀取擴展日志。
-b blocknumber,表示使用之前備份的超級塊來打開文件系統,一般用於查看現有超級塊是不是當前所要的文件。
-B blocksize,表示使用數據塊大小來打開文件系統,一般用於查看已經知道大小的文件。

1>fuser -k /dev/part && umount /dev/被刪除數據的盤 --殺掉訪問磁盤的進程,umount 被刪除數據的盤
2>extundelete --inode 2 /dev/被刪除數據的盤
3>extundelete --restore-inode 13 /dev/被刪除數據的盤
4>恢復到 RECOVERD_FILES/


在數據被誤刪除後,第一時間要做的就是卸載被刪除數據所在的分區,如果是根分區的數據遭到誤刪,
就需要將系統進入單用戶模式,並且將根分區以只讀模式掛載。這樣做的原因很簡單,因為將文件刪除後,
僅僅是將文件的inode節點中的扇區指針清零,實際文件還儲存在磁盤上,如果磁盤繼續以讀寫模式掛載,
這些已刪除的文件的數據塊就可能被操作系統重新分配出去,在這些數據庫被新的數據覆蓋後,這些數據就真的丟失了,
恢復工具也無力回天。所以!以只讀模式掛載磁盤可以盡量降低數據庫中數據被覆蓋的風險,以提高恢復數據成功的比例。

刪除1.txt

方法1:通過inode恢復
查看刪除文件在哪個分區上
root@dg extundelete-0.2.4]# df -h
文件系統 容量 已用 可用 已用%% 掛載點
/dev/sda2 44G 3.0G 39G 8% /
tmpfs 1004M 76K 1004M 1% /dev/shm
/dev/sda1 194M 51M 134M 28% /boot
# extundelete /dev/sda4 --inode 2
mkdir test

extundelete /dev/sda4 --restore-inode 8001 文件號

對比文件
diff /etc/passwd recover_file/file12
如果沒有任何輸出結果,說明兩個文件完全一樣

方法2:通過文件名稱進行恢復
extundelete /dev/sdb1 --restore-file passwd
會在當前目錄下生成一個RECOVERED_FILES目錄,裡面保存已經恢復的文件

方法3:通過目錄名稱進行恢復
extundelete /dev/sdb1 --restore-directory /mongodb

方法4:恢復所有誤刪文件:
extundelete /dev/sdb1 --restore-all
extundelete還可以實現恢復某個時間段的數據。可以通過“--after”和“--before”參

不能恢復空文件和空目錄

方法4:
extundelete /dev/sda4 --restore-all a

extundelete 不能恢復空文件和空目錄

*********************************************************************************
使用debugfs
用debugfs查找被刪文件的inode,再想法恢復。
[root@hs12 ~]# debugfs /dev/sdb1
debugfs 1.41.12 (17-May-2010)

debugfs:
debugfs: lsdel
Inode Owner Mode Size Blocks Time deleted
0 deleted inodes found.

Copyright © Linux教程網 All Rights Reserved