一、需求研究

分析对比debugfs、testdisk 6.14、extundelete,对比各自官网介绍和操作说明本次决定研究extundelete对文件和目录的恢复操作。

二、项目内容

1、工具安装部署

官方网站是http://extundelete.sourceforge.net/ ,其目前的稳定版本是extundelete-0.2.4.

工具下载

wget https://nchc.dl.sourceforge.net/project/extundelete/extundelete/0.2.4/extundelete-0.2.4.tar.bz2

解压按装

依赖包

yum -y install gcc-c++ e2fsprogs.x86_64 e2fsprogs-devel.x86_64

tar -jxvf extundelete-0.2.4.tar.bz2

cd extundelete-0.2.4

./configure

这时一般会报错;

Configuring extundelete 0.2.4
configure: error: in `/root/Desktop/extundelete-0.2.4':
configure: error: C++ compiler cannot create executables
See `config.log' for more details

经过查找知道需要安装gcc-c++包

yum -y install gcc gcc-c++

重新./configure显示
[root@localhost extundelete-0.2.4]# ./configure 
Configuring extundelete 0.2.4
configure: error: Can't find ext2fs library

经过查找知道缺少e2fsprogs-devel,下面开始安装

yum -y install e2fsprogs-devel

再./configure出现,表示成功了;

[root@localhost extundelete-0.2.4]# ./configure 
Configuring extundelete 0.2.4
Writing generated files to disk

make && make install

验证安装结果

extundelete -v

前提:如果确定文件被误删,在没有备份的情况下请马上对分区实施写入保护,(预防新的写入覆盖误删的块数据)mount -o remount,ro /dev/sdb1或者直接umount /dev/sdb1/解挂载目录,df -h命令可以看出你的数据目录挂载在那个分区下(fdisk磁盘管理)

2、文件恢复操作过程

恢复指定文件:

extundelete /dev/sdb1 --inode 2

可能会报下面错误

/usr/local/extundelete/bin/extundelete: Bad magic number in super-block when trying to open filesystem /dev/sdb1

网上搜了下,lvm是有区别的,主要是lvm的设备名不是/dev/sda的形式了vgscan查看具体的卷名。最后发现我的卷名是/dev/vg_centosdesktop/lv_root。

原理:从根节点(inode=2)开始找到被删除文件的i节点,然后recover i节点。

以下操作模拟在/dev/sdb1 删除文件apache-tomcat-8.0.24.tar.gz 和目录tomcat-app1,

extundelete /dev/sdb1 --inode 2

NOTICE: Extended attributes are not restored.

WARNING: EXT3_FEATURE_INCOMPAT_RECOVER is set.

The partition should be unmounted to undelete any files without further data loss.

If the partition is not currently mounted, this message indicates

it was improperly unmounted, and you should run fsck before continuing.

If you decide to continue, extundelete may overwrite some of the deleted

files and make recovering those files impossible.  You should unmount the

file system and check it with fsck before using extundelete.

Would you like to continue? (y/n)

y

Loading filesystem metadata ... 4000 groups loaded.

Group: 0

Contents of inode 2:

00d0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................

00e0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................

00f0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................

Inode is Allocated

File mode: 16877

Low 16 bits of Owner Uid: 0

Size in bytes: 4096

Access time: 1482394360

Creation time: 1482394361

Modification time: 1482394361

Deletion Time: 0

Low 16 bits of Group Id: 0

Links count: 3

Blocks count: 8

File flags: 0

File version (for NFS): 0

File ACL: 0

Directory ACL: 0

Fragment address: 0

Direct blocks: 9249, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

Indirect block: 0

Double indirect block: 0

Triple indirect block: 0

File name                                       | Inode number | Deleted status

.                                                 2

..                                                2

lost+found                                        11

apache-tomcat-8.0.24.tar.gz                       13             Deleted

apache-tomcat-8.0.24                              30670849       Deleted

tomcat-app1                                       30670849       Deleted

关注红色信息

