xfs文件系统的备份和恢复

首先了解一下xfsdump的备份级别有以下两种:0,代表完整备份;1~9,代表增量备份。默认为0(即完全备份)。
备份
先确定/boot是独立文件系统

# df -h /boot/
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1      1014M  146M  869M  15% /boot
# yum -y install xfsdump

全备文件系统

# xfsdump -l 0 -L boot_all -M boot_all -f /srv/boot.dump /boot
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:/boot
xfsdump: dump date: Sun Mar 22 14:04:00 2020
xfsdump: session id: 05f1d5dc-b2dc-4dcb-a02f-bdc6a27a60d1
xfsdump: session label: "boot_all"
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: 118228544 bytes
xfsdump: /var/lib/xfsdump/inventory created
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 117895032 bytes
xfsdump: dump size (non-dir files) : 117662128 bytes
xfsdump: dump complete: 3 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /srv/boot.dump OK (success)
xfsdump: Dump Status: SUCCESS
# ll /srv/
total 115132
-rw-r--r--. 1 root root    117895032 Mar 22 14:04 boot.dump

备份后会有文件产生:

# ll /var/lib/xfsdump/inventory/
total 16
-rw-r--r--. 1 root root  312 Mar 22 14:04 7e3c8d7e-bed2-43b3-8014-36cc39aad1c9.InvIndex
-rw-r--r--. 1 root root 5080 Mar 22 14:04 ebc8b723-ae66-42ec-a4c1-2577d5b06113.StObj
-rw-r--r--. 1 root root  576 Mar 22 14:04 fstab

进行增量备份:
查看是否有文件系统被dump过

# xfsdump -I
file system 0:
	fs id:		7e3c8d7e-bed2-43b3-8014-36cc39aad1c9
	session 0:
		mount point:	localhost.localdomain:/boot
		device:		localhost.localdomain:/dev/sda1
		time:		Sun Mar 22 14:04:00 2020
		session label:	"boot_all"
		session id:	05f1d5dc-b2dc-4dcb-a02f-bdc6a27a60d1
		level:		0
		resumed:	NO
		subtree:	NO
		streams:	1
		stream 0:
			pathname:	/srv/boot.dump
			start:		ino 69 offset 0
			end:		ino 1572934 offset 0
			interrupted:	NO
			media files:	1
			media file 0:
				mfile index:	0
				mfile type:	data
				mfile size:	117895032
				mfile start:	ino 69 offset 0
				mfile end:	ino 1572934 offset 0
				media label:	"boot_all"
				media id:	785b8a80-9731-4fb6-a507-916148d55515
xfsdump: Dump Status: SUCCESS

产生一个文件:

# dd if=/dev/zero of=/boot/test.img bs=1M count=10
10+0 records in
10+0 records out
10485760 bytes (10 MB) copied, 0.102524 s, 102 MB/s

创建差异备份:

# xfsdump -l 1 -L boot_2 -M boot_2 -f /srv/boot.dump1 /boot
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control
xfsdump: WARNING: most recent level 1 dump was interrupted, but not resuming that dump since resume (-R) option not specified
xfsdump: level 1 incremental dump of localhost.localdomain:/boot based on level 0 dump begun Sun Mar 22 14:04:00 2020
xfsdump: dump date: Sun Mar 22 14:10:05 2020
xfsdump: session id: 62b554c6-e17b-454f-b75a-684b8cfba2da
xfsdump: session label: "boot_2"
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: 10506880 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 10510952 bytes
xfsdump: dump size (non-dir files) : 10488352 bytes
xfsdump: dump complete: 0 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /srv/boot.dump1 OK (success)
xfsdump: Dump Status: SUCCESS

查看是否有记录level 1时间点

# xfsdump -I
file system 0:
	fs id:		7e3c8d7e-bed2-43b3-8014-36cc39aad1c9
	session 0:
		mount point:	localhost.localdomain:/boot
		device:		localhost.localdomain:/dev/sda1
		time:		Sun Mar 22 14:04:00 2020
		session label:	"boot_all"
		session id:	05f1d5dc-b2dc-4dcb-a02f-bdc6a27a60d1
		level:		0
		resumed:	NO
		subtree:	NO
		streams:	1
		stream 0:
			pathname:	/srv/boot.dump
			start:		ino 69 offset 0
			end:		ino 1572934 offset 0
			interrupted:	NO
			media files:	1
			media file 0:
				mfile index:	0
				mfile type:	data
				mfile size:	117895032
				mfile start:	ino 69 offset 0
				mfile end:	ino 1572934 offset 0
				media label:	"boot_all"
				media id:	785b8a80-9731-4fb6-a507-916148d55515
	session 1:
		mount point:	localhost.localdomain:/boot
		device:		localhost.localdomain:/dev/sda1
		time:		Sun Mar 22 14:09:45 2020
		session label:	"boot_2"
		session id:	4830eb06-2f41-4534-9adf-1b886c2ae58f
		level:		1
		resumed:	NO
		subtree:	NO
		streams:	1
		stream 0:
			pathname:	/srv/boot.dump
			start:		ino 0 offset 0
			end:		ino 0 offset 0
			interrupted:	YES
			media files:	0
	session 2:
		mount point:	localhost.localdomain:/boot
		device:		localhost.localdomain:/dev/sda1
		time:		Sun Mar 22 14:10:05 2020
		session label:	"boot_2"
		session id:	62b554c6-e17b-454f-b75a-684b8cfba2da
		level:		1
		resumed:	NO
		subtree:	NO
		streams:	1
		stream 0:
			pathname:	/srv/boot.dump1
			start:		ino 79 offset 0
			end:		ino 80 offset 0
			interrupted:	NO
			media files:	1
			media file 0:
				mfile index:	0
				mfile type:	data
				mfile size:	10510952
				mfile start:	ino 79 offset 0
				mfile end:	ino 80 offset 0
				media label:	"boot_2"
				media id:	00d1fcb3-31ba-4d24-81e0-a41d18cb8141
