XFS文件系统的备份与恢复

xfs提供了xfsdump和xfsrestore工具协助xfs文件系统中的数据

xfs不需要再备份的时候进行卸载,可以保持镜像的一致性,xfs在恢复中终端是可以继续的,无需冻结文件系统。xfsdump还提供了多线程。

xfsdump备份级别

0:完全备份

1-9:增量备份

完全备份:每次备份都把指定的备份目录复制一遍,不管目录是否有文件变化

增量备份:每次将之前做过备份之后有变化的文件进行备份

差异备份:每次将第一次完整备份以来有变化的文件进行备份

备份

没有xfsdump命令可以使用yum进行安装

[root@master ~]# yum install xfsdump -y

xfsdump -f 备份存放位置 需要备份路径或设备文件

备份路径可以是/dev/sdb1或者是/sdb1,不能是/sdb1/

案例:

备份/dev/sdb1分区

 [root@master ~]# xfsdump -f  /opt/dump_sdb /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_sdb  //输入备份后保存的名字
 session label entered: "dump_sdb"
 --------------------------------- end dialog ---------------------------------
 xfsdump: level 0 dump of master:/data
 xfsdump: dump date: Mon Sep  9 15:07:41 2019
 xfsdump: session id: dfbd9cf7-337b-4fb1-9f72-24483ba7e635
 xfsdump: session label: "dump_sdb"
 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: 22720 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 22880 bytes
 xfsdump: dump size (non-dir files) : 0 bytes
 xfsdump: dump complete: 37 seconds elapsed
 xfsdump: Dump Summary:
 xfsdump:   stream 0 /opt/dump_sdb OK (success)
 xfsdump: Dump Status: SUCCESS

查看备份的文件

[root@master ~]# ll /opt/
 总用量 24
 -rw-r--r-- 1 root root 22880 9月   9 15:08 dump_sdb

指定备份免交互操作

[root@master opt]# xfsdump -f /opt/dump_passwd /dev/sdb1 -L dump_passwd -M sdb1
 xfsdump: using file dump (drive_simple) strategy
 xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control
 xfsdump: level 0 dump of master:/data
 xfsdump: dump date: Mon Sep  9 15:20:27 2019
 xfsdump: session id: 26b9735a-37d5-4707-b042-2f97fd712125
 xfsdump: session label: "dump_passwd"
 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: 22720 bytes
 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 22880 bytes
 xfsdump: dump size (non-dir files) : 0 bytes
 xfsdump: dump complete: 0 seconds elapsed
 xfsdump: Dump Summary:
 xfsdump:   stream 0 /opt/dump_passwd OK (success)
 xfsdump: Dump Status: SUCCESS

指定备份分区中的某个目录

[root@master data]# xfsdump -f /opt/dump_grub2 -s grub2/grub.cfg /boot -L dump_grub2 -M boot-sda1
 xfsdump: using file dump (drive_simple) strategy
 xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control
 xfsdump: level 0 dump of master:/boot
 xfsdump: dump date: Mon Sep  9 15:35:24 2019
 xfsdump: session id: 922de0e9-ba17-4ca0-b5da-7dcd72180c27
 xfsdump: session label: "dump_grub2"
 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: 29632 bytes
 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 27936 bytes
 xfsdump: dump size (non-dir files) : 4640 bytes
 xfsdump: dump complete: 0 seconds elapsed
 xfsdump: Dump Summary:
 xfsdump:   stream 0 /opt/dump_grub2 OK (success)
 xfsdump: Dump Status: SUCCESS

查看备份信息和内容

[root@master data]# ls /var/lib/xfsdump/inventory/
 209d1533-0f86-4ef8-ae2d-6a00175b4758.InvIndex  61be573b-fa52-4684-af23-b635779a76e0.InvIndex  fstab
 5610774a-3a49-461b-b56e-c633e2300b44.StObj     6c6596a1-f58a-4d0f-81d2-64aa8e64dda9.StObj

查看备份信息

[root@master data]# xfsdump -I

恢复

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

案例

[root@master opt]# xfsrestore -f dump_sdb /data
 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: /data
 xfsrestore: volume: /dev/sdb1
 xfsrestore: session time: Mon Sep  9 15:07:41 2019
 xfsrestore: level: 0
 xfsrestore: session label: "dump_sdb"
 xfsrestore: media label: "sdb1"
 xfsrestore: file system id: 61be573b-fa52-4684-af23-b635779a76e0
 xfsrestore: session id: dfbd9cf7-337b-4fb1-9f72-24483ba7e635
 xfsrestore: media id: 7d7f8e34-f918-4061-9a94-c1d17f38dbbd
 xfsrestore: using online session inventory
 xfsrestore: searching media for directory dump
 xfsrestore: reading directories
 xfsrestore: 2 directories and 6 entries processed
 xfsrestore: directory post-processing
 xfsrestore: restoring non-directory files
 xfsrestore: restore complete: 0 seconds elapsed
 xfsrestore: Restore Summary:
 xfsrestore:   stream 0 /opt/dump_sdb OK (success)
 xfsrestore: Restore Status: SUCCESS

查看是否恢复

[root@master opt]# ls /data/wxj/
 file1  file2  file3  file4  file5

文件都已恢复

