9.恢复删除的内容。
[root@localhost ~]# extundelete /dev/sdb1 --restore-all NOTICE: Extended attributes are not restored. Loading filesystem metadata ... 160 groups loaded. Loading journal descriptors ... 24 descriptors loaded. Searching for recoverable inodes in directory / ... 2 recoverable inodes found. Looking through the directory structure for deleted files ... 0 recoverable inodes still lost.10.恢复的文件会在在当前目录下的RECOVERED_FILES文件夹内。
[root@localhost ~]# ls RECOVERED_FILES/ a b XFS 类型文件备份和恢复#extundelete工具仅可以恢复EXT类型的文件,无法恢复CentOS 7系统默认采用xfs类型的文件。针对xfs文件系统目前也没有比较成熟的文件恢复工具,所以建议提前做好数据备份,以避免数据丢失。
xfs类型的文件可使用xfsdump与xfsrestore工具进行备份恢复。若系统中未安装xfsdump与xfsrestore工具,可以通过yum install -y xfsdump命令安装。xfsdump按照inode顺序备份一个xfs文件系统。
xfsdump的备份级别有两种:0表示完全备份;1-9表示增量备份。默认为0。
xfsdump -f 备份存放位置 要备份路径或设备文件-f:指定备份文件目录
-L:指定标签session label
-M:指定设备标签media label
-s:备份单个文件,-s后面不能直接跟路径。
使用xfsdump时,需要注意以下的几个限制:
1.xfsdump不支持没有挂载的文件系统备份,所以只能备份已挂载的;
2.xfsdump必须使用root的权限才能操作(涉及文件系统的关系);
3.xfsdump只能备份XFS文件系统;
4.xfsdump备份下来的数据(档案或储存媒体)只能让xfsrestore解析;
5.xfsdump是透过文件系统的UUID来分辨各个备份档的,因此不能备份两个具有相同UUID的文件系统。
1.准备好用于测试的分区,/dev/sdb1为ext4格式,挂载到/mnt/ext4目录下。
[root@localhost ~]# mkdir /mnt/xfs [root@localhost ~]# mount /dev/sdb1 /mnt/xfs/ [root@localhost ~]# df -hT /mnt/xfs/ Filesystem Type Size Used Avail Use% Mounted on /dev/sdb1 xfs 20G 33M 20G 1% /mnt/xfs2.创建测试文件。
[root@localhost ~]# cd /mnt/xfs/ [root@localhost xfs]# mkdir test [root@localhost xfs]# touch a.txt [root@localhost xfs]# touch test/b.txt3.可以使用tree查看目录结构。
[root@localhost ~]# yum install tree -y [root@localhost ~]# tree /mnt/xfs/ /mnt/xfs/ ├── a.txt └── test └── b.txt 1 directory, 2 files4.使用xfsdump命令备份整个分区。
[root@localhost ~]# xfsdump -f /opt/dump_sdb1 /dev/sdb1 xfsdump: using file dump (drive_simple) strategy xfsdump: version 3.1.4 (dump format 3.0) - type ^C for status and control ============================= dump label dialog ============================== please enter label for this dump session (timeout in 300 sec) -> dump_sdb1 //指定备份会话标签 session label entered: "dump_sdb1" --------------------------------- end dialog --------------------------------- xfsdump: level 0 dump of localhost.localdomain:/mnt/xfs xfsdump: dump date: Fri Sep 6 13:36:12 2019 xfsdump: session id: 74232f85-124c-4486-8d91-f35208534f74 xfsdump: session label: "dump_sdb1" xfsdump: ino map phase 1: constructing initial dump list xfsdump: ino map phase 2: skipping (no pruning necessary) xfsdump: ino map phase 3: skipping (only one dump stream) xfsdump: ino map construction complete xfsdump: estimated dump size: 21760 bytes xfsdump: /var/lib/xfsdump/inventory created ============================= media label dialog ============================= please enter label for media in drive 0 (timeout in 300 sec) -> sdb1 //指定设备标签,就是对要备份的设备做一个描述 media label entered: "sdb1" --------------------------------- end dialog --------------------------------- xfsdump: creating dump session media file 0 (media 0, file 0) xfsdump: dumping ino map xfsdump: dumping directories xfsdump: dumping non-directory files xfsdump: ending media file xfsdump: media file size 22952 bytes xfsdump: dump size (non-dir files) : 0 bytes xfsdump: dump complete: 46 seconds elapsed xfsdump: Dump Summary: xfsdump: stream 0 /opt/dump_sdb1 OK (success) xfsdump: Dump Status: SUCCESS5.查看备份信息与内容。
[root@localhost ~]# xfsdump -I file system 0: fs id: f8805a3e-089e-4875-ad54-d31e5dc98835 session 0: mount point: localhost.localdomain:/mnt/xfs device: localhost.localdomain:/dev/sdb1 time: Fri Sep 6 13:36:12 2019 session label: "dump_sdb1" session id: 74232f85-124c-4486-8d91-f35208534f74 level: 0 resumed: NO subtree: NO streams: 1 stream 0: pathname: /opt/dump_sdb1 start: ino 68 offset 0 end: ino 70 offset 0 interrupted: NO media files: 1 media file 0: mfile index: 0 mfile type: data mfile size: 22952 mfile start: ino 68 offset 0 mfile end: ino 70 offset 0 media label: "sdb1" media id: cc32446f-42e8-489b-867f-84a55949c1fa xfsdump: Dump Status: SUCCESS6.删除创建的测试文件,模拟数据丢失。
[root@localhost ~]# rm -rf /mnt/xfs/* [root@localhost ~]# tree /mnt/xfs/ /mnt/xfs/ 0 directories, 0 files