centos5下面恢复数据手记
作者:阿川 发布时间:May 28, 2014 分类:服务器
客户在我这边有一台基于xen-hvm的VPS,硬盘40G,分为10G系统.30G为数据盘(挂载在/home下面).网站在/home下面.数据库安装在usr/local/.
早上客户打电话给我说.网站打不开了..本以为是很简单的问题.结果看了客户发来的网站,发现打不开,但是SSH可以登陆上去,于是常规排除:
1:关闭防火墙
service iptables stop //关闭防火墙
2:重启Apache
service httpd restart
报错
Syntax error on line 94 of /usr/local/apache/conf/httpd.conf: DocumentRoot must be a directory httpd not running, trying to start
3:重启MySQL
service mysqld restart
提示
mysqld: unrecognized service
一看这个错误..立马吓一跳,mysql服务居然没有了.查系统日志,发现几行命令:
990 ls 991 tar -zxvf xxx_cn.tar.gz 992 ls 993 wget http://amysql.com/file/AMH/4.2/amh.sh 994 chmod 775 amh.sh 995 ./amh.sh 2>&1 | tee amh.log 996 amh info 997 amh ftp 998 wget http://amysql.com/file/AMH/4.2/amh.sh 999 chmod 775 amh.sh 1000 ./amh.sh 2>&1 | tee amh.log
一看这里不对劲.因为客户基本上不可能会配置这个AMH,于是到usr/local/目录,发现mysql目录不见了.接着到home目录,
发现wwwroot不见了..个狗日的,好狠.两个文件夹直接删光了.查询半天无果,只好着手开始恢复.
恢复数据.首先想到两款软件extundelete和ext3grep
最开始我尝试ext3grep,发现找回来全是一堆乱码文件..折腾半天未果.不过这也更加确信了数据是被人为删除的结论
截下来尝试extundelete.
1:安装前准备,先安装依赖环境
yum install gcc gcc-c++ gcc-g77
2:安装e2fsprogs
yum install e2fsprogs* -y
3:下载文件安装包
wget http://nchc.dl.sourceforge.net/project/extundelete/extundelete/0.2.4/extundelete-0.2.4.tar.bz2
4:解压文件
bunzip2 extundelete-0.2.4.tar.bz2 ls tar xvf extundelete-0.2.4.tar cd extundelete-0.2.4
5:编译和安装
cd extundelete-0.2.4 ./configure make make install
成功之后查看extundelete版本
[root@MyCloudServer ~]# extundelete -v extundelete version 0.2.4 libext2fs version 1.41.12 Processor is little endian.
之后着手数据恢复,查看挂载详情:
[root@MyVPS3251 ~]# df -hal Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 9.3G 5.6G 3.3G 63% / proc 0 0 0 - /proc sysfs 0 0 0 - /sys devpts 0 0 0 - /dev/pts /dev/xvda1 99M 29M 66M 31% /boot tmpfs 513M 32K 513M 1% /dev/shm /dev/xvdb1 30G 422M 28G 2% /home none 0 0 0 - /proc/sys/fs/binfmt_misc sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs
将/home卸载
fuser -k /home umount /home
之后执行恢复.我是直接挂载了一块新的虚拟硬盘进行数据恢复
所以直接cd到新的硬盘挂载目录执行:
extundelete /dev/VolGroup00/LogVol00 --restore-all [root@MyCloudServer cc]# extundelete /dev/VolGroup00/LogVol00 --restore-all NOTICE: Extended attributes are not restored. Loading filesystem metadata ... 77 groups loaded. Loading journal descriptors ... 31226 descriptors loaded. Searching for recoverable inodes in directory / ... 68 recoverable inodes found. Looking through the directory structure for deleted files ... Unable to restore inode 1967279 (etc/.ins.conf): Space has been reallocated. Unable to restore inode 1967278 (etc/mtab~9471): Space has been reallocated.
完成之后在目录下面会生成一个RECOVERED_FILES文件夹.进去之后发现wwwroot的文件已经恢复.
这是最简单的方法.之前使用ext3grep恢复浪费了大量的时间去查找Inode,结果毛都没恢复出来一根
接着需要恢复/usr/local/下面的文件.这里比较麻烦.老机器是LVM逻辑卷,不能直接挂载.所以比较麻烦
首先将老机器的硬盘卸载掉.重新开通一台新的VPS,系统不要与老的一样(老的是centos5 32bit,新的我开通为centos 6 64bit)
之后将硬盘挂载到新的VPS中.
之后登陆上新的VPS,扫描卷:
[root@MyCloudServer ~]# vgscan Reading all physical volumes. This may take a while... Found volume group "VolGroup00" using metadata type lvm2 Found volume group "vg_have" using metadata type lvm2 [root@MyCloudServer ~]#
激活卷
[root@MyCloudServer home]# vgchange --available y VolGroup00 2 logical volume(s) in volume group "VolGroup00" now active [root@MyCloudServer home]#
开始扫描文件:
extundelete /dev/VolGroup00/LogVol00 --restore-all
不过遗憾的是,数据库没办法恢复回来.可能是因为AMH编译的缘故.已经覆盖掉的文件,所以无法找回了..
在此提醒各位.注意备份好自己的数据库.详情参见:每日备份mysql到网站目录
xtundelete /dev/partition --restore-all //恢复磁盘所有文件 extundelete /dev/partition --restore-directory /backup/gnutool-delete //恢复单个目录 extundelete /dev/partition --restore-files /etc/passwd //恢复单个文件
PS:文章属于原创,转载请注明出处.