[root@master opt]# xfsrestore -f /opt/dump_grub2 -s grub2/grub.cfg /data/
 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: /boot
 xfsrestore: volume: /dev/sda1
 xfsrestore: session time: Mon Sep  9 15:35:24 2019
 xfsrestore: level: 0
 xfsrestore: session label: "dump_grub2"
 xfsrestore: media label: "boot-sda1"
 xfsrestore: file system id: 209d1533-0f86-4ef8-ae2d-6a00175b4758
 xfsrestore: session id: 922de0e9-ba17-4ca0-b5da-7dcd72180c27
 xfsrestore: media id: df6efe5d-d32d-4a92-a2d6-224302e05621
 xfsrestore: using online session inventory
 xfsrestore: searching media for directory dump
 xfsrestore: reading directories
 xfsrestore: 2 directories and 17 entries processed
 xfsrestore: directory post-processing
 xfsrestore: restoring non-directory files
 xfsrestore: restore complete: 0 seconds elapsed
 xfsrestore: Restore Summary:
 xfsrestore:   stream 0 /opt/dump_grub2 OK (success)
 xfsrestore: Restore Status: SUCCESS
 [root@master opt]# ls /data/
 grub2  wxj

增量备份

备份快、恢复慢

做一个等级为1的增量备份

[root@master data]# xfsdump -l 1 -f  /opt/test-back1 /dev/sdb1 -L test-back1 -M media0
 xfsdump: using file dump (drive_simple) strategy
 xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control
 xfsdump: level 1 incremental dump of master:/data based on level 0 dump begun Mon Sep  9 15:54:36 2019
 xfsdump: dump date: Mon Sep  9 15:58:17 2019
 xfsdump: session id: c6bd99f2-37bf-4b38-9e05-1547a9d9a81f
 xfsdump: session label: "test-back1"
 xfsdump: ino map phase 1: constructing initial dump list
 xfsdump: ino map phase 2: pruning unneeded subtrees
 xfsdump: ino map phase 3: skipping (only one dump stream)
 xfsdump: ino map construction complete
 xfsdump: estimated dump size: 21440 bytes
 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 22032 bytes
 xfsdump: dump size (non-dir files) : 0 bytes
 xfsdump: dump complete: 0 seconds elapsed
 xfsdump: Dump Summary:
 xfsdump:   stream 0 /opt/test-back1 OK (success)
 xfsdump: Dump Status: SUCCESS
[root@master data]# xfsdump -l 2 -f  /opt/test-back2 /dev/sdb1 -L test-back2 -M media0
 xfsdump: using file dump (drive_simple) strategy
 xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control
 xfsdump: level 2 incremental dump of master:/data based on level 1 dump begun Mon Sep  9 15:58:17 2019
 xfsdump: dump date: Mon Sep  9 16:01:28 2019
 xfsdump: session id: 6d0be7d6-3364-481f-b690-bf2aff6b1038
 xfsdump: session label: "test-back2"
 xfsdump: ino map phase 1: constructing initial dump list
 xfsdump: ino map phase 2: pruning unneeded subtrees
 xfsdump: ino map phase 3: skipping (only one dump stream)
 xfsdump: ino map construction complete
 xfsdump: estimated dump size: 21440 bytes
 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 22064 bytes
 xfsdump: dump size (non-dir files) : 0 bytes
 xfsdump: dump complete: 0 seconds elapsed
 xfsdump: Dump Summary:
 xfsdump:   stream 0 /opt/test-back2 OK (success)
 xfsdump: Dump Status: SUCCESS

增量恢复

1、先恢复全量备份

2、依次恢复等级从1开始的增量备份

恢复全量

[root@master opt]# xfsrestore -f test-full /data
 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: /data
 xfsrestore: volume: /dev/sdb1
 xfsrestore: session time: Mon Sep  9 15:54:36 2019
 xfsrestore: level: 0
 xfsrestore: session label: "test"
 xfsrestore: media label: "media0"
 xfsrestore: file system id: 61be573b-fa52-4684-af23-b635779a76e0
 xfsrestore: session id: b79b8f76-bac8-402d-9302-85ae3450e279
 xfsrestore: media id: fa685885-f775-451a-9938-e67fa7c6f1c2
 xfsrestore: using online session inventory
 xfsrestore: searching media for directory dump
 xfsrestore: reading directories
 xfsrestore: 4 directories and 10 entries processed
 xfsrestore: directory post-processing
 xfsrestore: restoring non-directory files
 xfsrestore: restore complete: 0 seconds elapsed
 xfsrestore: Restore Summary:
 xfsrestore:   stream 0 /opt/test-full OK (success)
 xfsrestore: Restore Status: SUCCESS
[root@master opt]# xfsrestore -f test-back1 /data
 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: /data
 xfsrestore: volume: /dev/sdb1
 xfsrestore: session time: Mon Sep  9 15:58:17 2019
 xfsrestore: level: 1
 xfsrestore: session label: "test-back1"
 xfsrestore: media label: "media0"
 xfsrestore: file system id: 61be573b-fa52-4684-af23-b635779a76e0
 xfsrestore: session id: c6bd99f2-37bf-4b38-9e05-1547a9d9a81f
 xfsrestore: media id: c71ac71e-3578-4fda-ab71-fd04ca9a5546
 xfsrestore: using online session inventory
 xfsrestore: searching media for directory dump
 xfsrestore: reading directories
 xfsrestore: 2 directories and 5 entries processed
 xfsrestore: directory post-processing
 xfsrestore: restoring non-directory files
 xfsrestore: restore complete: 0 seconds elapsed
 xfsrestore: Restore Summary:
 xfsrestore:   stream 0 /opt/test-back1 OK (success)
 xfsrestore: Restore Status: SUCCESS
[root@master opt]# ls /data/
 aa  bb  cc  grub2  wxj  yt

所有文件都已恢复

发表评论

登录... 后才能评论