暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

企业误删文件恢复实战

原创 手机用户4903 2022-08-15
361

[root@itlaoxin63 ~]# rm -Rf / #执行不成功的, rm: 在"/" 进行递归操作十分危险

rm: 使用 --no-preserve-root 选项跳过安全模式[root@itlaoxin63 ~]# rm -rf /* #这个可以执行成功。

企业删除文件规范:

删除一个文件的规范1) 不要使用 rf

  1. 不要使用通配符
  2. 先移动文件到一个目录,过段时间再删除。
  3. 每次删除文件发邮件确认要删除的内容没有其他部门在使用

ext4 文件系统上删除文件,可以恢复: extundelete ,ext3 恢复使用:ext3grep windows 恢复误删除的文件: final data v2.0 汉化版 和 easyrecovery

扩展:

Linux 文件系统由三部分组成:文件名,inode,block windows 也由这三部分组成。

a.txt -->inode --> block

文件名 存放文件元数据信息 真正存放数据查看文件文件名:

[root@itlaoxin63 ~]# cp /etc/passwd a.txt [root@itlaoxin63 ~]# ls a.txt

a.txt

查看 inode 号:

常识: 每个文件,有一个 inode 号。[root@itlaoxin63 ~]# ls -i a.txt 440266 a.txt

查看 inode 中的文件属性; 通过 stat 命令查看 inode 中包含的内容[root@itlaoxin63 ~]# stat a.txt # 查 看 inode 信 息 : [root@itlaoxin63 ~]# ls -l a.txt

-rw-r--r-- 1 root root 1720 Oct 25 10:21 a.txt

block 块:真正存储数据的地方逻辑删除:

为什么删除比复制快?

误删除文件后,第一件事要做什么??? 你不心删除把存了几十年的大片删除了。避免误删除的文件内容被覆盖。 如何避免?

卸载需要恢复文件的分区或以只读的方式挂载

实战:在 ext4 文件系统上恢复被误删除的文件下载 extundelete

http://sourceforge.net/ 开源软件发布中心准备测试分区:

[root@itlaoxin63 /]# fdisk /dev/sdb #创建一个 sdb1 分区

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u').

Command (m for help): p #查看现有分区表

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000b8b35

Device Boot Start End Blocks Id System

/dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary.

/dev/sda2

26

1301

10240000

83

Linux

/dev/sda3

1301

1428

1024000

82

Linux swap / Solaris

Command (m for help): n #创建一个新分区Command action

e extended

p primary partition (1-4) p #创建一个主分区

Selected partition 4

First cylinder (1428-2610, default 1428):

Using default value 1428

Last cylinder, +cylinders or +size{K,M,G} (1428-2610, default 2610): +1G #指定分区大小

Command (m for help): w # 保 存The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.

[root@itlaoxin63 ~]#reboot

[root@itlaoxin63 ~]# partx -a /dev/sdb #获得新分区表

使用新的分区表:

[root@itlaoxin63 /]# mkdir /tmp/sdb1 #创建挂载点[root@itlaoxin63 ~]# mkfs.ext4 /dev/sdb1 #格式化[root@itlaoxin63 ~]# mount /dev/sdb1 /tmp/sdb1/ #挂载

      1. 复制一些测试文件,然后把这些文件再删除,然后演示恢复: [root@itlaoxin63 ~]# cp /etc/passwd /tmp/sdb1/ [root@itlaoxin63 ~]# cp /etc/hosts /tmp/sdb1/ [root@itlaoxin63 ~]# echo aaa > a.txt

[root@itlaoxin63 ~]# mkdir -p /tmp/sdb1/a/b/c [root@itlaoxin63 ~]# cp a.txt /tmp/sdb1/a/ [root@itlaoxin63 ~]# cp a.txt /tmp/sdb1/a/b/ [root@itlaoxin63 ~]# touch /tmp/sdb1/a/b/kong.txt 安装 tree 命令:

[root@itlaoxin63 ~]# rpm -ivh /mnt/Packages/tree-1.5.3-2.el6.x86_64.rpm [root@itlaoxin63 ~]# tree /tmp/sdb1/

