当前位置: 首页 > news >正文

https://blog.csdn.net/dayancn/article/details/54692111

Ubuntu恢复被删除的文件

 

昨天一不小心,执行了rm xx  -rf,把一个项目删除了。然后就是各种悔恨,各种自责,这个项目可是一周的工作量啊。最后肯定得解决,于是google搜索发现了恢复神器extundelete,最后顺利恢复了所有被我无意中的删除的文件。感谢上天,感谢extundelete。下面将个人的经历总结下。

如何使用extundelete

 

1)  下载工具extundelete

       Ubuntu下下载这个工具太简单了

[python]  view plain  copy
 
 
  在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install extundelete  

 

2)  使用

     使用这个也很简单。使用extundelete–help命令,可以告诉我们很多。

 

[python]  view plain  copy
 
 
  在CODE上查看代码片派生到我的代码片
  1. Itleaks@ Itleaks::~$ extundelete --help  
  2. Usage: extundelete [options] [--] device-file  
  3. Options:  
  4.   ……………….  
  5.   --after dtime          Only process entries deleted on or after 'dtime'.  
  6.   --before dtime         Only process entries deleted before 'dtime'.  
  7. Actions:  
  8.   …………  
  9.   --restore-file 'path'  Will restore file 'path'. 'path' is relative to root  
  10.                          of the partition and does not start with a '/' (it  
  11.                          must be one of the paths returned by --dump-names).  
  12.                          The restored file is created in the current  
  13.                          directory as 'RECOVERED_FILES/path'.  
  14.   --restore-files 'path' Will restore files which are listed in the file 'path'.  
  15.                          Each filename should be in the same format as an option  
  16.                          to --restore-file, and there should be one per line.  
  17.   --output-dir 'path'    Restore files in the output dir 'path'.  
  18.                          By default the restored files are created under current directory 'RECOVERED_FILES'.  
  19.   --restore-all          Attempts to restore everything.  
  20.   ………..  

      我们知道当我们不小心删除了有用的文件,我们一般是比较容易知道删除的时间的,因此,使用时间这个option可以很快并且精确的恢复出我们想要的文件。那这个dtime怎么生成。请参考如下命令:

      

[python]  view plain  copy
 
 
  在CODE上查看代码片派生到我的代码片
  1. Itleaks@ Itleaks:~$ date -d "2014-06-01 23:02:00" +%s  
  2. 1401634920  

     %s的意思是seconds since 1970-01-01 00:00:00 UTC,就是输入时间与1970-01-0100:00:00的时间差

     然后就可以使用这个来恢复了

[python]  view plain  copy
 
 
  在CODE上查看代码片派生到我的代码片
  1. sudo extundelete /dev/sda8 --after 1401634920--restore-all  

     现在我们来做个试验:具体操作如下

 

[python]  view plain  copy
 
 
  在CODE上查看代码片派生到我的代码片
  1. Itleaks@ Itleaks:/tmp$ echo "recovery test"> itleaks.test  
  2. Itleaks@ Itleaks:/tmp$ rm itleaks.test   
  3. Itleaks@ Itleaks:/tmp$ date -d "2014-06-01 22:28:00" +%s  
  4. 1401632880  
  5. Itleaks@ Itleaks:/tmp$ sudo extundelete /dev/sda8 --after 1401632880 --restore-all  
  6. Only show and process deleted entries if they are deleted on or after 1401632880 and before 9223372036854775807.  
  7.   
  8. WARNING: Extended attributes are not restored.  
  9. WARNING: EXT3_FEATURE_INCOMPAT_RECOVER is set.  
  10. The partition should be unmounted to undelete any files without further data loss.  
  11. If the partition is not currently mounted, this message indicates   
  12. it was improperly unmounted, and you should run fsck before continuing.  
  13. If you decide to continue, extundelete may overwrite some of the deleted  
  14. files and make recovering those files impossible.  You should unmount the  
  15. file system and check it with fsck before using extundelete.  
  16. Would you like to continue? (y/n)   
  17. y  
  18. Loading filesystem metadata ... 378 groups loaded.  
  19. Loading journal descriptors ...   
  20. 27106 descriptors loaded.  
  21. Searching for recoverable inodes in directory / ...   
  22.   
  23. 85 recoverable inodes found.  
  24. Looking through the directory structure for deleted files ...   
  25. ………………..  
  26. Unable to restore inode 2360218 (etc/brltty/brl-fs-bumpers.kti): No undeleted copies found in the journal.  
  27. Unable to restore inode 2359564 (etc/mtab~): No undeleted copies found in the journal.  
  28. Restored inode 2883641 to file RECOVERED_FILES/tmp/itleaks.test  
  29.   
  30. Itleaks@ Itleaks:/tmp$ tree RECOVERED_FILES/  
  31. RECOVERED_FILES/  
  32. └── tmp  
  33.     └── itleaks.test  
  34.   
  35. 1 directory, 1 file  

