xfs文件系统的备份和恢复详解程序员

         xfs提供了xfsdump和xfsrestore工具,协助备份xfs文件系统中的数据。xfsdump按inode顺序备份一个xfs文件系统

         在CentOS7中,xfs格式作为默认文件系统,不再使用以前的ext,但仍然支持ext4。xfs专为大数据产生,每个文件系统最大可以支持8eb,单个文件可以支持16tb,不仅数据量大,而且扩展性高。还可以通过xfsdump和xfsrestore来备份和恢复。原始备份数据方法:cp

         与传统的UNIX文件系统不同,xfs不需要备份前卸载;对使用中的xfs文件系统做备份就可以保证镜像的一致性。xfs的备份和恢复的过程是可以被中断然后继续的,无需冻结文件系统。xfsdump甚至特功了高性能的多线程备份操作——它把一次dump拆分成多个数据流,每个数据流可以被发往不同的目的地

         首先了解一下xfsdump的备份级别有以下两种:0,代表完整备份;1~9,代表增量备份。默认为0(即完全备份)。

(1).环境

VMware12       系统CentOS7.6

添加一块虚拟硬盘(准备一个测试分区),分区,格式化,挂载

1)添加完一块虚拟硬盘后如何查看系统是否识别

[[email protected] xf]# fdisk -l 
磁盘 /dev/sda:21.5 GB, 21474836480 字节,41943040 个扇区 
Units = 扇区 of 1 * 512 = 512 bytes 
扇区大小(逻辑/物理):512 字节 / 512 字节 
I/O 大小(最小/最佳):512 字节 / 512 字节 
磁盘标签类型:dos 
磁盘标识符:0x000c83f7 
 
   设备 Boot      Start         End      Blocks   Id  System 
/dev/sda1   *        2048      411647      204800   83  Linux 
/dev/sda2          411648    21383167    10485760   83  Linux 
/dev/sda3        21383168    25577471     2097152   82  Linux swap / Solaris 
 
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区 
Units = 扇区 of 1 * 512 = 512 bytes 
扇区大小(逻辑/物理):512 字节 / 512 字节 
I/O 大小(最小/最佳):512 字节 / 512 字节 
[[email protected] xf]# ls /dev/sd* 
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda3  /dev/sdb

2)分区,格式化,挂载可以参考以下文档:

https://www.cnblogs.com/diantong/p/8855683.html

这里创建一个1G的sdb1分区,xfs格式化,并挂载到新建的文件夹/sdb1

3)准备一份备份的测试文件

[[email protected] xf]# cd /sdb1/ 
[[email protected] sdb1]# ls 
[[email protected] sdb1]# cp /etc/passwd ./ 
[[email protected] sdb1]# mkdir test 
[[email protected] sdb1]# touch test/a 
[[email protected] sdb1]# tree /sdb1/ 
/sdb1/ 
├── passwd 
└── test 
    └── a 
1 directory, 2 files

(2).完整备份

1)备份整个分区

xfsdump –f [备份存放路径] [要备份的设备文件或挂载点]

注意:备份的路径这里不能写/sdb1/。可以写成/dev/sdb1或/sdb1

[[email protected] sdb1]# mkdir /dump 
[[email protected] sdb1]# xfsdump -f /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_20181228		//指定备份会话标签,就是对此文件系统的简短描述 
session label entered: "dump_sdb1_20181228" 
 --------------------------------- end dialog --------------------------------- 
xfsdump: level 0 dump of xuexi:/sdb1 
xfsdump: dump date: Fri Dec 28 14:11:55 2018 
xfsdump: session id: a1afa104-8f0c-42fa-be6e-594b674f13c7 
xfsdump: session label: "dump_sdb1_20181228" 
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: 25856 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 25552 bytes 
xfsdump: dump size (non-dir files) : 2592 bytes 
xfsdump: dump complete: 39 seconds elapsed 
xfsdump: Dump Summary: 
xfsdump:   stream 0 /dump/sdb1 OK (success) 
xfsdump: Dump Status: SUCCESS

2)指定备份时免交互操作,方便后期做定时备份

-L 指定备份会话标签

-M 指定设备标签