/tmp/sdb1/

├── a

│ ├── a.txt

│ └── b

│ ├── a.txt

│ ├── c # 空 目 录

│ └── kong.txt # 空 文 件

├── hosts

├── lost+found

└── passwd

删除文件:

[root@itlaoxin63 ~]# cd /tmp/sdb1/ [root@itlaoxin63 sdb1]# ls

a hosts lost+found passwd [root@itlaoxin63 sdb1]# rm -rf a hosts passwd

误删除文件后,第一件事要做什么??? 如何避免误删除的文件内容被覆盖???

卸载需要恢复文件的分区:或以只读的方式挂载[root@localhost ~]#cd /root [root@localhost ~]# umount /tmp/sdb1

      1. 安装 extundelet

上传 extundelete 到linux 中:

从 windows 上传 extundelete 文件到 linux,安装 xmanager v5 或者CRT

[root@itlaoxin63 ~]# rpm -ivh /mnt/Packages/lrzsz-0.12.20-27.1.el6.x86_64.rpm 安装后,就有了rz命令和sz命令 需要 xshell 连接上

rz : 上传 windows 中的文件到 linux sz :下载,将 linux 中的文件传到 windows

解压并安装 extundelet

[root@itlaoxin63 extundelete-0.2.4]# tar jxvf extundelete-0.2.4.tar.bz2 [root@itlaoxin63 ~]# cd extundelete-0.2.4

[root@itlaoxin63]# yum install e2fsprogs-devel

[root@itlaoxin63 extundelete-0.2.4]# ./configure #检查系统安装环境Echo $?

[root@itlaoxin63 extundelete-0.2.4]# make -j 4 #编译,把源代码编译成可执行的二进制文件。

-j 4 使用 4 进程同时编译,提升编译速度 或 使用 4 核CPU 同时编译。[root@itlaoxin63 extundelete-0.2.4]# make install # 安 装

      1. 开始恢复:

方法 1:通过 inode 结点恢复方法二:通过文件名恢复

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

[root@itlaoxin63 ~]# umount /tmp/sdb1/

[root@itlaoxin63 ~]# mkdir test #创建一个目录使用于存放恢复的数据[root@itlaoxin63 ~]# cd test/

方法 1:

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

[root@itlaoxin63 test]# extundelete /dev/sdb1 --inode 2

.

2

lost+found

11

passwd

12

Deleted

hosts

13

Deleted

a

7313

Deleted

扩展:ext4 文件系统的分区根目录的 inode 值为 2,xfs 分区根目录的inode 值为 64

方法 1:通过 inode 结点恢复

[root@itlaoxin63 test]# extundelete /dev/sdb1 --restore-inode 12 NOTICE: Extended attributes are not restored.

Loading filesystem metadata ... 9 groups loaded. Loading journal descriptors ... 63 descriptors loaded. [root@itlaoxin63 test]# ls

RECOVERED_FILES

[root@itlaoxin63 test]# diff /etc/passwd RECOVERED_FILES/file.12 # 没有任何输出,说明一样

方法二,通过文件名恢复

[root@itlaoxin63 test]# extundelete /dev/sdb1 --restore-file passwd

[root@itlaoxin63 test]# diff /etc/passwd RECOVERED_FILES/passwd # 没有任何输出,说明一样

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

[root@itlaoxin63 test]# extundelete /dev/sdb1 --restore-directory a [root@localhost ~]# tree RECOVERED_FILES/

RECOVERED_FILES/

├── a

│ ├── a.txt

│ └── b

│ └── a.txt

├── file.12

└── hosts

下面是原来的目录结构:

[root@itlaoxin63 ~]# tree /root/sdb1-back/a/

/root/sdb1-back/a/

├── a.txt

└── b

├── a.txt

├── c

└── kong.txt

方法四:恢复所有的文件

[root@itlaoxin63 test]# extundelete /dev/sdb1 --restore-all 删除前后的数据:

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论