Linux文件误删恢复
一、需求研究
分析对比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文件误删恢复的更多相关文章
- linux 下文件误删恢复
linux 下文件误删恢复 0x01 事件背景 某天晚上写代码的时候,本来想删除当前目录下一个叫xxx的文件夹 rm -rdf ./xxx/*, 结果光顾着和人说话,一不留神手贱把命令敲成了rm -r ...
- git stash 暂存恢复和文件误删恢复
git commit提交文件,服务器返回本地文件有修改. 1.git stash :暂存本地代码 2.git pull origin develop : 获取远程分支代码 3.git stash po ...
- Linux文件误删之后恢复方法
前言 今天不小心把一个文件给误删了,因为不想花半天时间重新写,就查找了一下Linux下恢复文件的方法. 因为是刚删不久,文件实际的数据应该还在 首先查看系统分区 Linux:~# df Filesys ...
- Linux文件误删除恢复操作
作为一个多用户.多任务的操作系统,Linux下的文件一旦被删除,是难以恢复的.尽管删除命令只是在文件节点中作删除标记,并不真正清除文件内容,但是 其他用户和一些有写盘动作的进程会很快覆盖这些数据.不过 ...
- 40、Linux文件误删除恢复操作
rm -rf / #此方法删除不了/目录: rm -rf /* #此方法可以删除/目录下的所有内容,禁止使用: 40.1.前言: 作为一个多用户.多任务的操作系统,Linux下的文件一旦被删除,是难以 ...
- oracle11g 数据文件误删恢复(无备份)
OS: Oracle Linux Server release 5.7 DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - ...
- linux 文件删除恢复extundelete
首先要把删除文件所有磁盘分区卸载掉 然后安装yum install -y extundelete *2fs* extundelete /dev/sdb1 --inode #查看sdb1分区下删除的文件 ...
- 【实习记】2014-09-26恢复linux下误删的ntfs盘中的文件
情景,ubuntu下把NTFS格式的盘中的“实习记”文件夹彻底删除了,追毁莫及,粗心觉不是一件好的事情. linux下回复ntfs盘下的文件不能用ext3grep,而使用debugfs命令实在 ...
- Linux下文件误删除恢复案例
说明:将/etc/profile文件删除,然后恢复 在linux中为什么讲文件删除还能恢复呢? 详见:文件删除原理 http://blog.csdn.net/grantlee1988/article/ ...
随机推荐
- fluent懒人篇之journal的用法【转载】
转载地址:http://blog.sina.cn/dpool/blog/s/blog_63a80e870100oblp.html?type=-1 当你在用fluent计算大量类似算例,重复着相同操作的 ...
- 2、vueJs基础知识02
vue生命周期: 钩子函数: created -> 实例已经创建 √ beforeCompile -> 编译之前 compiled -> 编译之后 ready -> 插入到文档 ...
- c# lock TransactionScope
c# lock TransactionScope TransactionOptions option = new TransactionOptions(); //option.IsolationLev ...
- 高可用Redis:Redis Cluster
转(https://www.cnblogs.com/renpingsheng/p/9862485.html) Redis Cluster是Redis官方提供的Redis集群功能 1.为什么要实现Red ...
- SPM(Software Project Management)课程感想
今天要说的是软件项目管理课程学习后的一些心得体会.这学期我选修了软件项目管理课程,进行了共8周的学习. 其实,进入大三后,我们开设了各种专业选修课,通过对各种课程的学习,我见识到了丰富多样的知识体 ...
- PostgreSQL中定时job执行(pgAgent)
PostgreSQL中定时job执行 业务分析 近期项目需要定期清理数据库中的多余数据,即每月1号删除指定表中一年以上的数据. 初步分析这种定时job可以使用一下两种技术实现: Linux的cront ...
- 第2课第1节_Java面向对象编程_类的引入_P【学习笔记】
摘要:韦东山android视频学习笔记 1. 面向对象编程的引入,我们先写一个简单的程序输出张三,李四的名字.代码如下,假如,现在我们要在名字前面添加籍贯广东,那样岂不是每个printf语句都得修改添 ...
- 微信小程序的z-index在苹果ios无效
1.在微信开发者工具可以正常显示 2.在安卓真机手机可以正常显示 3.在ios手机真机无法正常显示 原因:父级view的css属性有 position: fixed; ,把它注释掉即可
- MQTT(一)C#使用 MQTTnet 快速实现 MQTT 通信(文末有完整Demo下载)
https://blog.csdn.net/panwen1111/article/details/79245161 目录MQTT(一)C#使用 MQTTnet 快速实现 MQTT 通信(文末有完整De ...
- jvm 命令使用调优 通过jstat、jmap对java程序进行性能调优
转载:http://blog.csdn.net/jerry024/article/details/8507589 转载: https://blog.csdn.net/zhaozheng7758/art ...