xfsdump、xfsrestore备份恢复

感情迁移 提交于 2020-04-06 20:49:43

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的文件系统。

xfsrestore    -f    恢复文件的位置     存放恢复后文件的路径

测试实例

前期准备

1、准备测试分区

vm虚拟机添加一块盘,格式化、分区

[root@master ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x6af1f974.

Command (m for help): n
Partition number (1-128, default 1): 1
First sector (2048-41943006, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943006, default 41943006): +10G           
Created partition 1

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt
Disk identifier: CFF6D029-AE1C-4D43-8673-34243A25651C


#         Start          End    Size  Type            Name
 1         2048     20973567     10G  Linux filesyste 

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

Calling ioctl() to re-read partition table.
Syncing disks.

创建文件系统,挂载

[root@master ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=655360 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2621440, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

[root@master ~]# mkdir /mnt/xfs/

[root@master ~]# mount -t xfs /dev/sdb1 /mnt/xfs
[root@master ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        901M     0  901M   0% /dev
tmpfs           911M     0  911M   0% /dev/shm
tmpfs           911M  9.6M  902M   2% /run
tmpfs           911M     0  911M   0% /sys/fs/cgroup
/dev/sda3        98G  2.0G   96G   3% /
/dev/sda1      1014M  135M  880M  14% /boot
tmpfs           183M     0  183M   0% /run/user/0
/dev/sdb1        10G   33M   10G   1% /mnt/xfs

安装软件、创建文件

[root@master ~]# echo "1234" >> /mnt/xfs/num.txt
[root@master ~]# mkdir /mnt/xfs/test
[root@master ~]# echo "test" >> /mnt/xfs/test/num.txt
[root@master ~]# yum install -y xfsdump
Loaded plugins: fastestmirror

备份数据

[root@master ~]# xfsdump -f /backup/dump_sdb1 /dev/sdb1 
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (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 master:/mnt/xfs
xfsdump: dump date: Mon Apr  6 02:39:40 2020
xfsdump: session id: c378e1cd-7b83-4082-8c9e-23b81846a2f5
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: 29952 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 24056 bytes
xfsdump: dump size (non-dir files) : 1088 bytes
xfsdump: dump complete: 38 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /backup/dump_sdb1 OK (success)
xfsdump: Dump Status: SUCCESS

查看备份信息

[root@master ~]# xfsdump -I
file system 0:
    fs id:        3c9dc4de-31ff-4092-8540-d8eae0b2c1d3
    session 0:
        mount point:    master:/mnt/xfs
        device:        master:/dev/sdb1
        time:        Mon Apr  6 02:39:40 2020
        session label:    "dump_sdb1"
        session id:    c378e1cd-7b83-4082-8c9e-23b81846a2f5
        level:        0
        resumed:    NO
        subtree:    NO
        streams:    1
        stream 0:
            pathname:    /backup/dump_sdb1
            start:        ino 67 offset 0
            end:        ino 70 offset 0
            interrupted:    NO
            media files:    1
            media file 0:
                mfile index:    0
                mfile type:    data
                mfile size:    24056
                mfile start:    ino 67 offset 0
                mfile end:    ino 70 offset 0
                media label:    "sdb1"
                media id:    32613bce-0fb1-4fd5-bd81-2166246de691
xfsdump: Dump Status: SUCCESS

模拟误删除数据

[root@master ~]# rm -f /mnt/xfs/* -r
[root@master ~]# ll /mnt/xfs/
total 0

恢复文件

[root@master ~]# xfsrestore -f /backup/dump_sdb1 /mnt/xfs
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.7 (dump format 3.0) - type ^C for status and control
xfsrestore: searching media for dump
xfsrestore: examining media file 0
xfsrestore: dump description: 
xfsrestore: hostname: master
xfsrestore: mount point: /mnt/xfs
xfsrestore: volume: /dev/sdb1
xfsrestore: session time: Mon Apr  6 02:39:40 2020
xfsrestore: level: 0
xfsrestore: session label: "dump_sdb1"
xfsrestore: media label: "sdb1"
xfsrestore: file system id: 3c9dc4de-31ff-4092-8540-d8eae0b2c1d3
xfsrestore: session id: c378e1cd-7b83-4082-8c9e-23b81846a2f5
xfsrestore: media id: 32613bce-0fb1-4fd5-bd81-2166246de691
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 2 directories and 3 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore:   stream 0 /backup/dump_sdb1 OK (success)
xfsrestore: Restore Status: SUCCESS

[root@master ~]# ll /mnt/xfs/
num.txt  test/    
[root@master ~]# ll /mnt/xfs/test/
total 4
-rw-r--r--. 1 root root 5 Apr  6 02:35 num.txt

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!