xfsdump: Dump Status: SUCCESS

还原:

查看备份

# xfsrestore -I
file system 0:
	fs id:		7e3c8d7e-bed2-43b3-8014-36cc39aad1c9
	session 0:
		mount point:	localhost.localdomain:/boot
		device:		localhost.localdomain:/dev/sda1
		time:		Sun Mar 22 14:04:00 2020
		session label:	"boot_all"
		session id:	05f1d5dc-b2dc-4dcb-a02f-bdc6a27a60d1
		level:		0
		resumed:	NO
		subtree:	NO
		streams:	1
		stream 0:
			pathname:	/srv/boot.dump
			start:		ino 69 offset 0
			end:		ino 1572934 offset 0
			interrupted:	NO
			media files:	1
			media file 0:
				mfile index:	0
				mfile type:	data
				mfile size:	117895032
				mfile start:	ino 69 offset 0
				mfile end:	ino 1572934 offset 0
				media label:	"boot_all"
				media id:	785b8a80-9731-4fb6-a507-916148d55515
	session 1:
		mount point:	localhost.localdomain:/boot
		device:		localhost.localdomain:/dev/sda1
		time:		Sun Mar 22 14:09:45 2020
		session label:	"boot_2"
		session id:	4830eb06-2f41-4534-9adf-1b886c2ae58f
		level:		1
		resumed:	NO
		subtree:	NO
		streams:	1
		stream 0:
			pathname:	/srv/boot.dump
			start:		ino 0 offset 0
			end:		ino 0 offset 0
			interrupted:	YES
			media files:	0
	session 2:
		mount point:	localhost.localdomain:/boot
		device:		localhost.localdomain:/dev/sda1
		time:		Sun Mar 22 14:10:05 2020
		session label:	"boot_2"
		session id:	62b554c6-e17b-454f-b75a-684b8cfba2da
		level:		1
		resumed:	NO
		subtree:	NO
		streams:	1
		stream 0:
			pathname:	/srv/boot.dump1
			start:		ino 79 offset 0
			end:		ino 80 offset 0
			interrupted:	NO
			media files:	1
			media file 0:
				mfile index:	0
				mfile type:	data
				mfile size:	10510952
				mfile start:	ino 79 offset 0
				mfile end:	ino 80 offset 0
				media label:	"boot_2"
				media id:	00d1fcb3-31ba-4d24-81e0-a41d18cb8141
xfsrestore: Restore Status: SUCCESS

还原至/tmp/boot

# mkdir /tmp/boot
# xfsrestore -f /srv/boot.dump -L boot_all /tmp/boot
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.7 (dump format 3.0) - type ^C for status and control
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: examining media file 0
xfsrestore: reading directories
xfsrestore: 9 directories and 324 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 2 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore:   stream 0 /srv/boot.dump OK (success)
xfsrestore: Restore Status: SUCCESS

未还原增量备份:

# diff -r /boot /tmp/boot
Only in /boot: test.img

仅还原备份中间中grub2:

# mkdir /tmp/boot1

还原操作

# xfsrestore -f /srv/boot.dump -L boot_all -s grub2 /tmp/boot1
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.7 (dump format 3.0) - type ^C for status and control
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: examining media file 0
xfsrestore: reading directories
xfsrestore: 9 directories and 324 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore:   stream 0 /srv/boot.dump OK (success)
xfsrestore: Restore Status: SUCCESS

# ll /tmp/boot1/
total 0
drwx------. 5 root root 97 Jun 17  2019 grub2

还原增量备份:

# xfsrestore -f /srv/boot.dump1 /tmp/boot
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: /boot
xfsrestore: volume: /dev/sda1
xfsrestore: session time: Sun Mar 22 14:10:05 2020
xfsrestore: level: 1
xfsrestore: session label: "boot_2"
xfsrestore: media label: "boot_2"
xfsrestore: file system id: 7e3c8d7e-bed2-43b3-8014-36cc39aad1c9
xfsrestore: session id: 62b554c6-e17b-454f-b75a-684b8cfba2da
xfsrestore: media id: 00d1fcb3-31ba-4d24-81e0-a41d18cb8141
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 1 directories and 13 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore:   stream 0 /srv/boot.dump1 OK (success)
xfsrestore: Restore Status: SUCCESS

完全还原了:

# diff -r /boot /tmp/boot

你可能感兴趣的:(xfs文件系统的备份和恢复)