Chinaunix首页 | 论坛 | 博客
  • 博客访问: 611243
  • 博文数量: 244
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-27 09:53
个人简介

记录学习,记录成长

文章分类

全部博文(244)

我的朋友

分类: LINUX

2015-06-11 23:18:52

前提是extundelete命令必须要有,我的红帽版本是6.4的,这次用这个命令来恢复,我的另一篇博客有下载地址和安装extundelete的介绍
http://blog.chinaunix.net/uid-30212356-id-5079136.html

用df  -hT命令可以查看文件系统类型,如:
[root@localhost extundelete-0.2.4]# df -Th
文件系统    类型      容量  已用  可用 已用%% 挂载点
/dev/sda2     ext4     18G  2.5G   15G  15% /
tmpfs        tmpfs    504M  224K  504M   1% /dev/shm
/dev/sda1     ext4    291M   32M  245M  12% /boot
/dev/sr0   iso9660    3.0G  3.0G     0 100% /media/RHEL_6.4 i386 Disc 1

上面只有/boot和/ 是ext4文件系统类型的,可以用来测试,当然你也可以用fdisk命令额外划分一个区来测试,这里我就用/boot来测试吧!

1.在/boot下拷贝几个文件,再创建一个目录和非空文本(随便写点内容),然后把a.txt拷贝到创建的目录中

[root@localhost boot]# cp /etc/passwd ./
[root@localhost boot]# cp /etc/hosts ./
[root@localhost boot]# vim a.txt
[root@localhost boot]# mkdir test
[root@localhost boot]# cp a.txt test/
[root@localhost boot]# ll test/
总用量 1
-rw-r--r-- 1 root root 15 6月  11 06:52 a.txt

2.用rm  -rf  文件    删除创建的文件和目录(可以一个一个的删也可以一下子全部删完)
[root@localhost boot]# rm -rf a.txt 
[root@localhost boot]# rm -rf hosts passwd 
[root@localhost boot]# rm -rf test/

3.删除之后,最好cd ~退出原目录重新开一个终端,在新开的终端上恢复。然后你可以用mount  -o  ro,remount  /boot以只读的方式重新挂载目录,也可以用umount    /boot目录直接卸载。然后创建一个目录
[root@localhost ~]# mkdir recover
[root@localhost ~]# cd recover/
[root@localhost recover]# 

4.开始恢复
可以以节点(inode)的方式恢复,他记录的是你的文件叫什么名字,在哪个块存放着

[root@localhost recover]# extundelete /dev/sda1 --inode 2  (这里要输入2)
                           .......
File name                                       | Inode number | Deleted status
.                                                 2
..                                                2
lost+found                                        11
grub                                              32385
efi                                               32387
passwd                                            18             Deleted
hosts                                             19             Deleted
vmlinuz-2.6.32-358.el6.i686                       16
initramfs-2.6.32-358.el6.i686.img                 17
test                                              20             Deleted
a.txt                                             21             Deleted
可以看到被删除的文件,状态是Deleted
进入原来的终端,进入/root/recover,如果想通过inode的方式恢复a.txt,inode 后要加上21

[root@localhost recover]# extundelete /dev/sda1 --restore-inode 21
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 38 groups loaded.
Loading journal descriptors ... 110 descriptors loaded.
[root@localhost recover]# ll
总用量 4
drwxr-xr-x 2 root root 4096 6月  11 07:49 RECOVERED_FILES        注意:恢复后的文件默认位于 RECOVERED_FILES 里!
[root@localhost recover]# ls RECOVERED_FILES/
file.21
以inode方式恢复时都是file.文件的inode形式,查看一下该文件,正是原来删除的文件

[root@localhost recover]# cat RECOVERED_FILES/file.21 
abcd
efgh
igkl

RECOVERED_FILES删了,用另外一种方式恢复
[root@localhost recover]# rm -rf RECOVERED_FILES/
[root@localhost recover]# ll
总用量 0

假如你知道删除的文件名,那么可以通过文件名恢复(我把刚恢复的文件又删除了)

[root@localhost recover]# extundelete /dev/sda1 --restore-file a.txt    //这里是删除的文件名
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 38 groups loaded.
Loading journal descriptors ... 110 descriptors loaded.
Successfully restored file a.txt

[root@localhost recover]# ll
总用量 4
drwxr-xr-x 2 root root 4096 6月  11 07:56 RECOVERED_FILES
[root@localhost recover]# ls RECOVERED_FILES/
a.txt
查看一下,恢复成功了!
[root@localhost recover]# cat RECOVERED_FILES/a.txt 
abcd
efgh
igkl

接下来看看可不可以恢复目录(我把刚恢复的文件又删除了
这个恢复目录的时候有可能恢复出来也可能恢复不出来的。

[root@localhost recover]# extundelete /dev/sda1 --restore-directory /test
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 38 groups loaded.
Loading journal descriptors ... 110 descriptors loaded.
Searching for recoverable inodes in directory /test ... 
6 recoverable inodes found.
Looking through the directory structure for deleted files ... 
5 recoverable inodes still lost.

可以看到,找到了6个inode,但是5个丢失了,查看一下,成功的恢复了,不错!

[root@localhost recover]# ls RECOVERED_FILES/
test
[root@localhost recover]# cat RECOVERED_FILES/test/a.txt 
abcd
efgh
igkl

如果你很懒的话,也可以一下子恢复所有的文件或目录(删除所有恢复的东西重新测试)
[root@localhost recover]# extundelete /dev/sda1 --restore-all
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 38 groups loaded.
Loading journal descriptors ... 110 descriptors loaded.
Searching for recoverable inodes in directory / ... 
6 recoverable inodes found.
Looking through the directory structure for deleted files ... 
1 recoverable inodes still lost.
[root@localhost recover]# ll
总用量 4
drwxr-xr-x 3 root root 4096 6月  11 08:10 RECOVERED_FILES
[root@localhost recover]# ll RECOVERED_FILES/
总用量 20
-rw-r--r-- 1 root root   15 6月  11 08:10 a.txt
-rw-r--r-- 1 root root  781 6月  11 08:10 file.32391
-rw-r--r-- 1 root root  158 6月  11 08:10 hosts
-rw-r--r-- 1 root root 1522 6月  11 08:10 passwd
drwxr-xr-x 2 root root 4096 6月  11 08:10 test
最后再重新挂载一下刚刚卸载的/dev/sda1或者/boot即可~

总之,方法就是这个方法,具体的需要你试一下!而且你还可以用extundelete  --help查看一下具体的功能,根据你的需求来恢复删除的东西;
阅读(1580) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~