恢復Linux下被誤刪除的文件

2018年5月4日10:07:51 發表評論 5,058 ℃

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

分一個區:sda4

查找:extundelete

分一個區: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 #查看磁盤相關信息

[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

復制一些用于測試刪除的文件:

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

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

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

[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


卸載需要恢復文件的分區: 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 #報錯

[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 #檢查安裝環境并生成Makefile

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

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

開始恢復:

方法1:

通過inode結點查看被刪除的文件名字:

[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

通過inode節點來恢復:

[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/ #恢復成功

file.12

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

方法二,通過文件名恢復

恢復某個文件:

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

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

恢復某個目錄,如目錄a下的所有文件:

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

恢復所有的文件

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

使用心得:

空目錄或空文件恢復不成功。

【騰訊云】云服務器、云數據庫、COS、CDN、短信等云產品特惠熱賣中

發表評論

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