[[email protected] sdb1]# xfsdump -f /dump/sdb1_v2 /sdb1 -L dump_sdb1_20181228_v2 -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 xuexi:/sdb1 
xfsdump: dump date: Fri Dec 28 14:26:05 2018 
xfsdump: session id: 5595618f-a3c3-4f4d-a5fc-0f6b86513400 
xfsdump: session label: "dump_sdb1_20181228_v2"		//备份会话标签 
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: 25856 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 25552 bytes 
xfsdump: dump size (non-dir files) : 2592 bytes 
xfsdump: dump complete: 0 seconds elapsed 
xfsdump: Dump Summary: 
xfsdump:   stream 0 /dump/sdb1_v2 OK (success) 
xfsdump: Dump Status: SUCCESS

3)指定只备份分区中某个目录或文件

-s [文件路径] 只对指定的文件或目录进行备份,路径是相对路径

[[email protected] sdb1]# ls /boot/grub2/ 
device.map  fonts  grub.cfg  grub.cfg.1544939406.rpmsave  grubenv  i386-pc  locale 
[[email protected] sdb1]# xfsdump -f /dump/grub2_grub.cfg -s grub2/grub.cfg /boot -L dump_grub2_grub.cfg_20181228 -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 xuexi:/boot 
xfsdump: dump date: Fri Dec 28 15:43:25 2018 
xfsdump: session id: 6c2c5768-7389-46be-ab7b-11ceaf19c2b5 
xfsdump: session label: "dump_grub2_grub.cfg_20181228" 
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 28848 bytes 
xfsdump: dump size (non-dir files) : 5152 bytes 
xfsdump: dump complete: 0 seconds elapsed 
xfsdump: Dump Summary: 
xfsdump:   stream 0 /dump/grub2_grub.cfg OK (success) 
xfsdump: Dump Status: SUCCESS

4)查看备份信息和内容

备份成功后,我们可以在/var/lib/xfsdump/inventory目录下看到生成的档案信息

[[email protected] sdb1]# ls /var/lib/xfsdump/inventory/	 
02c76feb-497b-4167-8e72-f8b81a79dbf9.InvIndex  43384fc8-7ba5-4f18-b9f9-246e4992962b.StObj  fstab 
1eccfe79-a9eb-4f09-83c1-f28aa64db1ce.InvIndex  afe37eaa-9e10-4243-ad45-36aadc180d58.StObj 
[[email protected] sdb1]# xfsdump –I(大写的i)	//查看所有备份信息

注意:使用xfsdump时有以下几个限制:

1.xfsdump不支持没有挂载的文件系统备份!

2.xfsdump必须使用root权限才能操作(涉及文件系统的关系)

3.xfsdump只能备份xfs文件系统

4.xfsdump备份下来的数据(档案或存储媒体)只能让xfsrestore解析

5.xfsdump是通过文件系统的UUID来分辨系统各个备份档的,英雌不能备份两个具有相同UUID的文件系统

(3).文件系统恢复

xfsrestore –f [指定需要恢复的备份文件路径] [指定恢复后文件的存放路径]

1)测试恢复:先删除之前创建的内容

[[email protected] sdb1]# ls 
passwd  test 
[[email protected] sdb1]# pwd 
/sdb1 
[[email protected] sdb1]# rm -rf ./*

2)恢复整个分区

[[email protected] sdb1]# xfsrestore -f /dump/sdb1 /sdb1/ 
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: xuexi 
xfsrestore: mount point: /sdb1 
xfsrestore: volume: /dev/sdb1 
xfsrestore: session time: Fri Dec 28 14:11:55 2018 
xfsrestore: level: 0 
xfsrestore: session label: "dump_sdb1_20181228" 
xfsrestore: media label: "sdb1" 
xfsrestore: file system id: 1eccfe79-a9eb-4f09-83c1-f28aa64db1ce 
xfsrestore: session id: a1afa104-8f0c-42fa-be6e-594b674f13c7 
xfsrestore: media id: 8db0ba63-465f-42ba-8581-7cc22a24b902 
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 /dump/sdb1 OK (success) 
xfsrestore: Restore Status: SUCCESS 
[[email protected] sdb1]# ls /sdb1/ 
passwd  test 
[[email protected] sdb1]# tree /sdb1/ 
/sdb1/ 
├── passwd 
└── test 
    └── a 
1 directory, 2 files

3)恢复单个文件

