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


CentOS7使用Extundelete恢复误删除的文件


本文转自 Mr_sheng 51CTO博客,原文链接:http://blog.51cto.com/sf1314/2054166


相关文章
|
3天前
|
Linux
Linux 文件查找
Linux 文件查找
|
1天前
|
运维 监控 Linux
如何在Linux上部署1Panel运维管理面板并远程访问内网进行操作
如何在Linux上部署1Panel运维管理面板并远程访问内网进行操作
4 0
如何在Linux上部署1Panel运维管理面板并远程访问内网进行操作
|
2天前
|
Linux 开发工具
Linux E325: 注意 发现交换文件 “*.swp“
Linux E325: 注意 发现交换文件 “*.swp“
11 0
|
2天前
|
Linux 开发工具
linux中出现不在 sudoers 文件中。此事将被报告的解决方法
linux中出现不在 sudoers 文件中。此事将被报告的解决方法
9 0
|
2天前
|
编解码 Linux Android开发
linux文件组 avc: denied { dac_read_search } for capability=2
linux文件组 avc: denied { dac_read_search } for capability=2
9 0
|
2天前
|
关系型数据库 MySQL Linux
Linux 文件访问权限说明
Linux 文件访问权限说明
8 0
|
2天前
|
运维 NoSQL Linux
linux环境收集core文件步骤
请注意,生成core文件可能会占用磁盘空间,因此应谨慎使用。一旦完成故障排查,建议将相关的core文件删除以释放磁盘空间。
28 5
|
3天前
|
运维 NoSQL Linux
linux环境收集core文件步骤
请注意,生成core文件可能会占用磁盘空间,因此应谨慎使用。一旦完成故障排查,建议将相关的core文件删除以释放磁盘空间。
18 4
|
5天前
|
Linux 开发工具 Perl
|
7天前
|
Shell Linux 开发工具
【Linux】环境变量常见指令操作&基本实验(入门必看!)
【Linux】环境变量常见指令操作&基本实验(入门必看!)