阿汤博客-承接中小企业服务器维护和网站维护,有意者可以联系博主!

恢复Linux下被误删除的文件

运维维护 214℃ 0评论

[[email protected] ~]# mount /dev/cdrom /mnt/

分一个区:sda4

查找:extundelete

分一个区:sda4

[[email protected] ~]# mkdir /tmp/sda4

[[email protected] ~]# mkfs.ext4 /dev/sda4 格式化

[[email protected] Desktop]# echo $?

0

[[email protected] ~]# mount /dev/sda4 /tmp/sda4/

[[email protected] ~]# df -Th #查看磁盘相关信息

[[email protected] Desktop]# mount /dev/sda4 /tmp/sda4

[[email protected] Desktop]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda2 9.7G 3.8G 5.5G 41% /

tmpfs 569M 264K 569M 1% /dev/shm

/dev/sda1 194M 28M 157M 15% /boot

/dev/sr0 3.4G 3.4G 0 100% /mnt

/dev/sda4 1012M 34M 928M 4% /tmp/sda4

复制一些用于测试删除的文件:

[[email protected] ~]# cp /etc/passwd /tmp/sda4/

[[email protected] ~]# cp /etc/hosts /tmp/sda4/

[[email protected] ~]# vim /tmp/sda4/a.txt #vim编辑a.txt 随便写入一些数据。

[[email protected] ~]# mkdir -p /tmp/sda4/a/b/c

[[email protected] ~]# cp /tmp/sda4/a.txt /tmp/sda4/a

[[email protected] ~]# cp /tmp/sda4/a.txt /tmp/sda4/a/b/

删除:

[[email protected]  ~]# mkdir /tmp/back

[[email protected] ~]# cp -r /tmp/sda4/* /tmp/back

[[email protected] ~]# cd /tmp/sda4/

[[email protected] ~]# rm -rf passwd hosts a a.txt

[[email protected] ~]# ls /tmp/sda4/

lost+found


卸载需要恢复文件的分区: inode

[[email protected] sda4]# cd

[[email protected] ~]# umount /tmp/sda4/

安装软件 extundelete

[[email protected] ~]# tar jxvf extundelete-0.2.4.tar.bz2

[[email protected] ~]# cd extundelete-0.2.4

[[email protected] extundelete-0.2.4]# ./configure

Configuring extundelete 0.2.4

configure: error: Can't find ext2fs library #报错

[[email protected] ~]# mount /dev/cdrom /mnt/

[[email protected] extundelete-0.2.4]# rpm -ivh /mnt/Packages/e2fsprogs-devel-1.41.12-11.el6.x86_64.rpm

[[email protected] extundelete-0.2.4]#

[[email protected] extundelete-0.2.4]# ./configure #检查安装环境并生成Makefile

[[email protected]  extundelete-0.2.4]# make #编译

[[email protected] extundelete-0.2.4]# make install #安装

开始恢复:

方法1:

通过inode结点查看被删除的文件名字:

[[email protected] ~]# mkdir test

[[email protected] ~]# cd test/

[[email protected] ~]# extundelete /dev/sda4 –inode 2

。。。

lost+found                11

passwd                      12                  Deleted

hosts                         13                  Deleted

a                               8193              Deleted

a.txt                          15                 Deleted

通过inode节点来恢复:

[[email protected] ~]# extundelete /dev/sda4 –restore-inode 12

NOTICE: Extended attributes are not restored.

Loading filesystem metadata … 16 groups loaded.

Loading journal descriptors … 32 descriptors loaded.

[[email protected] ~]# ls RECOVERED_FILES/ #恢复成功

file.12

[[email protected]  test]# diff /etc/passwd /root/test/RECOVERED_FILES/file.12

方法二,通过文件名恢复

恢复某个文件:

[[email protected] test]# rm -rf RECOVERED_FILES/

[[email protected] ~]# extundelete /dev/sda4 –restore-file passwd

恢复某个目录,如目录a下的所有文件:

[[email protected] ~]# extundelete /dev/sda4 –restore-directory a #恢复目录a 

恢复所有的文件

[[email protected] ~]# extundelete /dev/sda4 –restore-all

使用心得:

空目录或空文件恢复不成功。

转载请注明:阿汤博客 » 恢复Linux下被误删除的文件

喜欢 (0)or分享 (0)