[[email protected] sdb1]# ls 
passwd  test 
[[email protected] sdb1]# xfsrestore -f /dump/grub2_grub.cfg -s grub2/grub.cfg /sdb1/ 
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: xuexi 
xfsrestore: mount point: /boot 
xfsrestore: volume: /dev/sda1 
xfsrestore: session time: Fri Dec 28 15:43:25 2018 
xfsrestore: level: 0 
xfsrestore: session label: "dump_grub2_grub.cfg_20181228" 
xfsrestore: media label: "boot-sda1" 
xfsrestore: file system id: 02c76feb-497b-4167-8e72-f8b81a79dbf9 
xfsrestore: session id: 6c2c5768-7389-46be-ab7b-11ceaf19c2b5 
xfsrestore: media id: dc813998-6f28-4686-96c2-d844525cecff 
xfsrestore: using online session inventory 
xfsrestore: searching media for directory dump 
xfsrestore: reading directories 
xfsrestore: 2 directories and 24 entries processed 
xfsrestore: directory post-processing 
xfsrestore: restoring non-directory files 
xfsrestore: restore complete: 0 seconds elapsed 
xfsrestore: Restore Summary: 
xfsrestore:   stream 0 /dump/grub2_grub.cfg OK (success) 
xfsrestore: Restore Status: SUCCESS 
[[email protected] sdb1]# ls 
grub2  passwd  test 
[[email protected] sdb1]# tree /sdb1/ 
/sdb1/ 
├── grub2 
│   └── grub.cfg 
├── passwd 
└── test 
    └── a 
2 directories, 3 files

注意:

[[email protected] sdb1]# xfsrestore -f /dump/grub2_grub.cfg  -s grub2/grub.cfg /sdb1/

[[email protected] sdb1]# xfsrestore -f /dump/grub2_grub.cfg  -s grub2 /sdb1/

这两个命令相同效果

(4).增量备份

开始之前看一下备份目录

[[email protected] sdb1]# tree /sdb1/ 
/sdb1/ 
├── grub2 
│   └── grub.cfg 
├── passwd 
└── test 
    └── a 
2 directories, 3 files

1)  进行第一次完整备份

[[email protected] sdb1]# xfsdump -f /dump/full_backup /sdb1 -L full_backup_sdb1 -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 xuexi:/sdb1 
xfsdump: dump date: Fri Dec 28 16:54:44 2018 
xfsdump: session id: d3809f53-bc01-4138-afd1-98e436fbc48a 
xfsdump: session label: "full_backup_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: 34688 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 32312 bytes 
xfsdump: dump size (non-dir files) : 7744 bytes 
xfsdump: dump complete: 0 seconds elapsed 
xfsdump: Dump Summary: 
xfsdump:   stream 0 /dump/full_backup OK (success) 
xfsdump: Dump Status: SUCCESS

2)  进行第一次增量备份

注意:-l [备份级别],设置备份级别

[[email protected] sdb1]# touch /sdb1/{1.txt,2.txt}	//新增两个文件 
[[email protected] sdb1]# tree /sdb1/ 
/sdb1/ 
├── 1.txt 
├── 2.txt 
├── grub2 
│   └── grub.cfg 
├── passwd 
└── test 
    └── a 
2 directories, 5 files 
[[email protected] sdb1]# xfsdump -l 1 -f /dump/incremental_backup1 /sdb1 -L incremental_backup1_sdb1 -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 1 incremental dump of xuexi:/sdb1 based on level 0 dump begun Fri Dec 28 16:54:44 2018 
xfsdump: dump date: Fri Dec 28 16:59:54 2018 
xfsdump: session id: 0dd47814-2901-4301-99dc-5203e9a3dac0 
xfsdump: session label: "incremental_backup1_sdb1" 
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 22704 bytes 
xfsdump: dump size (non-dir files) : 0 bytes 
xfsdump: dump complete: 0 seconds elapsed 
xfsdump: Dump Summary: 
xfsdump:   stream 0 /dump/incremental_backup1 OK (success) 
xfsdump: Dump Status: SUCCESS

3)  进行第二次增量备份

[[email protected] sdb1]# touch /sdb1/test/a.txt /sdb1/b.txt 
[[email protected] sdb1]# tree /sdb1/ 
/sdb1/ 
├── 1.txt 
├── 2.txt 
├── b.txt 
├── grub2 
│   └── grub.cfg 
├── passwd 
└── test 
    ├── a 
    └── a.txt 
2 directories, 7 files 
[[email protected] sdb1]# xfsdump -l 2 -f /dump/incremental_backup2 /sdb1 -L incremental_backup2_sdb1 -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 2 incremental dump of xuexi:/sdb1 based on level 1 dump begun Fri Dec 28 16:59:54 2018 
xfsdump: dump date: Fri Dec 28 17:05:21 2018 
xfsdump: session id: 6d59a61c-5e5b-476d-ac8d-07b7610355ae 
xfsdump: session label: "incremental_backup2_sdb1" 
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: 21760 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 23400 bytes 
xfsdump: dump size (non-dir files) : 0 bytes 
xfsdump: dump complete: 0 seconds elapsed 
xfsdump: Dump Summary: 
xfsdump:   stream 0 /dump/incremental_backup2 OK (success) 
xfsdump: Dump Status: SUCCESS

4)  恢复

步骤:

1.先恢复完整备份

2.如果两次备份都是1级的,那么只需要恢复最后一次增量备份;但如果第一次是1级备份,第二次是2级备份,那么需要先恢复完整备份,然后恢复1级备份,最后2级备份

实际操作:

删除,测试恢复

[[email protected] sdb1]# rm -rf /sdb1/*

先恢复完整备份

[[email protected] sdb1]# xfsrestore -f /dump/full_backup  /sdb1/ 
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: xuexi 
xfsrestore: mount point: /sdb1 
xfsrestore: volume: /dev/sdb1 
xfsrestore: session time: Fri Dec 28 16:54:44 2018 
xfsrestore: level: 0 
xfsrestore: session label: "full_backup_sdb1" 
xfsrestore: media label: "sdb1" 
xfsrestore: file system id: 1eccfe79-a9eb-4f09-83c1-f28aa64db1ce 
xfsrestore: session id: d3809f53-bc01-4138-afd1-98e436fbc48a 
xfsrestore: media id: 3f4eeb44-b277-4df8-a7ba-de162e8a5c3e 
xfsrestore: using online session inventory 
xfsrestore: searching media for directory dump 
xfsrestore: reading directories 
xfsrestore: 3 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 /dump/full_backup OK (success) 
xfsrestore: Restore Status: SUCCESS 
[[email protected] sdb1]# tree /sdb1/ 
/sdb1/ 
├── grub2 
│   └── grub.cfg 
├── passwd 
└── test 
    └── a 
2 directories, 3 files

恢复1级备份

[[email protected] sdb1]# xfsrestore -f /dump/incremental_backup1 /sdb1/ 
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: xuexi 
xfsrestore: mount point: /sdb1 
xfsrestore: volume: /dev/sdb1 
xfsrestore: session time: Fri Dec 28 16:59:54 2018 
xfsrestore: level: 1 
xfsrestore: session label: "incremental_backup1_sdb1" 
xfsrestore: media label: "sdb1" 
xfsrestore: file system id: 1eccfe79-a9eb-4f09-83c1-f28aa64db1ce 
xfsrestore: session id: 0dd47814-2901-4301-99dc-5203e9a3dac0 
xfsrestore: media id: dc9c4bed-671c-4199-9660-31b6a3c560b7 
xfsrestore: using online session inventory 
xfsrestore: searching media for directory dump 
xfsrestore: reading directories 
xfsrestore: 1 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 /dump/incremental_backup1 OK (success) 
xfsrestore: Restore Status: SUCCESS 
[[email protected] sdb1]# tree /sdb1/ 
/sdb1/ 
├── 1.txt 
├── 2.txt 
├── grub2 
│   └── grub.cfg 
├── passwd 
└── test 
    └── a 
2 directories, 5 files

恢复2级备份

[[email protected] sdb1]# xfsrestore -f /dump/incremental_backup2 /sdb1/ 
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: xuexi 
xfsrestore: mount point: /sdb1 
xfsrestore: volume: /dev/sdb1 
xfsrestore: session time: Fri Dec 28 17:05:21 2018 
xfsrestore: level: 2 
xfsrestore: session label: "incremental_backup2_sdb1" 
xfsrestore: media label: "sdb1" 
xfsrestore: file system id: 1eccfe79-a9eb-4f09-83c1-f28aa64db1ce 
xfsrestore: session id: 6d59a61c-5e5b-476d-ac8d-07b7610355ae 
xfsrestore: media id: daf6acdb-921f-437e-a33b-538e47c0ca1a 
xfsrestore: using online session inventory 
xfsrestore: searching media for directory dump 
xfsrestore: reading directories 
xfsrestore: 2 directories and 8 entries processed 
xfsrestore: directory post-processing 
xfsrestore: restoring non-directory files 
xfsrestore: restore complete: 0 seconds elapsed 
xfsrestore: Restore Summary: 
xfsrestore:   stream 0 /dump/incremental_backup2 OK (success) 
xfsrestore: Restore Status: SUCCESS 
[[email protected] sdb1]# tree /sdb1/ 
/sdb1/ 
├── 1.txt 
├── 2.txt 
├── b.txt 
├── grub2 
│   └── grub.cfg 
├── passwd 
└── test 
    ├── a 
    └── a.txt 
