恢復linux ext4分區上誤刪除的文件。


我是使用  Xmanager Enterprise 4 來連接CentOS Linux 6.4 的。

可惡的XManager有一個惡心的bug,時不時的出現 焦點問題:

2012年10月15日 星期一,14:44:01
==============================================
溫馨提示: Xmanager有個毛病

就是 時不時的出現 窗口之間焦點的切換必須點擊菜單欄上面的 title 才可以,而且不能用alt拖動窗口了.有時又可以..

解決方法:打開后,按住 win+D  再win+D

焦點的切換就會發生變化了...可以點擊內容 切換
而且,也可以使用alt 移動窗口了....



2013年5月25日 今天,14:09:40
==============================================
鍵盤上 按p鍵 也會失效。
需要win+D 多次 才會解決這個問題

不知道有人遇到過這個問題沒,使用 XMing 來連接xdmcp 倒是沒問題,而且xmanager無法hook快捷鍵,用起來 快捷鍵使用起來不方便,這個就不說了,但是上面的 我確認 是一個 BUG。很惡心。

這次 我要刪除一個桌面的文件,點擊后,shift+del 回車,快速刪除,一看文件,沒刪除,難道。。。看看另一個nautilus 窗口,正在瀏覽自己的ftp服務,缺少了一個文件夾,我勒個去啊。。。。。。。。。。

 

如果是ntfs分區,windows下的,我可以diskgenius + winhex 速度恢復文件。但是ext4分區下,我真沒干過這種事情啊。

搜索一下,

http://my.oschina.net/Qunero/blog/8607


今天一時手快 rm -rf .* ,刪除了一個重要郵件目錄,幸好通過extundelete恢復了。
記下操作流程:
1.准備工作
主要通過 extundelete 0.2.0完成恢復

https://sourceforge.net/projects/extundelete/files/latest/download


需要依賴兩個包

sudo aptitude install e2fsprogs e2fslibs-dev

下載頁面http://extundelete.sourceforge.net/

快速下載: download extundelete

編譯三部曲

./configure
make
sudo make install

2.如果分區已經掛載,先umount,並且在將要恢復的地方查看空間大小

df -h ./

如果你要恢復的是根目錄或者系統目錄就只有拿硬盤掛到另外一台電腦上操作了。

3.恢復制定分區下所有刪除文件,默認恢復到執行命令的目錄下,文件夾名字為RECOVERED_FILES,使用詳情請參考:extundelete --help 運行的結果

sudo extundelete /dev/sda8 --restore-all


---------------------------------------------

$ 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 ./RESTORED_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 '/' (it

                         must be one of the paths returned by --dump-names).

                         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-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. 

按照這個文章的提示,下載extundelete-0.2.4.tar.bz2 同時需要 yum install e2fsprogs e2fsprogs-devel e2fsprogs-libs ,其他系統下命名略有不同。我是 yum search e2fs找到的,在epel 倉庫下的:wget http://mirrors.yun-idc.com/epel/6/x86_64/epel-release-6-8.noarch.rpm 。

 

 

搞定。恢復的文件在 當前目錄下的  RECOVERED_FILES 文件夾內。

 

再送一篇文章,我反正沒成功,因為是在vsftpd下刪除的文件,可能和 rm -rf 刪除機制不太一樣??

系統管理:恢復誤刪除的Linux文件全攻略2008-08-01 20:18
作為一個多用戶、多任務的操作系統,Linux下的文件一旦被刪除,是難以恢復的。盡管刪除命令只是在文件節點中作刪除標記,並不真正清除文件內容,但是其他用戶和一些有寫盤動作的進程會很快覆蓋這些數據。不過,對於家庭單機使用的Linux,或者誤刪文件后及時補救,還是可以恢復的。


1、Ext2文件系統結構的簡單介紹


在Linux所用的Ext2文件系統中,文件是以塊為單位存儲的,默認情況下每個塊的大小是1K,不同的塊以塊號區分。每個文件還有一個節點,節點中包含有文件所有者,讀寫權限,文件類型等信息。對於一個小於12個塊的文件,在節點中直接存儲文件數據塊的塊號。如果文件大於12個塊,那么節點在12個塊號之后存儲一個間接塊的塊號,在這個間接塊號所對應的塊中,存儲有256個文件數據塊的塊號(Ext2fs中每個塊號占用4字節,這樣一個塊中所能存儲的塊號就是1024/4=256)。如果有更大的文件,那么還會在節點中出現二級間接塊和三級間接塊。