恢复命令(恢复过程不要在误删分区进行,谨防inode、block块相互覆盖

extundelete /dev/sdb1 --restore-inode 13   根据inode信息进行文件恢复

extundelete /dev/sdb1 --restore-file apache-tomcat-8.0.24.tar.gz  根据文件名进行文件修复

修复后的文件存储在当前目录RECOVERED_FILES里面

ll RECOVERED_FILES/

-rw-r----- 1 root root 9106353 Dec 22 17:23 apache-tomcat-8.0.24.tar.gz

-rw-r----- 1 root root 9106353 Dec 22 17:23 file.13

3、目录恢复操作过程

extundelete /dev/sdb1 --restore-directory /tomcat-app1 根据目录名称恢复目录

NOTICE: Extended attributes are not restored.

WARNING: EXT3_FEATURE_INCOMPAT_RECOVER is set.

The partition should be unmounted to undelete any files without further data loss.

If the partition is not currently mounted, this message indicates

it was improperly unmounted, and you should run fsck before continuing.

If you decide to continue, extundelete may overwrite some of the deleted

files and make recovering those files impossible.  You should unmount the

file system and check it with fsck before using extundelete.

Would you like to continue? (y/n)

y

Loading filesystem metadata ... 4000 groups loaded.

Loading journal descriptors ... 1204 descriptors loaded.

Searching for recoverable inodes in directory /tomcat-app1 ...

2405 recoverable inodes found.

Looking through the directory structure for deleted files ...

ll RECOVERED_FILES/

-rw-r----- 1 root root 9106353 Dec 22 17:23 apache-tomcat-8.0.24.tar.gz

-rw-r----- 1 root root 9106353 Dec 22 17:23 file.13

drwxr-x--- 6 root root    4096 Dec 22 17:27 tomcat-app1   恢复成功

4.重新挂载磁盘目录或者reboot重启都是ok的。

三、项目结果

根据上面操作证明extundelete 工具可以实现对误删数据的恢复,而且操作简单。

总结:

1、使用rm一定要谨慎

2、磁盘按照功能进行分区是必要的

3、最少掌握一种数据恢复方式

Linux文件误删恢复的更多相关文章

  1. linux 下文件误删恢复

    linux 下文件误删恢复 0x01 事件背景 某天晚上写代码的时候,本来想删除当前目录下一个叫xxx的文件夹 rm -rdf ./xxx/*, 结果光顾着和人说话,一不留神手贱把命令敲成了rm -r ...

  2. git stash 暂存恢复和文件误删恢复

    git commit提交文件,服务器返回本地文件有修改. 1.git stash :暂存本地代码 2.git pull origin develop : 获取远程分支代码 3.git stash po ...

  3. Linux文件误删之后恢复方法

    前言 今天不小心把一个文件给误删了,因为不想花半天时间重新写,就查找了一下Linux下恢复文件的方法. 因为是刚删不久,文件实际的数据应该还在 首先查看系统分区 Linux:~# df Filesys ...

  4. Linux文件误删除恢复操作

    作为一个多用户.多任务的操作系统,Linux下的文件一旦被删除,是难以恢复的.尽管删除命令只是在文件节点中作删除标记,并不真正清除文件内容,但是 其他用户和一些有写盘动作的进程会很快覆盖这些数据.不过 ...

  5. 40、Linux文件误删除恢复操作

    rm -rf / #此方法删除不了/目录: rm -rf /* #此方法可以删除/目录下的所有内容,禁止使用: 40.1.前言: 作为一个多用户.多任务的操作系统,Linux下的文件一旦被删除,是难以 ...

  6. oracle11g 数据文件误删恢复(无备份)

    OS: Oracle Linux Server release 5.7 DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - ...

  7. linux 文件删除恢复extundelete

    首先要把删除文件所有磁盘分区卸载掉 然后安装yum install -y extundelete *2fs* extundelete /dev/sdb1 --inode #查看sdb1分区下删除的文件 ...

  8. 【实习记】2014-09-26恢复linux下误删的ntfs盘中的文件

        情景,ubuntu下把NTFS格式的盘中的“实习记”文件夹彻底删除了,追毁莫及,粗心觉不是一件好的事情. linux下回复ntfs盘下的文件不能用ext3grep,而使用debugfs命令实在 ...

  9. Linux下文件误删除恢复案例

    说明:将/etc/profile文件删除,然后恢复 在linux中为什么讲文件删除还能恢复呢? 详见:文件删除原理 http://blog.csdn.net/grantlee1988/article/ ...

随机推荐

  1. leetcode解题报告(27):Reverse Linked List

    描述 Reverse a singly linked list. 分析 一开始写的时候总感觉没抓到要点,然后想起上数据结构课的教材上有这道题,翻开书一看完就回忆起来了,感觉解法挺巧妙的,不比讨论区的答 ...

  2. 洛谷 P1257 平面上的最接近点对 题解

    P1257 平面上的最接近点对 题目描述 给定平面上n个点,找出其中的一对点的距离,使得在这n个点的所有点对中,该距离为所有点对中最小的. 输入格式 第一行:n:2≤n≤10000 接下来n行:每行两 ...

  3. [java][JEECG] Maven settings.xml JEECG项目初始化 RouYi settings.xml配置

    好吧一下是经验之谈,原本这些坑不应该躺的,从头看手册完全可以避免这些. 懒得整理了,看懂了就看,看不懂自己琢磨JEECG的帮助文档去,不过嘛我喜欢用Intelij IDEA,他里面都是别的IDE,不喜 ...

  4. PHP var_dump() 函数

    var_dump() 函数用于输出变量的相关信息 <?php $b = 3.1; $c = true; var_dump($b, $c); ?> 输出 float(3.1) bool(tr ...

  5. JetBrains CLion 2019 for Mac(智能C和C++编辑器)中英文如何切换完整教程

    右键显示包内容,进入目录,contents/lib,删除resources_zh.jar,重启即可. 参考: https://blog.csdn.net/qq_45179462/article/det ...

  6. 2、Apache(httpd)之一 三种工作模式

    httpd的特性: 高度模块化:core + modules 模块化设计DSO:Dynamic Shared Object MPM:Multipath Processing Modules 多路处理模 ...

  7. jenkins之SSH Publishers环境变量

    我使用的是docker部署jenkins,使用172.16.1.245作为部署服务器. 1.问题 在SSH Publishers里执行的环境变量,不是ssh server主机设置的环境变量,这样会导致 ...

  8. Ibatis自动解决sql注入机制

    疑问1:为什么IBatis解决了大部分的sql注入?(实际上还有部分sql语句需要关心sql注入,比如like) 之前写Java web,一直使用IBatis,从来没有考虑过sql注入:最近写php( ...

  9. php手记之06-tp5验证器

    # 创建验证器 php think make:validate 模块名/验证器名(首字母大写) # 验证器 namespace app\index\validate; use think\Valida ...

  10. Mitmproxy的mimdump mimproxy mitmweb命令行性能对比

    引用官方的原话如下 Very cool test - thanks for sharing!