在生产环境,运维人员有时候会误删文件,或者一些别有用心的人故意删除你服务器数据上的重要数据。出现这种情况导致数据丢失,对公司可能造成重大影响,因此你的饭碗也有可能不保。在linux环境下有一些帮助我们恢复丢失数据的软件,其中"extundelete"就是一个很强大的开源软件。
首先,下载extundelete,编译安装它。
[[email protected] opt]# wget http://sourceforge.net/projects/extundelete/files/latest/download
[[email protected] opt]# tar jxf extundelete-0.2.4.tar.bz2
[[email protected] opt]# ls
extundelete-0.2.4 extundelete-0.2.4.tar.bz2
[[email protected] opt]# cd extundelete-0.2.4
[[email protected] extundelete-0.2.4]# ./configure
[[email protected] extundelete-0.2.4]#make && make install
测试建立测试环境
[[email protected] extundelete-0.2.4]# mkdir /movie
[[email protected] extundelete-0.2.4]# mkfs.ext3 /dev/sdb
[[email protected] ~]# mount /dev/sdb /movie/
[[email protected] ~]# vim /movie/test
[[email protected] ~]# mkdir /movie/data
[[email protected] ~]# cp /etc/passwd /movie/data/
[[email protected] ~]# rm -rf /movie/*
[[email protected] ~]# umount /dev/sdb
查看/dev/sdb的数据情况,可以看到被删除的文件"deleted".
[[email protected] /]# extundelete /dev/sdb --inode 2
File name | Inode number | Deleted status
. 2
.. 2
.test.swp 11 Deleted
test 12 Deleted
data 751728 Deleted
恢复单个文件:
[[email protected] /]# extundelete /dev/sdb --restore-file test
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 80 groups loaded.
Loading journal descriptors ... 39 descriptors loaded.
Successfully restored file test
恢复单个目录:
[[email protected] ~]# extundelete /dev/sdb --restore-directory bbq
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 80 groups loaded.
Loading journal descriptors ... 34 descriptors loaded.
Searching for recoverable inodes in directory bbq ...
2 recoverable inodes found.
Looking through the directory structure for deleted files ...
Unable to restore inode 557058 (bbq/qweqweqw): Space has been reallocated.
1 recoverable inodes still lost.
恢复所有文件:
[[email protected] ~]# extundelete /dev/sdb --restore-all
extundelete会把文件恢复到当前目录的“ RECOVERED_FILES”里面,可以查看数据是否有还原回来
[[email protected] /]# ls RECOVERED_FILES/
test test.v1