extundelete原理

         这个是由于linuxext3文件系统的组织结构决定的,如下图:

          

         在Linux系统中,超级块描述了分区的信息,一个分区被分为两个部分,索引节点表和数据块区,这个在格式化的时候就定下来了。文件(目录也是文件的一种,只不过它的内容是描述目录下的文件的)由索引节点描述,索引节点描述了文件的修改时间,文件的名称,文件的数据块地址等等。并且,linux对于文件删除操作是个懒动作,删除文件时系统只是将文件对应的索引节点及其拥有的数据块置为free(将nlink=0),而并没有做其他清空的,只有当这个索引节点或者数据块被真正用到的时候才会修改里面的数据。这就为我们文件修复提供了可趁之机。由于系统中的索引节点是固定大小的,因此可以很轻松的遍历扫描系统中所有的索引节点,找出free的索引节点并检查其数据块是否已经被用,如果没有则可修复并修复。同时,由于索引节点里的时间等信息也是保留的,因此就可以根据时间来恢复特定的被删除的文件。

文件误删除后的注意事项

     从上面的分析可知,误删文件后,尽量不要做大的数据操作,以避免被删除的文件的数据块被重新使用,导致数据完全丢失。

 

 

/********************************

* 本文来自博客  “爱踢门”

* 转载请标明出处:http://blog.csdn.net/itleaks

******************************************/

转载于:https://www.cnblogs.com/Ph-one/p/9516015.html

相关文章:

  • 用C++调用tensorflow在python下训练好的模型(centos7)
  • 如何用Tensorflow训练模型成pb文件和和如何加载已经训练好的模型文件
  • TensorFlow 自定义模型导出:将 .ckpt 格式转化为 .pb 格式
  • 模型文件后缀介绍
  • 【专家坐堂QA】在 petalinux-config 中选择外部来源时,可将符号链路添加内核来源目录树...
  • 动态存储区、静态存储区、堆和栈的区别
  • 浅析alsa声卡驱动snd_interval结构体openmin,openmax和integer含义
  • fread和fseek的用法
  • 17-18专业课
  • 希尔排序为什么不稳定
  • memory cache 和 disk cache
  • 现成
  • 光滑--可导
  • alloc_skb申请函数分析
  • UML状态机图【图3】--☆
  • 《Javascript数据结构和算法》笔记-「字典和散列表」
  • Angular2开发踩坑系列-生产环境编译
  • angular2开源库收集
  • CentOS从零开始部署Nodejs项目
  • js面向对象
  • MD5加密原理解析及OC版原理实现
  • mysql外键的使用
  • python 装饰器(一)
  • Vue2 SSR 的优化之旅
  • vue2.0一起在懵逼的海洋里越陷越深(四)
  • Webpack 4x 之路 ( 四 )
  • 聊一聊前端的监控
  • 罗辑思维在全链路压测方面的实践和工作笔记
  • 微信公众号开发小记——5.python微信红包
  • 云栖大讲堂Java基础入门(三)- 阿里巴巴Java开发手册介绍
  • #pragma 指令
  • (03)光刻——半导体电路的绘制
  • (2)nginx 安装、启停
  • (Mac上)使用Python进行matplotlib 画图时,中文显示不出来
  • (二开)Flink 修改源码拓展 SQL 语法
  • (附源码)ssm教师工作量核算统计系统 毕业设计 162307
  • (详细版)Vary: Scaling up the Vision Vocabulary for Large Vision-Language Models
  • (转)visual stdio 书签功能介绍
  • (转载)Linux网络编程入门
  • ***linux下安装xampp,XAMPP目录结构(阿里云安装xampp)
  • . NET自动找可写目录
  • .net framework4与其client profile版本的区别
  • .NET MVC第三章、三种传值方式
  • .vue文件怎么使用_vue调试工具vue-devtools的安装
  • @configuration注解_2w字长文给你讲透了配置类为什么要添加 @Configuration注解
  • @Query中countQuery的介绍
  • [ IO.File ] FileSystemWatcher
  • [23] GaussianAvatars: Photorealistic Head Avatars with Rigged 3D Gaussians
  • [AutoSar]BSW_OS 02 Autosar OS_STACK
  • [BZOJ1008][HNOI2008]越狱
  • [C#]C# winform实现imagecaption图像生成描述图文描述生成
  • [C++]C++类基本语法
  • [C++打怪升级]--学习总目录
  • [CareerCup] 17.8 Contiguous Sequence with Largest Sum 连续子序列之和最大
  • [Git].gitignore失效的原因