Linux下利用ext3grep恢復(fù)被刪除的文件
Linux系統(tǒng)下,如何恢復(fù)被刪除的文件?看看文章作者是怎樣解決的吧!
10個(gè)G的數(shù)據(jù)被誤刪除了,差點(diǎn)崩潰,試遍了所有常規(guī)恢復(fù)軟件,無用,就要放棄的時(shí)候,發(fā)現(xiàn)了ext3grep這個(gè)開源東東!
順利恢復(fù)所有數(shù)據(jù),所以linux下數(shù)據(jù)刪除并不可怕,可怕的是刪除后沒有恢復(fù)的方法,看看下面的操作吧!
- [root@localhost ~]# uname -a
- Linux localhost.localdomain 2.6.18-8.el5 #1 SMP Fri Jan 26 14:15:21 EST 2007 i686 i686 i386 GNU/Linux
其實(shí)什么版本的系統(tǒng)無所謂 !
所需的相關(guān)庫
- [root@localhost ~]# rpm -qa |grep e2fsprogs
- e2fsprogs-libs-1.39-8.el5
- e2fsprogs-1.39-8.el5
- e2fsprogs-devel-1.39-8.el5
必須要有e2fsprogs-libs,不然在后面ext3grep的安裝會有問題。
分區(qū)情況:
- [root@localhost ~]# df -h
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/VolGroup00-LogVol00
- 6.2G 1.8G 4.2G 30% /
- /dev/sda1 99M 11M 83M 12% /boot
- /dev/mapper/VolGroup00-LogVol02
- 1008M 34M 924M 4% /data
- tmpfs 125M 0 125M 0% /dev/shm
需要軟件
http://code.google.com/p/ext3grep/downloads/list
先下載軟件
- [root@localhost ~]# cd /root/src/
- [root@localhost src]# wget http://ext3grep.googlecode.com/files/ext3grep-0.6.0.tar.gz src
- [root@localhost src]# ls
- ext3grep-0.6.0.tar.gz
- [root@localhost src]# tar xfvz ext3grep-0.6.0.tar.gz
- [root@localhost ext3grep-0.6.0]# ./configure
- [root@localhost ext3grep-0.6.0]# make install
- [root@localhost ext3grep-0.6.0]# ext3grep
- Running ext3grep version 0.6.0
編譯然后測試可以使用了,一切做好了以后開始我們的恢復(fù)過程。
我的目錄是/data分區(qū),我先格式化了分區(qū),我放一個(gè)文件在根目錄下和一個(gè)子目錄下的文件。
/dev/mapper/VolGroup00-LogVol02 1008M 34M 924M 4% /data
下面斜體部分不是必須的:
其實(shí)這里用什么分區(qū)倒是無所謂,也可以模擬一個(gè)出來,下面是模擬步驟:
- mkdir /data1/
- cd /data1/
- dd if=/dev/zero of=disk1 count=2048000
- mkfs.ext3 disk1
- mkdir -p /dfs/a
- mount -o loop /data1/disk1 /dfs/a
這里,我們用/data分區(qū),先拷貝些文件過去
- [root@localhost ~]# ]# cp /bin/ls /data/
- [root@localhost ~]# ]# cp -rf /bin /data/
- [root@localhost ~]# ]# ls -la /data/
- total 136
- drwxr-xr-x 4 root root 4096 Apr 21 17:37 .
- drwxr-xr-x 25 root root 4096 Apr 21 17:11 ..
- drwxr-xr-x 2 root root 4096 Apr 21 17:37 bin
- drwx—— 2 root root 16384 Apr 21 17:15 lost+found
- -rwxr-xr-x 1 root root 93560 Apr 21 17:37 ls
- [root@localhost ~]#
一個(gè)子目錄一個(gè)可執(zhí)行文件
現(xiàn)在刪除ls文件和bin下面的zcat
- [root@localhost ~]# rm /data/ls
- rm: remove regular file `/data/ls’? y
- [root@localhost ~]# rm /data/bin/zcat
- rm: remove regular file `/data/bin/zcat’? y
- [root@localhost ~]# ls -la /data/ls /data/bin/zcat
- ls: /data/ls: No such file or directory
- ls: /data/bin/zcat: No such file or directory
#p#
文件沒有了然后我們來恢復(fù):
首先必須umount掉誤刪除數(shù)據(jù)的分區(qū):
- [root@localhost ~]# umount /dev/mapper/VolGroup00-LogVol02
- [root@localhost ~]# df -h
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/VolGroup00-LogVol00
- 6.2G 1.8G 4.2G 30% /
- /dev/sda1 99M 11M 83M 12% /boot
- tmpfs 125M 0 125M 0% /dev/shm
確認(rèn)卸載,然后使用ext3grep來恢復(fù)。
[root@localhost ~]# ext3grep /dev/mapper/VolGroup00-LogVol02 --ls --inode 2
這里會創(chuàng)建掃描分區(qū)
- [root@localhost ~]# ext3grep /dev/mapper/VolGroup00-LogVol02 --ls --inode 2
- [root@localhost ~]# ext3grep /dev/mapper/VolGroup00-LogVol02 --restore-file ls
- Running ext3grep version 0.6.0
- WARNING: I don’t know what EXT3_FEATURE_COMPAT_EXT_ATTR is.
- Number of groups: 8
- Minimum / maximum journal block: 585 / 8787
- Loading journal descriptors… sorting… done
- Number of descriptors in journal: 58; min / max sequence numbers: 2 / 5
- Loading VolGroup00-LogVol02.ext3grep.stage2… done
- Restoring ls
- [root@localhost ~]# ext3grep /dev/mapper/VolGroup00-LogVol02 --restore-file bin/ls
- Running ext3grep version 0.6.0
- WARNING: I don’t know what EXT3_FEATURE_COMPAT_EXT_ATTR is.
- Number of groups: 8
- Minimum / maximum journal block: 585 / 8787
- Loading journal descriptors… sorting… done
- Number of descriptors in journal: 58; min / max sequence numbers: 2 / 5
- Loading VolGroup00-LogVol02.ext3grep.stage2… done
- Restoring bin/ls
- [root@localhost ~]# ls -la RESTORED_FILES/
- total 124
- drwxr-xr-x 3 root root 4096 Apr 21 18:01 .
- drwxr-x— 5 root root 4096 Apr 21 17:55 ..
- -rwxr-xr-x 1 root root 93560 Apr 21 17:48 ls
- [root@localhost ~]# ext3grep /dev/mapper/VolGroup00-LogVol02 --restore-file bin/zcat
- Running ext3grep version 0.6.0
- WARNING: I don’t know what EXT3_FEATURE_COMPAT_EXT_ATTR is.
- Number of groups: 8
- Minimum / maximum journal block: 585 / 8787
- Loading journal descriptors… sorting… done
- Number of descriptors in journal: 58; min / max sequence numbers: 2 / 5
- Loading VolGroup00-LogVol02.ext3grep.stage2… done
- Restoring bin/zcat
- [root@localhost ~]# ls -la RESTORED_FILES/bin/
- total 188
- drwxr-xr-x 2 root root 4096 Apr 21 18:01 .
- drwxr-xr-x 3 root root 4096 Apr 21 18:01 ..
- -rwxr-xr-x 1 root root 62136 Apr 21 17:48 zcat
看看都恢復(fù)在RESTORED_FILES目錄下,大小也一樣,這里RESTORED_FILES目錄是執(zhí)行ext3grep的當(dāng)前目錄下!
也可以使用:
ext3grep /termite/cc-disk --restore-all
恢復(fù)所有文件和目錄,但是目錄的話,如果刪除時(shí)間較長,不一定能完全恢復(fù),壓縮文件一般都能恢復(fù)。
如果想詳細(xì)的了解ext3grep,可以到它的的HOW TO頁去看看:
http://www.xs4all.nl/~carlo17/howto/undelete_ext3.html
1、刪除/root/shell/hehe下的a文件
2、安裝ext3grep-0.10.1.tar.gz ext3grep命令已經(jīng)可以正常使用
3、ext3grep /dev/sda3 --ls --inode 2 創(chuàng)建掃描分區(qū)
4、ext3grep /dev/sda3 --restore-file root/shell/hehe/a 恢復(fù)文件a
5、ext3grep /dev/sda3 --restore-inode 75631 根基inode
【編輯推薦】
- 匯總:Linux下svn命令大全
- Linux 發(fā)行版將引入 /run 目錄
- Linux上的MRTG流量監(jiān)控中心介紹
- Linux下用mrtg監(jiān)控網(wǎng)絡(luò)設(shè)備端口流量
- Nagios監(jiān)控Linux和Unix服務(wù)器-安裝步驟