恢復(fù)Linux下被誤刪除的文件

2018年5月4日10:07:51 發(fā)表評(píng)論 4,987 ℃

[root@xuegod63 ~]# mount /dev/cdrom /mnt/

分一個(gè)區(qū):sda4

查找:extundelete

分一個(gè)區(qū):sda4

[root@localhost ~]# mkdir /tmp/sda4

[root@localhost ~]# mkfs.ext4 /dev/sda4 格式化

[root@amd5 Desktop]# echo $?

0

[root@localhost ~]# mount /dev/sda4 /tmp/sda4/

[root@localhost ~]# df -Th #查看磁盤相關(guān)信息

[root@amd5 Desktop]# mount /dev/sda4 /tmp/sda4

[root@amd5 Desktop]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda2 9.7G 3.8G 5.5G 41% /

tmpfs 569M 264K 569M 1% /dev/shm

/dev/sda1 194M 28M 157M 15% /boot

/dev/sr0 3.4G 3.4G 0 100% /mnt

/dev/sda4 1012M 34M 928M 4% /tmp/sda4

復(fù)制一些用于測(cè)試刪除的文件:

[root@localhost ~]# cp /etc/passwd /tmp/sda4/

[root@localhost ~]# cp /etc/hosts /tmp/sda4/

[root@localhost ~]# vim /tmp/sda4/a.txt #vim編輯a.txt 隨便寫入一些數(shù)據(jù)。

[root@localhost ~]# mkdir -p /tmp/sda4/a/b/c

[root@localhost ~]# cp /tmp/sda4/a.txt /tmp/sda4/a

[root@localhost ~]# cp /tmp/sda4/a.txt /tmp/sda4/a/b/

刪除:

[root@amd5  ~]# mkdir /tmp/back

[root@amd5 ~]# cp -r /tmp/sda4/* /tmp/back

[root@amd5 ~]# cd /tmp/sda4/

[root@localhost ~]# rm -rf passwd hosts a a.txt

[root@localhost ~]# ls /tmp/sda4/

lost+found


卸載需要恢復(fù)文件的分區(qū): inode

[root@amd5 sda4]# cd

[root@amd5 ~]# umount /tmp/sda4/

安裝軟件 extundelete

[root@amd5 ~]# tar jxvf extundelete-0.2.4.tar.bz2

[root@amd5 ~]# cd extundelete-0.2.4

[root@amd5 extundelete-0.2.4]# ./configure

Configuring extundelete 0.2.4

configure: error: Can't find ext2fs library #報(bào)錯(cuò)

[root@amd5 ~]# mount /dev/cdrom /mnt/

[root@amd5 extundelete-0.2.4]# rpm -ivh /mnt/Packages/e2fsprogs-devel-1.41.12-11.el6.x86_64.rpm

[root@amd5 extundelete-0.2.4]#

[root@amd5 extundelete-0.2.4]# ./configure #檢查安裝環(huán)境并生成Makefile

[root@amd5  extundelete-0.2.4]# make #編譯

[root@amd5 extundelete-0.2.4]# make install #安裝

開始恢復(fù):

方法1:

通過(guò)inode結(jié)點(diǎn)查看被刪除的文件名字:

[root@xuegod63 ~]# mkdir test

[root@xuegod63 ~]# cd test/

[root@localhost ~]# extundelete /dev/sda4 --inode 2

。。。

lost+found                11

passwd                      12                  Deleted

hosts                         13                  Deleted

a                               8193              Deleted

a.txt                          15                 Deleted

通過(guò)inode節(jié)點(diǎn)來(lái)恢復(fù):

[root@localhost ~]# extundelete /dev/sda4 --restore-inode 12

NOTICE: Extended attributes are not restored.

Loading filesystem metadata ... 16 groups loaded.

Loading journal descriptors ... 32 descriptors loaded.

[root@localhost ~]# ls RECOVERED_FILES/ #恢復(fù)成功

file.12

[root@amd5  test]# diff /etc/passwd /root/test/RECOVERED_FILES/file.12

方法二,通過(guò)文件名恢復(fù)

恢復(fù)某個(gè)文件:

[root@amd5 test]# rm -rf RECOVERED_FILES/

[root@localhost ~]# extundelete /dev/sda4 --restore-file passwd

恢復(fù)某個(gè)目錄,如目錄a下的所有文件:

[root@localhost ~]# extundelete /dev/sda4 --restore-directory a #恢復(fù)目錄a 

恢復(fù)所有的文件

[root@localhost ~]# extundelete /dev/sda4 --restore-all

使用心得:

空目錄或空文件恢復(fù)不成功。

【騰訊云】云服務(wù)器、云數(shù)據(jù)庫(kù)、COS、CDN、短信等云產(chǎn)品特惠熱賣中

發(fā)表評(píng)論

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: