5.打包与压缩
本章同步视频:https://edu.51cto.com/sd/e4874
5.3 xfs文件系统的备份和恢复
XFS提供了 xfsdump 和 xfsrestore 工具协助备份XFS文件系统中的数据。XFS不需要在备份前被卸载;对使用中的XFS文件系统做备份就可以保证镜像的一致性。XFS的备份和恢复的过程是可以被中断然后继续的,无须冻结文件系统。xfsdump 甚至提供了高性能的多线程备份操作——它把一次dump拆分成多个数据流,每个数据流可以被发往不同的目的地。
5.3.1 备份策略
完全备份是指把所有需要备份的数据全部备份。完全备份可以备份整块硬盘、整个分区或某个具体的目录。
完全备份的好处是,所有数据都进行了备份,系统中任何数据丢失都能恢复,且恢复效率较高。
完全备份的缺点也很明显,那就是需要备份的数据量较大,备份时间较长,备份了很多无用数据,占用的空间较大,所以完全备份不可能每天执行。
累计增量备份是指先进行一次完全备份,服务器运行一段时间之后,比较当前系统和完全备份的备份数据之间的差异,只备份有差异的数据。服务器继续运行,再经过一段时间,进行第二次增量备份。在进行第二次增量备份时,当前系统和第一次增量备份的数据进行比较,也是只备份有差异的数据。第三次增量备份是和第二次增量备份的数据进行比较,以此类推。
采用累计增量备份的好处是,每次备份需要备份的数据较少,耗时较短,占用的空间较小;坏处是数据恢复比较麻烦,那么当进行数据恢复时,就要先恢复完全备份的数据,再依次恢复第一次增量备份的数据、第二次增量备份的数据和第三次增量备份的数据,最终才能恢复所有的数据。
差异备份也要先进行一次完全备份,但是和累计增量备份不同的是,每次差异备份都备份和原始的完全备份不同的数据。也就是说,差异备份每次备份的参照物都是原始的完全备份,而不是上一次的差异备份。
相比较而言,差异备份既不像完全备份一样把所有数据都进行备份,也不像增量备份在进行数据恢复时那么麻烦,只要先恢复完全备份的数据,再恢复差异备份的数据即可。不过,随着时间的增加,和完全备份相比,变动的数据越来越多,那么差异备份也可能会变得数据量庞大、备份速度缓慢、占用空间较大。
5.3.2 XFS 文件系统备份xfsdump
u xfsdump不支援没有挂载的文件系统备份!所以只能备份已挂载的!
u xfsdump必须使用 root 的权限才能操作 (涉及文件系统的关系)
u xfsdump备份下来的数据 (档案或储存媒体) 只能让xfsrestore解析
u xfsdump是透过文件系统的 UUID 来分辨各个备份档的,因此不能备份两个具有相同 UUID 的文件系统喔!
2.xfsdump - XFS filesystem incremental dump utility
[root@study ~]# xfsdump [-L S_label] [-M M_label] [-l #] [-f 备份档] 待备份资料
-L :xfsdump会纪录每次备份的 session 标头,这里可以填写针对此文件系统的简易说明
-M :xfsdump可以纪录储存媒体的标头,这里可以填写此媒体的简易说明
-l :是 L 的小写,就是指定等级~有 0~9 共 10 个等级喔! (预设为 0,即完整备份)
-f :有点类似 tar 啦!后面接产生的档案,亦可接例如 /dev/st0 装置文件名或其他一般档案档名等
-I :从 /var/lib/xfsdump/inventory 列出目前备份的信息状态
使用fdisk划分一个分区sda3,并格式化为xfs。(此部分操作省略)
[root@localhost mnt]# mount /dev/sda3 /mnt/sda3/ #挂载
[root@localhost mnt]# df -h /dev/sda3 #查看挂载情况,可省略
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 197M 11M 187M 6% /mnt/sda3
[root@localhost mnt]# blkid /dev/sda3 #查看分区信息,可省略
/dev/sda3: UUID="f598c75c-bd26-4543-af2f-8192841c4c8b" TYPE="xfs"
[root@localhost mnt]# touch /mnt/sda3/1.txt
[root@localhost mnt]# xfsdump -l 0 -f /tmp/sda3 /dev/sda3
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.3 (dump format 3.0) - type ^C for status and control
=============== dump label dialog =================
please enter label for this dump session (timeout in 300 sec)
session label entered: "dump_sda3_20200331"
--------------------------------- end dialog ---------------------------------
xfsdump: level 0 dump of localhost.localdomain:/mnt/sda3
xfsdump: dump date: Tue Mar 31 20:30:53 2020
xfsdump: session id: 0dab0e83-90fb-4fef-88db-974bd0e5a2f3
xfsdump: session label: "dump_sda3_20200331"
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: 21120 bytes
xfsdump: /var/lib/xfsdump/inventory created
=============== media label dialog =================
please enter label for media in drive 0 (timeout in 300 sec)
--------------------------------- end dialog ---------------------------------
xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping non-directory files
xfsdump: media file size 21656 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 33 seconds elapsed
xfsdump: stream 0 /tmp/sda3 OK (success)
[root@localhost mnt]# ls /tmp/
[root@localhost mnt]# xfsdump -l 0 -L dump_sda3_20200331 -M sda3 -f /tmp/sda3 /dev/sda3
[root@localhost mnt]# xfsdump -I #
fs id: f598c75c-bd26-4543-af2f-8192841c4c8b
mount point: localhost.localdomain:/mnt/sda3
device: localhost.localdomain:/dev/sda3
time: Tue Mar 31 20:42:51 2020
session label: "dump_sda3_20200331"
session id: b2315293-f79f-43b2-9276-157268eea187
media id: 23a27bd0-e47b-4bee-9005-d530e6303f63
[root@localhost mnt]# ls sda3/
[root@localhost mnt]# touch sda3/2.txt
[root@localhost mnt]# ls sda3/
[root@localhost mnt]# xfsdump -l 1 -L dump_sda3_20200331-1 -M sda3 -f /tmp/sda3-1 /dev/sda3
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.3 (dump format 3.0) - type ^C for status and control
xfsdump: level 1 incremental dump of localhost.localdomain:/mnt/sda3 based on level 0 dump begun Tue Mar 31 20:42:51 2020
xfsdump: dump date: Tue Mar 31 20:47:58 2020
xfsdump: session id: 989e4ade-b8c3-40be-9714-10c648f6b46c
xfsdump: session label: "dump_sda3_20200331-1"
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: 21120 bytes
xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping non-directory files
xfsdump: media file size 21680 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 0 seconds elapsed
xfsdump: stream 0 /tmp/sda3-1 OK (success)
[root@localhost mnt]# xfsdump -I
fs id: f598c75c-bd26-4543-af2f-8192841c4c8b
mount point: localhost.localdomain:/mnt/sda3
device: localhost.localdomain:/dev/sda3
time: Tue Mar 31 20:42:51 2020
session label: "dump_sda3_20200331"
session id: b2315293-f79f-43b2-9276-157268eea187
media id: 23a27bd0-e47b-4bee-9005-d530e6303f63
mount point: localhost.localdomain:/mnt/sda3
device: localhost.localdomain:/dev/sda3
time: Tue Mar 31 20:47:58 2020
session label: "dump_sda3_20200331-1"
session id: 989e4ade-b8c3-40be-9714-10c648f6b46c
media id: 42121b62-abf0-4e26-98f1-48d50f01b633
[root@localhost mnt]# touch sda3/{3,4,5,6}.txt
[root@localhost mnt]# ls sda3/
1.txt 2.txt 3.txt 4.txt 5.txt 6.txt
[root@localhost mnt]# xfsdump -l 2 -L dump_sda3_20200331-2 -M sda3 -f /tmp/sda3-2 /dev/sda3
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.3 (dump format 3.0) - type ^C for status and control
xfsdump: level 2 incremental dump of localhost.localdomain:/mnt/sda3 based on level 1 dump begun Tue Mar 31 20:47:58 2020
xfsdump: dump date: Tue Mar 31 20:56:34 2020
xfsdump: session id: 1a6e946b-fd0e-4e70-bb00-b82c04291de7
xfsdump: session label: "dump_sda3_20200331-2"
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: 22080 bytes
xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping non-directory files
xfsdump: media file size 23624 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 0 seconds elapsed
xfsdump: stream 0 /tmp/sda3-2 OK (success)
[root@localhost mnt]# xfsdump -I
fs id: f598c75c-bd26-4543-af2f-8192841c4c8b
mount point: localhost.localdomain:/mnt/sda3
device: localhost.localdomain:/dev/sda3
time: Tue Mar 31 20:42:51 2020
session label: "dump_sda3_20200331"
session id: b2315293-f79f-43b2-9276-157268eea187
media id: 23a27bd0-e47b-4bee-9005-d530e6303f63
mount point: localhost.localdomain:/mnt/sda3
device: localhost.localdomain:/dev/sda3
time: Tue Mar 31 20:47:58 2020
session label: "dump_sda3_20200331-1"
session id: 989e4ade-b8c3-40be-9714-10c648f6b46c
media id: 42121b62-abf0-4e26-98f1-48d50f01b633
mount point: localhost.localdomain:/mnt/sda3
device: localhost.localdomain:/dev/sda3
time: Tue Mar 31 20:56:34 2020
session label: "dump_sda3_20200331-2"
session id: 1a6e946b-fd0e-4e70-bb00-b82c04291de7
media id: f410ea13-eada-4566-87c8-844b1a939ce1