2 directories, 7 files

(5).扩展:

  完整备份:每次都将所有数据(不管自第一次备份以来有没有修改过),进行一次完整的复制,备份后会清除文件的存档属性,方便日后增量备份或者差异备份进行版本比较。

  特点:占用空间大,备份速度慢,但恢复时一次恢复到位,恢复速度快。

 

  增量备份:在第一次完整备份之后,第二次开始每次都将添加了存档属性的文件进行备份,并且在备份之后再把这些存档属性清除。为什么要清除存档属性呢?这就是为了下一次备份的时候判断是否有文件变化,因为用户在每次备份以后修改这些被清除存档属性的文件,存档属性就会自动加上,相当于用户告诉系统,这些文件有变化,你下一次就备份这些文件,其他没有存档属性的就不需要备份,这就是增量备份的工作机制。

  类比:相当于机器人把地板打扫干净了,你踩过,就会有脚印(增加标记),下次机器人就把脚印记录下来,并且把脚印打扫干净(清除标记),始终保持地板干净。机器人每次记录并打扫的脚印就相当于每次增量备份的内容

  特点:因每次仅备份自上一次备份(注意是上一次,不是第一次)以来有变化的文件,所  以备份体积小,备份速度快,但是恢复的时候,需要按备份时间顺序,逐个备份版本进行恢复,恢复时间长。

 

  差异备份:在第一次完整备份之后,第二次开始每次都将所有文件与第一次完整备份的文件做比较,把自第一次完整备份以来所有修改过的文件进行备份,且以后每次备份都是和第一次完整备份进行比较(注意是第一次,不是上一次),备份自第一次完整备份以来所有的修改过的文件。因此,差异备份在备份完毕之后不需要清除文件的存档属性,因为这些文件和下一次备份没有什么关系,它仅仅和第一次完整备份的数据进行比较(第一次完整备份之后是清除存档属性的)。

  类比:相当于第一次机器人把地板打扫干净了,你踩过,就会有脚印,机器人就把脚印记录下来,但不打扫,下次你又有踩脏的,机器人就把你这几次所有踩脏的地方都记录下来,始终不打扫,每次都这样。机器人每次记录的内容就相当于差异备份的内容

       特点:占用空间比增量备份大,比完整备份小,恢复时仅需要恢复第一个完整版本和最后一次的差异版本,恢复速度介于完整备份和增量备份之间。

 

  简单的讲,完整备份就是不管三七二十一,每次都把指定的备份目录完整的复制一遍,不管目录下的文件有没有变化;增量备份就是每次将之前(第一次、第二次、直到前一次)做过备份之后有变化的文件进行备份;差异备份就是每次都将第一次完整备份以来有变化的文件进行备份。

 

举例:

  假设指定备份目录周一包含A、B、C三个文件。周一的时候,做了完整备份。周二新增了D文件,同时A文件发生变化,变成A1文件;周三新增了E文件,同时A文件变成了A2,B文件变成B1;周四新增了F文件,A2变成了A3,D变成了D1,同时删掉了C文件。

  不同备份方式下的备份情况(假设每天做一次备份):

       完整备份:周一,备份ABC三个文件;周二,备份A1、B、C、D四个文件;周三,备份A2、B1、C、D、E五个文件;周四,备份A3、B1、D1、E、F五个文件。

  增量备份:周一,备份ABC三个文件,完整备份;周二,备份与周一相比有变化的文件,即备份A1和D两个文件;周三,备份与之前所有版本相比有变化的文件,即备份A2,B1,E三个文件;周四,备份与之前所有版本相比有变化的文件,即备份A3,D1,F三个文件并删除C。

  差异备份:周一,备份ABC三个文件,完整备份;周二,备份与周一相比有变化的文件,即备份A1和D两个文件;周三,备份与周一相比有变化的文件,即备份A2、B1、D、E四个文件;周四,备份与周一相比有变化的文件,即备份A3、B1、D1、E、F五个文件并删除C。

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/2796.html

(0)
上一篇 2021年7月16日
下一篇 2021年7月16日

相关推荐

发表回复

登录后才能评论