xfsdump和xfsrestore是xfs备份、恢复工具,适用于xfs格式下的备份和恢复操作,包括全量备份恢复和增量备份恢复。
准备CentOS7虚机环境,yum源配置好,挂载一块10G硬盘(硬盘按需选择大小):
一、备份
创建目录
// 创建目录
mkdir /xfsdump //需要备份的目录
mkdir /xfsdump/xfsdump.{1,2,3} //需要备份目录下的子目录,用于区分增量备份和全量备份
mkdir /dump //备份文件保存在此目录
第一次全量备份
xfsdump
–f [备份存放路径]
[要备份的设备文件或挂载点]
-L 指定备份会话标签
-M 指定设备标签
//创建备份文件,分别进行全量备份和增量备份
[root@localhost /]# xfsdump -f /dump/sdb_bak1 /xfsdump -L dum_sdb_bak1 -M sdb //第一次全量备份,各目录下均为空
[root@localhost /]# touch /xfsdump/xfsdump.1/bak1.txt
[root@localhost /]# tree /xfsdump/
/xfsdump/
├── xfsdump.1
│ └── bak1.txt
├── xfsdump.2
└── xfsdump.3
3 directories, 1 file
第二次做全量备份
[root@localhost /]# xfsdump -l 1 -f /dump/sdb_bak2 /xfsdump -L dum_sdb_bak2 -M sdb
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 localhost.localdomain:/xfsdump based on level 0 dump begun Fri Jun 26 16:17:18 2020
xfsdump: dump date: Fri Jun 26 16:23:14 2020
xfsdump: session id: 8aee987b-b91b-433d-9bf1-6186a56bfaf3
xfsdump: session label: "dum_sdb_bak2"
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 22384 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 0 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /dump/sdb_bak2 OK (success)
xfsdump: Dump Status: SUCCESS
[root@localhost /]# touch /xfsdump/xfsdump.2/bak2.txt
[root@localhost /]# tree /xfsdump/
/xfsdump/
├── xfsdump.1
│ └── bak1.txt
├── xfsdump.2
│ └── bak2.txt
└── xfsdump.3
3 directories, 2 files
第三次做全量备份
[root@localhost /]# xfsdump -l 2 -f /dump/sdb_bak3 /xfsdump -L dum_sdb_bak3 -M sdb
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 localhost.localdomain:/xfsdump based on level 1 dump begun Fri Jun 26 16:23:14 2020
xfsdump: dump date: Fri Jun 26 16:25:49 2020
xfsdump: session id: 2479da11-bfde-4b72-8bd2-bf4c69af0bc3
xfsdump: session label: "dum_sdb_bak3"
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 22384 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 0 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /dump/sdb_bak3 OK (success)
xfsdump: Dump Status: SUCCESS
[root@localhost /]# touch /xfsdump/xfsdump.3/bak3
[root@localhost /]# tree /xfsdump/
/xfsdump/
├── xfsdump.1
│ └── bak1.txt
├── xfsdump.2
│ └── bak2.txt
└── xfsdump.3
└── bak3.txt
3 directories, 3 files
第四次做全量备份
[root@localhost /]# xfsdump -f /dump/sdb_bak4 /xfsdump -L dum_sdb_bak4 -M sdb
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 localhost.localdomain:/xfsdump
xfsdump: dump date: Fri Jun 26 16:27:46 2020
xfsdump: session id: 9a476feb-ea14-4de7-b855-e664c4a8050b
xfsdump: session label: "dum_sdb_bak4"
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 24928 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 0 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /dump/sdb_bak4 OK (success)
xfsdump: Dump Status: SUCCESS
[root@localhost /]# tree /dump/
/dump/
├── sdb_bak1
├── sdb_bak2
├── sdb_bak3
└── sdb_bak4
0 directories, 4 files
删除需要备份的全部文件
//删除需要备份的全部文件
[root@localhost /]# rm -rf /xfsdump/ *
[root@localhost /]# tree /xfsdump/
/xfsdump/
0 directories, 0 files
二、恢复
第一次全量恢复
[root@localhost /]# xfsrestore -f /dump/sdb_bak1 /xfsdump/
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: localhost.localdomain
xfsrestore: mount point: /xfsdump
xfsrestore: volume: /dev/sdb
xfsrestore: session time: Fri Jun 26 16:17:18 2020
xfsrestore: level: 0
xfsrestore: session label: "dum_sdb_bak1"
xfsrestore: media label: "sdb"
xfsrestore: file system id: 006c4d9e-6937-4b23-8e04-e095520a9d47
xfsrestore: session id: 3a88d749-9baf-4058-ba6f-0ca87246cb99
xfsrestore: media id: e81513d2-4017-4c13-8000-8776cf93e75e
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 4 directories and 3 entries processed
xfsrestore: directory post-processing
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore: stream 0 /dump/sdb_bak1 OK (success)
xfsrestore: Restore Status: SUCCESS
[root@localhost /]# tree /xfsdump/
/xfsdump/
├── xfsdump.1
├── xfsdump.2
└── xfsdump.3
3 directories, 0 files
第二次增量恢复
[root@localhost /]# xfsrestore -f /dump/sdb_bak2 /xfsdump/
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: localhost.localdomain
xfsrestore: mount point: /xfsdump
xfsrestore: volume: /dev/sdb
xfsrestore: session time: Fri Jun 26 16:23:14 2020
xfsrestore: level: 1
xfsrestore: session label: "dum_sdb_bak2"
xfsrestore: media label: "sdb"
xfsrestore: file system id: 006c4d9e-6937-4b23-8e04-e095520a9d47
xfsrestore: session id: 8aee987b-b91b-433d-9bf1-6186a56bfaf3
xfsrestore: media id: 84bb3a2b-f018-4ca9-a611-dd5a81eb2923
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 2 directories and 4 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore: stream 0 /dump/sdb_bak2 OK (success)
xfsrestore: Restore Status: SUCCESS
[root@localhost /]# tree /xfsdump/
/xfsdump/
├── xfsdump.1
│ └── bak1.txt
├── xfsdump.2
└── xfsdump.3
3 directories, 1 file
第三次增量恢复
[root@localhost /]# xfsrestore -f /dump/sdb_bak3 /xfsdump/
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: localhost.localdomain
xfsrestore: mount point: /xfsdump
xfsrestore: volume: /dev/sdb
xfsrestore: session time: Fri Jun 26 16:25:49 2020
xfsrestore: level: 2
xfsrestore: session label: "dum_sdb_bak3"
xfsrestore: media label: "sdb"
xfsrestore: file system id: 006c4d9e-6937-4b23-8e04-e095520a9d47
xfsrestore: session id: 2479da11-bfde-4b72-8bd2-bf4c69af0bc3
xfsrestore: media id: 1be5687a-6653-4e6c-8367-7677a8caa7a6
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 2 directories and 4 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore: stream 0 /dump/sdb_bak3 OK (success)
xfsrestore: Restore Status: SUCCESS
[root@localhost /]# tree /xfsdump/
/xfsdump/
├── xfsdump.1
│ └── bak1.txt
├── xfsdump.2
│ └── bak2.txt
└── xfsdump.3
3 directories, 2 files
第四次全量恢复
[root@localhost /]# rm -rf /xfsdump/ *
[root@localhost /]# xfsrestore -f /dump/sdb_bak4 /xfsdump/
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: localhost.localdomain
xfsrestore: mount point: /xfsdump
xfsrestore: volume: /dev/sdb
xfsrestore: session time: Fri Jun 26 16:27:46 2020
xfsrestore: level: 0
xfsrestore: session label: "dum_sdb_bak4"
xfsrestore: media label: "sdb"
xfsrestore: file system id: 006c4d9e-6937-4b23-8e04-e095520a9d47
xfsrestore: session id: 9a476feb-ea14-4de7-b855-e664c4a8050b
xfsrestore: media id: 42a0600e-351a-49e4-9989-713e6142789a
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 4 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 /dump/sdb_bak4 OK (success)
xfsrestore: Restore Status: SUCCESS
[root@localhost /]# tree /xfsdump/
/xfsdump/
├── xfsdump.1
│ └── bak1.txt
├── xfsdump.2
│ └── bak2.txt
└── xfsdump.3
└── bak3.txt
3 directories, 3 files