欢迎光临
我们一直在努力

Linux文件误删除debugfs恢复操作

前言

作为一个多用户、多任务的操作系统,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 (mockbuild@worker1.bsys.centos.org) (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

四、打开,刚刚被删除文件所在的分区

 

[root@centos6 example]# df /example/

Filesystem           1K-blocks    Used Available Use% Mounted on

/dev/mapper/vg_centos6-LogVol01

18971088 3484148  14516600  20% /

五、用ls 加-d参数显示刚刚删除文件所在的目录

 

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

debugfs:  quit

七,执行完命令后,显示了一屏信息,我们需要的是下面这一行,并且要记住,后面的值

 

No magic number at block 435: end of journal.

debugfs:  quit

九、退出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/

total 4

-rw-r–r–. 1 root root 2048 Dec 25 05:52 web.txt

————————————————————————————————————————————————————————

centos7不管用

一、用运SecureCRT远程对操作系统上,查看一下当前系统版本号,及文件系统格式

[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 (builder@kbuilder.dev.centos.org) (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

total 4

-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文件格式的恢复

赞(0) 打赏
未经允许不得转载:运维那些事 » Linux文件误删除debugfs恢复操作

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