前言
作為一個多使用者、多任務的作業系統,Linux下的檔案一旦被删除,是難以恢複的。盡管删除指令隻是在檔案節點中作删除标記,并不真正清除檔案内容,但是其他使用者和一些有寫盤動作的程序會很快覆寫這些資料。不過,對于家庭單機使用的Linux,或者誤删檔案後及時補救,還是可以恢複的
一、用運SecureCRT遠端對作業系統上,檢視一下目前系統版本号,及檔案系統格式
[root@centos6 ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)
[root@centos6 ~]# cat /proc/version
Linux version 2.6.32-642.el6.x86_64 ([email protected]) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) ) #1 SMP Tue May 10 17:27:01 UTC 2016
[root@centos6 ~]# uname -a
Linux centos6 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@centos6 ~]# uname -r
2.6.32-642.el6.x86_64
二、為友善本次實驗,我們新建立一檔案。
[root@centos6 ~]# mkdir /example
[root@centos6 ~]# cd /example/
[root@centos6 example]# cat /proc/meminfo > web.txt
[root@centos6 example]# ll
total 4
-rw-r--r--. 1 root root 1198 Dec 25 05:35 web.txt
[root@centos6 example]# df /example/
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg_centos6-LogVol01
18971088 3484148 14516600 20% /
[root@centos6 example]# debugfs
debugfs 1.41.12 (17-May-2010)
debugfs: open /dev/mapper/vg_centos6-LogVol01
debugfs: ls -d /example/
391720 (12) . 2 (12) .. 393297 (4072) web.txt
debugfs: quit
三、執行删除操作
[root@centos6 example]# rm -rf web.txt
四、打開,剛剛被删除檔案所在的分區
五、用ls 加-d參數顯示剛剛删除檔案所在的目錄
[root@centos6 example]# debugfs
391720 (12) . 2 (4084) .. <393297> (4072) web.txt
六、顯示有<>尖括号的就是我們要找的檔案Inode 号 執行logdump –I <19662057>
debugfs: logdump -i <393297>
Inode 393297 is at group 48, block 1572970, offset 2048
Journal starts at block 1, transaction 1746
No magic number at block 435: end of journal.
七,執行完指令後,顯示了一屏資訊,我們需要的是下面這一行,并且要記住,後面的值
九、退出dedugfs
qiut
十,執行如下指令
[root@centos6 example]# dd if=/dev/mapper/vg_centos6-LogVol01 of=/example/web.txt bs=2048 count=1 skip=1572970
1+0 records in
1+0 records out
2048 bytes (2.0 kB) copied, 0.00769495 s, 266 kB/s
十一,以上結果表示恢複成功我們看下/example目錄下到底有沒有
[root@centos6 example]# ll /example/
-rw-r--r--. 1 root root 2048 Dec 25 05:52 web.txt
————————————————————————————————————————————————————————
centos7不管用
[root@sheng ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@sheng ~]# cat /proc/version
Linux version 3.10.0-693.5.2.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Fri Oct 20 20:32:50 UTC 2017
[root@sheng ~]# uname -a
Linux sheng 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@sheng ~]# uname -r
[root@sheng ~]# mkdir example
[root@sheng ~]# cd example/
[root@sheng example]# cat /proc/meminfo > web.txt
[root@sheng example]# ll
-rw-r--r--. 1 root root 1226 Dec 25 10:03 web.txt
[root@sheng example]# ls
web.txt
[root@sheng example]# rm -rf web.txt
*****************************************************************************************
檢視目錄在分區
[root@sheng example]# df /root/example
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/cl-root 18855936 11376924 7479012 61% /
******************************************************************************************
四、運用,系統自還工具debugfs來修複
[root@sheng example]# debugfs
debugfs 1.42.9 (28-Dec-2013)
debugfs: open /dev/mapper/cl-root
/dev/mapper/cl-root: Bad magic number in super-block while opening filesystem
[root@sheng example]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/cl-root xfs 18G 11G 7.2G 61% /
.....
不支援xfs檔案格式的恢複
本文轉自 Mr_sheng 51CTO部落格,原文連結:http://blog.51cto.com/sf1314/2054166