1. 程式人生 > >Linux之——利用extundelete恢復誤刪除的資料

Linux之——利用extundelete恢復誤刪除的資料

利用extundelete工具恢復磁碟誤刪除的資料

原理:

簡單介紹下關於inode的知識。在Linux下可以通過“ls -id”命令來檢視某個檔案或者目錄的inode值,例如檢視根目錄的inode值,可以輸入:

[[email protected] Server-100 shell]# ls -id /
2 /
在利用extundelete恢復檔案時並不依賴特定檔案格式,首先extundelete會通過檔案系統的inode資訊(根目錄的inode一般為2)
來獲得當前檔案系統下所有檔案的資訊,包括存在的和已經刪除的檔案,這些資訊包括檔名和inode。
然後利用inode資訊結合日誌去查詢該inode所在的block位置,包括直接塊、間接塊等資訊。
最後利用dd命令將這些資訊備份出來,從而恢復資料檔案。

安裝:

官網下載地址:https://sourceforge.net/projects/extundelete/files/latest/download?source=top3_dlp_t5 
[[email protected] Server-100 src]# yum -y install e2fsprogs-libs e2fsprogs e2fsprogs-devel
[[email protected] Server-100 src]# rpm -q e2fsprogs-libs e2fsprogs e2fsprogs-devel
[[email protected] Server-100 src]# tar jxvf extundelete-0.2.4.tar.bz2
[
[email protected]
Server-100 src]# cd extundelete-0.2.4 [[email protected] Server-100 src]#extundelete-0.2.4]# ./configure && make && make install

安裝完成之後生成一個可執行檔案

使用:

[[email protected] Server-100 src]# extundelete --help

