Linux文件恢復利器 ext3grep與extundelete


 

介紹兩款Linux文件恢復工具,ext3grepextundelete,可能在關鍵時刻會有所幫助。ext3grep僅對ext3文件系統有效,extundeleteext3ext4文件系統都有效

 

一 實驗環境
軟件環境
vmware workstation 9.0.1
ubuntu server 12.10 
ext3grep 0.10.1
extundelete 0.2.4
 
外掛磁盤
這里外掛 2 個磁盤來模擬需要恢復的設備。可以通過兩種方式實現
第一種:在虛擬機上添加 2 塊虛擬磁盤,具體方法略
第二種:通過 dd 命令用文件模擬塊設備
簡單介紹下第二種方式的命令:
cd /home 
dd if=/dev/zero of=sdc1 bs=1M count=100    #塊大小為1M,數量為100,也就是100M 
mkfs.ext3 /home/sdc1                     #ext3文件系統格式化 
mount /home/sdc1 /sdc  

本實例采用第一種方式添加2塊磁盤,添加后一塊ext3格式化,另一塊ext4格式化,然后掛載。具體操作過程省略

 

mount 查看下 
/dev/sdb1 on /sdb type ext4 (rw) 
/dev/sdc1 on /sdc type ext3 (rw) 

 

配置安裝源列表
ubuntu 配置好安裝源列表后,安裝軟件非常方便,以下是經過測試有效的安裝源列表:
root@ubuntu-test:/home# cat /etc/apt/sources.list 
deb http://ubuntu.cn99.com/ubuntu/ quantal main restricted universe multiverse 
deb http://ubuntu.cn99.com/ubuntu/ quantal-updates main restricted universe multiverse 
deb http://ubuntu.cn99.com/ubuntu/ quantal-security main restricted universe multiverse 
deb http://ubuntu.cn99.com/ubuntu/ quantal-backports main restricted universe multiverse 
deb http://ubuntu.cn99.com/ubuntu-cn/ quantal main restricted universe multiverse 

 

二、 ext3grep 恢復工具
安裝 ext3grep
ubuntu 服務器上可以使用以下命令直接安裝 ext3grep ,使用這種方式可以直接安裝相關的依賴關系包,真是太省心了。
aptitude install ext3grep 
或者直接去官網下載源碼包安裝
官網下載地址:https://code.google.com/archive/p/ext3grep/downloads
編譯安裝需要先安裝依賴
apt-get install e2fslibs-dev # Centos上用yum install e2fsprogs-devel

如果不安裝依賴會報錯:

checking for compiler with PCH support... yes
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... no
Package ext2fs was not found in the pkg-config search path.
Perhaps you should add the directory containing `ext2fs.pc'
to the PKG_CONFIG_PATH environment variable
No package 'ext2fs' found
checking ext2fs/ext2_fs.h usability... no
checking ext2fs/ext2_fs.h presence... no
checking for ext2fs/ext2_fs.h... no
checking ext2fs/ext2fs.h usability... no
checking ext2fs/ext2fs.h presence... no
checking for ext2fs/ext2fs.h... no
configure: error: Missing headers. Please install the package e2fslibs-dev from e2fsprogs, or http://e2fsprogs.sourceforge.net for the upstream tar-ball.

然后編譯安裝軟件

tar xvf ext3grep-0.10.1.tar.gz 
cd ext3grep-0.10.1
./configuremake && make install
 
安裝完后,可以用以下命令驗證下:

2 ext3grep 查找被刪除的文件
ext3grep --ls --inode 2 /dev/sdc1 

注意:這里只能看到 /dev/sdc1  根目錄下的文件與文件夾,不能顯示目錄下文件
顯示目錄 vmware-tools-distrib 下的文件,列表這個目錄節點號
ext3grep --ls --inode 8193 /dev/sdc1 

以上紅線條標注的表示已經被刪除掉的文件或目錄
如果想要顯示出所有被刪除文件的名字,用以下命令:
ext3grep --ls --dump-names /dev/sdc1 > filename.txt      #將顯示結果放在一個文件中 

 

恢復單個文件
恢復某個指定的文件,命令如下:
ext3grep --restore-file VMwareTools-9.2.2-893683.tar.gz /dev/sdc1 

然后在當前目錄 RESTORED_FILES 目錄下找到被恢復的文件

如果是恢復目錄下面的指定文件要加上相對路徑
ext3grep --restore-file vmware-tools-distrib/INSTALL.log /dev/sdc1 
 
恢復整個設備上的文件
ext3grep --restore-all /dev/sdc1  

 

恢復指定時間點之前或之后的所有文件
ext3grep --restore-all --after 1365661200 /dev/sdc1 #恢復Apr 11 14:20 2013之后被刪文件 
ext3grep --restore-all --before 1365661200 /dev/sdc1   #恢復Apr 11 14:20 2013之前被刪文件 

 

RHEL Ubuntu 上測試,發現 after before 這兩個參數好像沒起作用,具體啥原因沒暫時還沒有找到。
 
三、 extundelete 恢復工具
1 extundelete 軟件安裝
下載軟件
wget http://nchc.dl.sourceforge.net/project/extundelete/extundelete/0.2.4/extundelete-0.2.4.tar.bz2 
安裝 e2fsprogs e2fslibs
sudo apt-get install e2fsprogs 
安裝 e2fslibs-dev
sudo apt-get install e2fslibs-dev 
安裝 C++
sudo apt-get install build-essential 
安裝 extundelete
tar -jxvf extundelete-0.2.4.tar.bz2 
cd extundelete-0.2.4 
./configure --prefix=/usr/local/extundelete 
make && make install 
驗證是否安裝成功
cd /usr/local/extundelete/bin 
./extundelete -v 

查看被刪除文件

標記為”Deleted”的文件則是被刪除的文件
 
恢復指定的文件
./extundelete --restore-file aaa /dev/sdb1  

 
完全恢復設備上文件
./extundelete --restore-all /dev/sdb1 
 
恢復指定的時間點后被刪文件
指定一個時間點
date -d "Apr 11 14:30 2013" +%s 
1365661800 
恢復這個時間點后的文件
./extundelete --restore-all --after “1365661800” /dev/sdb1 

如果要恢之前的就用 before 參數。 extundelete 命令與 after 結合使用,在進行恢復時非常有用,可以過濾掉那太舊的文件,減小恢復壓力。
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM