Chinaunix首页 | 论坛 | 博客
  • 博客访问: 417841
  • 博文数量: 73
  • 博客积分: 1420
  • 博客等级: 上尉
  • 技术积分: 661
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-15 21:41
文章分类

全部博文(73)

文章存档

2017年(25)

2016年(6)

2015年(5)

2011年(1)

2010年(1)

2009年(2)

2007年(7)

2006年(26)

我的朋友

分类: LINUX

2017-06-07 17:26:18


转载至:

1.问题

因误操作,把磁盘中部分的文件删除了,需要进行恢复。
※ 注意:
在进行恢复前,不要对需要恢复的分区进行写入的操作。
如果分区在单独的磁盘上,应该把该磁盘卸载后,进行修复。(非 mount 状态)
如果分区与根分区在同一个磁盘上,那么,可以把分区挂载为 ro 只读状态;


mount -o remount,ro /dev/sdX1

如果需要修复的就是根分区所在的分区,那么,只能把机器关闭后,把磁盘挂载到其他的机器上进行修复。
◎ 修复的原理:
通过遍历文件系统的 journal ,找到对应的 inode 位置,然后组成正常的文件。
所以,若使用 mkfs.ext4 等格式化的磁盘,superblock 全部被刷写,则是无法修复的。

2.解决
通过 extundelete 工具可以进行尝试修复。
安装需要编译,编译前应安装 e2fsprogs-devel 软件包以及 gcc 等编译工具。
解压后,执行./configure 和 make install
然后对指定的分区进行扫描即可:

[root@demo ~]# extundelete --restore-all /dev/vdc1
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 160 groups loaded.
Loading journal descriptors ... 25677 descriptors loaded.
Searching for recoverable inodes in directory / ...
57192 recoverable inodes found.
Looking through the directory structure for deleted files ...
1 recoverable inodes still lost.

若能找到误删除的文件,所有恢复的文件默认会放在当前目录的 RECOVERED_FILES 目录中,需要注意可用磁盘的大小。

若能准确知道需要进行恢复文件的删除时间,可以考虑加入 --after 参数:

# extundelete --restore-all --after $(($(date +%s) - 7200)) /dev/sdX1

恢复时,还可以指定 inode、文件路径、目录等参数:

--restore-inode ino[,ino,...]
Restore the file(s) with known inode number 'ino'.
The restored files are created in ./RECOVERED_FILES
with their inode number as extension (ie, file.12345).
--restore-file 'path' Will restore file 'path'. 'path' is relative to root
of the partition and does not start with a '/'
The restored file is created in the current
directory as 'RECOVERED_FILES/path'.
--restore-files 'path' Will restore files which are listed in the file 'path'.
Each filename should be in the same format as an option
to --restore-file, and there should be one per line.
--restore-directory 'path'
Will restore directory 'path'. 'path' is relative to the
root directory of the file system. The restored
directory is created in the output directory as 'path'.
--restore-all Attempts to restore everything.


对应 superblock 部分损坏的情况,可以另外指定 backup superblock 位置进行修复:

-b blocknumber Uses the backup superblock at blocknumber when opening
the file system.


3.参考文档
undelete a just deleted file on ext4 with extundelete


undelete 官网


undelete 源码:
extundelete-0.2.4.tar.bz2
阅读(690) | 评论(0) | 转发(0) |
0

上一篇:Cisco VLAN划分,GVRP还是VTP

下一篇:没有了

给主人留下些什么吧!~~