Centos6 模拟ext4文件系统误删除数据后恢复流程

前言:

Extundelete 数据恢复

       “rm -rf /*” 是我们经常使用的命令,操作不慎全盘接蹦,从删库到跑路,身为过来人的我们都经历过rm带来的痛苦。

不要慌,当我们有了Extundelete就可以解决一系列误删除操作问题。下面我会详细介绍一下这款救命工具。

      inux文件系统由三部分组成: 文件名 inode(存放文件元数据信息) block(真正存储数据的地方) .

当误删文件之后要想通过Extundelete进行数据恢复,首先我们要禁止写入(卸载或者给只读权限)。

注意ext4文件系统空文件空目录会被默认为无用的都不会恢复

演示开始

第一步:创建一个新的硬盘,分区、挂载、格式化

创建20G硬盘重启系统,加载新的硬盘  

这里有个新技术 热拔插:功能就是允许用户在不关闭系统,不切断电源的情况下取出和更换损坏的硬盘、电源或板卡等部件,从而提高了系统对灾难的及时恢复能力、扩展性和灵活性等,例如一些面向高端应用的磁盘镜像系统都可以提供磁盘的热插拔功能。

[root@localhost ~]# fdisk -l    查看硬盘
[root@localhost ~]# fdisk /dev/sdb     进行分区
Command (m for help): n       创建一个分区
Command action
   e   extended
   p   primary partition (1-4)
p         创建一个主分区
Partition number (1-4): 1      主分区1 sdb1
First cylinder (1-2610, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +3G   给他分了3G
Command (m for help): p     查看已分的区
Command (m for help): w     保存退出
[root@localhost ~]# ll /dev/sdb*    查看刚才分好的区
brw-rw----. 1 root disk 8, 16 4月  17 20:47 /dev/sdb
brw-rw----. 1 root disk 8, 17 4月  17 20:47 /dev/sdb1
[root@localhost ~]# mkfs.ext4 /dev/sdb1   格式化sdb1这个分区
[root@localhost ~]# mkdir /sdb1    创建一个挂载点
[root@localhost ~]# mount /dev/sdb1 /sdb1    把sdb1这个分区挂载到/sdb1

 第二步:在上面的分区创建测试文件、然后删除(当误删除文件后需要卸载或者给只读权限

[root@localhost ~]# cd /sdb1/
[root@localhost sdb1]# df -h
/dev/sda1                     485M   35M  426M   8% /boot
/dev/sdb1                     3.0G   69M  2.8G   3% /sdb1
[root@localhost sdb1]# cp /etc/passwd ./       创建以下三个测试文件
[root@localhost sdb1]# cp /etc/hosts ./
[root@localhost sdb1]# echo "welcome to liunx" > a.txt
[root@localhost sdb1]# ls     查看创建是否成功
a.txt  hosts  lost+found  passwd
[root@localhost sdb1]# rm -rf ./*   删除当前目录下所有文件

[root@localhost sdb1]# umount /dev/sdb1  出现这种报错需要退出当前位置
umount: /sdb1: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
[root@localhost ~]# umount /dev/sdb1    这个位置就可以卸载掉了

第三步:上传Extundelete包进行安装

[root@localhost src]# ls
extundelete-0.2.4.zip
[root@localhost src]# unzip extundelete-0.2.4.zip
[root@localhost src]# cd extundelete-0.2.4    一般情况安装步骤都在README中,我们可以查看
[root@localhost extundelete-0.2.4]# ./configure
-bash: ./configure: 权限不够
[root@localhost extundelete-0.2.4]# chmod -R 777 ./*   然后我们给了个权限

[root@localhost extundelete-0.2.4]# ./configure   又发现了报错
Configuring extundelete 0.2.4
configure: error: in `/usr/local/src/extundelete-0.2.4':
configure: error: C++ compiler cannot create executables
See `config.log' for more details
[root@localhost extundelete-0.2.4]# yum -y install gcc*  我们先把软件按上

[root@localhost extundelete-0.2.4]# ./configure   又报了没有发现这个库的错
Configuring extundelete 0.2.4
configure: error: Can't find ext2fs library

[root@localhost extundelete-0.2.4]# yum -y install *2fs*  把所有相似的包全安装上
[root@localhost extundelete-0.2.4]# ./configure   这样就成功了
Configuring extundelete 0.2.4
Writing generated files to disk

[root@localhost extundelete-0.2.4]# make -j 4  使用四核同时编译
make -s all-recursive
Making all in src
extundelete.cc:571: 警告:未使用的参数‘flags’     这里出现报错我们可以通过$? 确定这步是否成功
[root@localhost extundelete-0.2.4]# echo $?     值为0的话说明我们上步没有问题,可以不用管
0
[root@localhost extundelete-0.2.4]# make install
Making install in src
  /usr/bin/install -c extundelete '/usr/local/bin'
[root@localhost extundelete-0.2.4]# echo $?     安装成功
0

第四步:使用extundelete  进行文件的恢复

[root@localhost ~]# mkdir /huifu   创建一个目录把文件恢复到这个目录
[root@localhost ~]# cd /huifu/
[root@localhost huifu]# extundelete /dev/sdb1 --inode 2  查看inode号
[root@localhost huifu]# extundelete /dev/sdb1 --restore-inode 12   基于inode号恢复
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 25 groups loaded.
Loading journal descriptors ... 41 descriptors loaded.
[root@localhost huifu]# ls    会出现这样一个目录恢复的文件就在里面
RECOVERED_FILES
[root@localhost huifu]# cd RECOVERED_FILES/
[root@localhost RECOVERED_FILES]# ls
file.12
[root@localhost RECOVERED_FILES]# md5sum /etc/passwd file.12  通过校验我们发现与原始文件一样
cac49cd2097a2c38bb91af1f7ebc1250  /etc/passwd
cac49cd2097a2c38bb91af1f7ebc1250  file.12

[root@localhost huifu]# extundelete /dev/sdb1 --restore-file passwd   通过文件名恢复
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 25 groups loaded.
Loading journal descriptors ... 41 descriptors loaded.
Successfully restored file passwd

[root@localhost huifu]# extundelete /dev/sdb1 --restore-all   恢复所有文件

注意#ext4文件系统空文件空目录会被默认为无用的都不会恢复
extundelte /dev/sdxx/ --restore-file 文件名
extundelte /dev/sdxx/ --restore-inode inode号
extundelte /dev/sdxx/ --restore-directory 目录名
extundelte /dev/sdxx/ --restore-all 所有

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

胖胖不胖、

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值