其中,引數(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,通過指定資料塊大小來開啟檔案系統,一般用於檢視已經知道大小的檔案。
在資料刪除之後,首先要解除安裝被刪除資料所在的磁碟或是分割槽,如果是系統根分割槽遭到誤刪除,
就需要進入單使用者模式下,將根分割槽以只讀的方式掛載。
原因:因為檔案刪除之後,僅僅是將檔案的inode節點中的扇區指標清零,實際上檔案還存在磁碟上面
如果磁碟以讀寫方式掛載,這些刪除的資料塊可能會被系統從新分配出去,這些資料塊被覆蓋之後,這些
資料就真的丟失了,所以以只讀的方式掛載,儘可能避免資料被覆蓋。

實驗:

下面的實驗我是將磁碟格式化為ext4檔案系統,當然在ext3檔案系統下面也是同樣的方法進行恢復
首先掛載一個新的分割槽
[[email protected] Server-100 src]# mkfs.ext4 /dev/sdb1
[[email protected] Server-100 src]# pwd
/usr/local/src/
[[email protected] Server-100 src]# mkdir test
[[email protected] Server-100 src]# mount /dev/sdb1 test/
[[email protected] Server-100 src]# cp /etc/passwd test/
[[email protected] Server-100 src]# cp -r shell/ test/
[[email protected] Server-100 src]# mkdir test/yhl
[[email protected] Server-100 src]# echo "Welcome to test" > test/yhl/1.txt
[[email protected] Server-100 src]# cd test/
[[email protected] Server-100 test]# md5sum passwd 
b182c9886c816aa0b4fc77ca6585d42e  passwd
[[email protected] Server-100 test]# md5sum yhl/1.txt 
eb39646285ff90dd31f24bd9f0a34257  yhl/1.txt
[[email protected] Server-100 test]# ls shell/ yhl/
shell/:
6.sh     check_system.sh  hanyi.sh  if2.sh  if4.sh  new.sh.bak  p_s1.sh    root.sh  yanse.sh  yuhulin.sh    yunsuan.sh
case.sh  chengji.sh       if1.sh    if3.sh  new.sh  ppp         python.sh  test     youxi.sh  yunsuan-1.sh

yhl/:
1.txt
[[email protected] Server-100 test]# rm -rf *

恢復:
1,解除安裝刪除檔案的分割槽
[[email protected] Server-100 test]# umount /usr/local/src/test/
umount: /usr/local/src/test: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
提示裝置忙,用下面方法解除安裝就可以解除安裝
[[email protected] Server-100 test]# fuser -m -v -i -k /usr/local/src/test/
[[email protected] Server-100 ~]# umount /usr/local/src/test/

檢視能恢復的資料
[[email protected] Server-100 ~]# extundelete /dev/sdb1 --inode 2  (因為根分割槽的inode值是2)
File name                                       | Inode number | Deleted status
.                                                 2
..                                                2
shell                                             130305         Deleted
passwd                                            12             Deleted
yhl                                               1042433        Deleted

首先測試恢復單個檔案
[[email protected] Server-100 ~]# extundelete /dev/sdb1 --restore-file passwd   //restore-file表示恢復檔案
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 153 groups loaded.
Loading journal descriptors ... 79 descriptors loaded.
Successfully restored file passwd
[[email protected] Server-100 ~]# cd RECOVERED_FILES/                           //恢復成功之後預設會建立這個檔案,恢復的檔案在這個目錄下面
[[email protected] Server-100 RECOVERED_FILES]# ls
passwd
[[email protected] Server-100 RECOVERED_FILES]# md5sum passwd                   //進行MD5校驗,和刪除之前對比是一樣的,說明恢復成功
b182c9886c816aa0b4fc77ca6585d42e  passwd

測試恢復目錄
[[email protected] Server-100 RECOVERED_FILES]# extundelete /dev/sdb1 --restore-directory /shell
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 153 groups loaded.
Loading journal descriptors ... 79 descriptors loaded.
Searching for recoverable inodes in directory /shell ... 
26 recoverable inodes found.
Looking through the directory structure for deleted files ... 
5 recoverable inodes still lost.
[[email protected] Server-100 RECOVERED_FILES]# ls
passwd  RECOVERED_FILES
[[email protected] Server-100 RECOVERED_FILES]# cd RECOVERED_FILES/
[[email protected] Server-100 RECOVERED_FILES]# ls
shell                
可以看見這個目錄,但是有一個問題是恢復回來的檔案許可權和之前的發生了變化,需要你重新修改許可權(我測試的時候是這樣的)

恢復所有資料
[[email protected] Server-100 shell]# extundelete /dev/sdb1 --restore-all
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 153 groups loaded.
Loading journal descriptors ... 79 descriptors loaded.
Searching for recoverable inodes in directory / ... 
26 recoverable inodes found.
Looking through the directory structure for deleted files ... 
1 recoverable inodes still lost.
[[email protected] Server-100 shell]# cd RECOVERED_FILES/
[[email protected] Server-100 RECOVERED_FILES]# ls
passwd  shell  yhl
[[email protected] Server-100 yhl]# ls
1.txt
[[email protected] Server-100 yhl]# cat 1.txt 
Welcome to test
[[email protected] Server-100 yhl]# md5sum 1.txt 
eb39646285ff90dd31f24bd9f0a34257  1.txt
[[email protected] Server-100 shell]# du -sh RECOVERED_FILES/*
4.0K    RECOVERED_FILES/passwd
96K RECOVERED_FILES/shell
8.0K    RECOVERED_FILES/yhl
可以看出,資料恢復成功

相關推薦

Linux——利用extundelete恢復刪除資料

利用extundelete工具恢復磁碟誤刪除的資料原理:簡單介紹下關於inode的知識。在Linux下可以通過“ls -id”命令來檢視某個檔案或者目錄的inode值,例如檢視根目錄的inode值,可以輸入:[[email protected] Server-100

Linux中用extundelete恢復刪除的數據

extundelete 數據恢復 數據丟失 誤刪除 extundelete是一個用來恢復ext3、ext4分區的文件的工具。它會利用分區中的日誌信息嘗試恢復被刪除的文件。但是,並非每個被刪除的文件都能確保被恢復,所以養成良好的備份習慣是非常重要的。extundelete恢復文件的原理在恢復文件

Linux ext4檔案系統下 extundelete 恢復 刪除的檔案

1、檔案基本操作 1.1 檢視檔案 # ls   1.2 建立 1.2.1 建立檔案 # touch {file_name} # vim {file_name}   1.2.2 建立目錄 # mkdir -p {dir}   1.3 複製 1.3.1 複

Linux ext4文件系統下 extundelete 恢復 刪除的文件

磁盤操作 mkfs 4.5 1.5 del 查看 -a 誤刪除 目錄名 1、文件基本操作 1.1 查看文件 # ls   1.2 創建 1.2.1 創建文件 # touch {file_name} # vim {file_name}   1.2.2 創

mysql利用mysqlbinlog命令恢復刪除資料

實驗環境: MYSQL 5.7.22  開啟二進志日誌 日誌格式MIXED 實驗過程: 1、執行:FLUSH LOGS; master-bin.000014 檔案就是新生成的檔案 重新整理日誌是為了實驗內容更直觀,更容易觀察到整個實驗過程的內容。 我看

CentOS7使用Extundelete恢復刪除的文件

centos7使用extundelete今天清理服務器的時候,不小心把一個重要文件給刪除了。於是馬上停止服務器的一切寫入操作,開始著手恢復被誤刪的文件。恢復工具我使用的是Extundelete,恢復過程記錄如下:安裝Extundeleteyum install e2fsprogs-devel首先安裝依賴程序w

Linux系統通過extundelete恢復刪除的數據

eve 數據覆蓋 root lib ear ali 工作 rect 如果 我們都知道windows系統有個回收站,凡是被刪除的文件都可以通過回收站來恢復數據,即便是按住shift鍵永久刪除了,也有很多數據恢復軟件可供使用。那麽Linux下如果數據被刪除了,又該如何恢復呢,L

linux恢復刪除文件-extundelete

linux恢復誤刪除文件-extunde經過本人測試該工具支持ext3和ext4文件系統當發現某個分區的數據被誤刪除後,要做的第一件事是立刻卸載被誤刪除文件所在的分區,或者重新以只讀方式掛載此分區。這麽做的原因其實很簡單:刪除一個文件,就是將文件inode節點中的扇區指針清除,同時,釋放這些數據對應的數據塊,

Linux中用extundelete恢復刪文件

linux extundelete 恢復誤刪文件 一、實驗前需知1、extundelete是一個用來恢復ext3,ext4分區文件的工具,他會利用分區中的日誌信息嘗試恢復被刪除的文件,但是,並非每個被刪除的文件都能確保被恢復,所以,重要的文件大家還是要做好備份。下面進行一個小實驗模擬文件誤刪,使用

Linux中用extundelete恢復刪除的文件

Linuxextundelete 恢復文件 在Linux中,我們會遇到不小心刪除文件的時候,那麽我們就可以用extundelete來恢復這些誤刪的文件。在此實驗裏,我將啟用rh6-2並用xshell來進行遠程連接。第一步:添加一塊硬盤添加硬盤的方法我在前面有講過,在這裏就不截圖了。添加硬盤之後一定要重

linux恢復刪除的數據文件

linux 數據還原在linux系統運維中,經常會遇到各種因操作不慎、操作失誤等行為導致數據丟失的情況,此時我們可以利用extundelete進行數據的恢復。一、 實驗前的準備 新建一個磁盤 在虛擬機設置窗口中,找到“硬盤”,點擊“添加”,在打開的“添加硬件向導”窗口中,選中“硬盤”,點擊下一步,接下

Linux恢復刪除文件

恢復誤刪除文件 Linux恢復誤刪除文件 環境要求:在虛擬機裏新建一個文件系統,在文件系統裏創建數個文件,模擬文件誤刪除在恢復實驗。 編譯安裝extundelete軟件包先使用yum倉庫安裝依賴包e2fsprogs-libs、e2fsprogs-devel(yum倉庫制作詳見前文,這裏不再贅訴)掛載Wind

利用plsql工具恢復刪表和恢復資料

一、恢復誤刪表     1.執行以下sql語句,找到被自己誤刪的資料表對應的object_name;         select * from user_recyclebin t;--檢視被刪掉

SQL Server 2008 資料庫刪除資料恢復

關鍵字:SQL Server 2008, recover deleted records 背景:誤刪除資料。 SQL Server中誤刪除資料的恢復本來不是件難事,從事務日誌恢復即可。但是,這個恢復需要有兩個前提條件: 1. 至少有一個誤刪除之前的資料庫完全備份。 2. 資料庫的恢

硬碟資料恢復——刪除資料恢復

軟體準備–DiskGenius DiskGenius 是一款專業級的資料恢復軟體(Hard Drive Recovery Software),演算法精湛、功能強大!支援多種情況下的檔案丟失、

oracle刪除資料恢復方法

學習資料庫時,我們只是以學習的態度,考慮如何使用資料庫命令語句,並未想過工作中,如果誤操作一下,都可能導致無可挽回的損失。當我在工作中真正遇到這些問題時,我開始尋找答案。 今天主要以oracle資料庫為例,介紹關於表中資料刪除的解決辦法。(不考慮全庫備份和利用歸檔日誌

SQL Server 2008 刪除資料恢復

    前言     在平時大家用到SQL Server的時候很多,也經常會對其進行各種操作,簡單的資料查詢或新增還沒什麼問題,頂多就是新增錯誤直接刪除就可以了,但如果你操作的是重要的資料庫,而且庫

mysql刪除資料恢復處理

1.事故 後臺操作許可權較高人員執行錯誤的刪除語句:mysql> delete from order where order_id=1; 2.事故影響 使用者看不到這個定單,且這個定單是活躍的定單 3.是故時間 4.恢復處理流程 保留現場。 mysql> del

D_db2重定向恢復+日誌前滾,恢復刪除資料

UPDATE COMMAND OPTIONS USING S ON Z ON HIS_NODE0000.out V ON; SET CLIENT ATTACH_DBPARTITIONNUM  0; SET CLIENT CONNECT_DBPARTITIONNUM 0; RESTORE DATABASE my

oracle資料閃回功能(恢復刪除的表資訊)

1  ORACLE用PL/SQL提交資料後執行回滾的方法  1、如果資料庫表,不支援閃回功能   alter table A enable row movement;  2、查詢刪除資料的時間點的資料(也就是閃回至該時間點之前的資料)    select * from A