2、恢復被誤刪文件的方法


大多數Linux發行版都提供一個debugfs工具,可以用來對Ext2文件系統進行編輯操作。不過在使用這個工具之前,還有一些工作要做。


首先以只讀方式重新掛載被誤刪的文件所在分區。使用如下命令:(假設文件在/usr分區)


mount –r –n –o remount /usr -r表示只讀方式掛載;-n表示不寫入/etc/mtab,如果是恢復/etc上的文件,就加上這個參數。如果系統說xxx partion busy,可以用fuser命令查看一下是哪些進程使用這個分區上的文件:


fuser –v –m /usr


如果沒有什么重要的進程,用以下命令停掉它們:


fuser -k –v –m /usr


然后就可以重新掛載這些文件系統了。


如果是把所有的文件統一安裝在一個大的/分區當中,可以在boot提示符下用linux single進入單用戶模式,盡量減少系統進程向硬盤寫入數據的機會,要不干脆把硬盤掛在別的機器上。另外,恢復出來的數據不要寫到/上面,避免破壞那些有用的數據。如果機器上有dos/windows,可以寫到這些分區上面:


mount –r –n /dev/hda1 /mnt/had

然后就可以執行debugfs:(假設Linux在 /dev/hda5)

#debugfs /dev/hda5

就會出現debugfs提示符debugfs:

使用lsdel命令可以列出很多被刪除的文件的信息:

debugfs:lsdel

debugfs: 2692 deleted inodes found.

Inode Owner Mode Size Blocks Time deleted

164821 0 100600 8192 1/ 1 Sun May 13 19:22:46 2001

…………………………………………………………

36137 0 100644 4 1/ 1 Tue Apr 24 10:11:15 2001

196829 0 100644 149500 38/ 38 Mon May 27 13:52:04 2001

debugfs:


列出的文件有很多(這里找到2692個),第一字段是文件節點號,第二字段是文件所有者,第三字段是讀寫權限,接下來是文件大小,占用塊數,刪除時間。


然后就可以根據文件大小和刪除日期判斷那些是我們需要的。比如我們要恢復節點是196829的文件:


可以先看看文件數據狀態:


debugfs:stat <196829>

Inode: 196829 Type: regular Mode: 0644 Flags: 0x0 Version: 1

User: 0 Group: 0 Size: 149500

File ACL: 0 Directory ACL: 0

Links: 0 Blockcount: 38

Fragment: Address: 0 Number: 0 Size: 0

ctime: 0x31a9a574 -- Mon May 27 13:52:04 2001

atime: 0x31a21dd1 -- Tue May 21 20:47:29 2001

mtime: 0x313bf4d7 -- Tue Mar 5 08:01:27 2001

dtime: 0x31a9a574 -- Mon May 27 13:52:04 2001

BLOCKS:

594810 594811 594814 594815 594816 594817 ………………………………….

TOTAL: 38

然后就可以用dump指令恢復文件:


debugfs:dump <196829> /mnt/hda/01.sav

這樣就把文件恢復出來了。退出debugfs:

debugfs:quit

另一種方法是手工編輯inode:

debugfs:mi <196829>

Mode [0100644]

User ID [0]

Group ID [0]

Size [149500]

Creation time [0x31a9a574]

Modification time [0x31a9a574]

Access time [0x31a21dd1]

Deletion time [0x31a9a574] 0

Link count [0] 1

Block count [38]

File flags [0x0]

Reserved1 [0]

File acl [0]

Directory acl [0]

Fragment address [0]

Fragment number [0]

Fragment size [0]

Direct Block #0 [594810]

…………………………….

Triple Indirect Block [0]


使用mi指令后每次顯示一行信息以供編輯,其它行可以直接按回車表示確認,把deletion time改成0(未刪除),Link count改成1。改好后退出debugfs:


debugfs:quit


然后用fsck檢查/dev/hda5


fsck /dev/hda5


程序會說找到丟失的數據塊,放在lost+found里面。這個目錄里的文件就是我們要的東東。
 
 
View Code

 


免責聲明!

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



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