一、需求研究

分析对比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. Problem 4 dp

    $des$ 小 $Y$ 十分喜爱光学相关的问题, 一天他正在研究折射.他在平面上放置了 $n$ 个折射装置, 希望利用这些装置画出美丽的折线.折线将从某个装置出发, 并且在经过一处装置时可以转向, 若 ...

  2. 数据科学速查手册(包括机器学习,概率,微积分,线性代数,python,pandas,numpy,数据可视化,SQL,大数据等方向)

    介绍:https://redstonewill.com/2372/ 项目网址:https://github.com/FavioVazquez/ds-cheatsheets

  3. c++学习知识整理

    <iomanip>传送门:https://baike.baidu.com/item/iomanip/3319954?fr=aladdin linux为何用./运行程序:https://bl ...

  4. 【一起来烧脑】一步学会CSS3体系

    [外链图片转存失败(img-yfi1VPyy-1563434266398)(https://upload-images.jianshu.io/upload_images/11158618-fc8784 ...

  5. Three.js实现滚轮放大展现不同的模型

    目录 Three.js实现滚轮放大展现不同的模型 修改OrbitControls.js的源码 OrbitControls在透视相机(PerspectiveCamera)的控制原理 具体实现 Three ...

  6. [WC2010]重建计划(长链剖分版)

    传送门 Description Solution 时隔多年,补上了这题的长链剖分写法 感觉比点分治要好写的多 我们假设\(pos\)是当前点的\(dfn\),它距离所在链的底端的边的数量是\(len\ ...

  7. WSL2(Ubuntu)安装Postgres

    原文链接:https://www.xu.ci/2019/12/wsl2ubuntupostgres.html 原文作者:博客园--曲高终和寡 *******************如果你看到这一行,说 ...

  8. localstorage和cookie的设置方法和获取方法

    1.设置localStorage window.localStorage.setItem(vm.mobileSelf,JSON.stringify(contactInfo)); vm.mobileSe ...

  9. 【caffe Net】使用举例和代码中文注释

    首先是Net使用的小例子: #include <vector> #include <iostream> #include <caffe/net.hpp> using ...

  10. Manning Java Persistence with Hibernate & hibernate_in_action

    Manning | Java Persistence with Hibernatehttps://www.manning.com/books/java-persistence-with-hiberna ...