gpbackup和gprestore工具支持创建追加优化表的增量备份以及从增量备份还原。 只有表被更改时,增量备份才会备份所有指定的堆表和追加优化的表(包括追加优化的,面向列的表)。 例如,如果追加优化表的行已更改,则会备份该表。 对于分区的追加优化表,仅备份更改的叶子分区。当自上次备份以来,追加优化表更或分区表更改的数据与未更改的数据相比量很小的时候,增量备份是高效的。
仅当在上次全量备份或增量备份后对表执行以下操作之一时,增量备份才会备份追加优化表:
要从增量备份还原数据,需要一个完整的增量备份集。 一个增量备份集包含如下备份:
创建增量备份时,这些选项与其他gpbackup选项一起创建备份:
将增量备份添加到备份集时,gpbackup通过检查以下gpbackup选项来确保全量备份和增量备份是一致的:
此示例假定您已创建数据库mytest的两个全量备份和增量备份。 要创建全量备份,请使用以下命令:
gpbackup --dbname mytest --backup-dir /mybackup --leaf-partition-data
使用下面命令创建增量备份:
gpbackup --dbname mytest --backup-dir /mybackup --leaf-partition-data --incremental
当指定--backup-dir选项时,备份被创建在每个数据库主机的/mybackup目录里。此命令基于全量备份20171114064330创建增量备份集,并与包含增量备份20180114051246的备份集分开。
gpbackup --dbname mytest --backup-dir /mybackup --leaf-partition-data --incremental --from-timesta
要使用增量备份20170914081205还原数据库, 需要增量备份20120914081205和20170714095512, 以及全量备份20170514054532。
gprestore --backup-dir /backupdir --timestamp 20170914081205
gpbackup输出显示增量备份所基于的备份的时间戳。 在此示例中,增量备份基于时间戳为20180802171642的备份。 备份20180802171642可以是增量备份或全量备份。
$ gpbackup --dbname test --backup-dir /backups --leaf-partition-data --incremental
20180803:15:40:51 gpbackup:mppadmin:mdw:002907-[INFO]:-Starting backup of database test
20180803:15:40:52 gpbackup:mppadmin:mdw:002907-[INFO]:-Backup Timestamp = 20180803154051
20180803:15:40:52 gpbackup:mppadmin:mdw:002907-[INFO]:-Backup Database = test
20180803:15:40:52 gpbackup:mppadmin:mdw:002907-[INFO]:-Gathering list of tables for backup
20180803:15:40:52 gpbackup:mppadmin:mdw:002907-[INFO]:-Acquiring ACCESS SHARE locks on tables
Locks acquired: 5 / 5 [================================================================] 100.00% 0s
20180803:15:40:52 gpbackup:mppadmin:mdw:002907-[INFO]:-Gathering additional table metadata
20180803:15:40:52 gpbackup:mppadmin:mdw:002907-[INFO]:-Metadata will be written to /backups/gpseg-1/backups/20180803/20180803154051/gpbackup_20180803154051_metadata.sql
20180803:15:40:52 gpbackup:mppadmin:mdw:002907-[INFO]:-Writing global database metadata
20180803:15:40:52 gpbackup:mppadmin:mdw:002907-[INFO]:-Global database metadata backup complete
20180803:15:40:52 gpbackup:mppadmin:mdw:002907-[INFO]:-Writing pre-data metadata
20180803:15:40:52 gpbackup:mppadmin:mdw:002907-[INFO]:-Pre-data metadata backup complete
20180803:15:40:52 gpbackup:mppadmin:mdw:002907-[INFO]:-Writing post-data metadata
20180803:15:40:52 gpbackup:mppadmin:mdw:002907-[INFO]:-Post-data metadata backup complete
20180803:15:40:52 gpbackup:mppadmin:mdw:002907-[INFO]:-Basing incremental backup off of backup with timestamp = 20180802171642
20180803:15:40:52 gpbackup:mppadmin:mdw:002907-[INFO]:-Writing data to file
Tables backed up: 4 / 4 [==============================================================] 100.00% 0s
20180803:15:40:52 gpbackup:mppadmin:mdw:002907-[INFO]:-Data backup complete
20180803:15:40:53 gpbackup:mppadmin:mdw:002907-[INFO]:-Found neither /usr/local/mpp-db/./bin/gp_email_contacts.yaml nor /home/mppadmin/gp_email_contacts.yaml
20180803:15:40:53 gpbackup:mppadmin:mdw:002907-[INFO]:-Email containing gpbackup report /backups/gpseg-1/backups/20180803/20180803154051/gpbackup_20180803154051_report will not be sent
20180803:15:40:53 gpbackup:mppadmin:mdw:002907-[INFO]:-Backup completed successfully
从增量备份还原时,可以指定--verbose选项以在命令行上显示还原操作中使用的备份。 例如,以下gprestore命令使用时间戳20180807092740(增量备份)还原备份。 输出包括用于还原数据库数据的备份。
$ gprestore --create-db --timestamp 20180807162904 --verbose
...
20180807:16:31:56 gprestore:mppadmin:mdw:008603-[INFO]:-Pre-data metadata restore complete
20180807:16:31:56 gprestore:mppadmin:mdw:008603-[DEBUG]:-Verifying backup file count
20180807:16:31:56 gprestore:mppadmin:mdw:008603-[DEBUG]:-Restoring data from backup with timestamp: 20180807162654
20180807:16:31:56 gprestore:mppadmin:mdw:008603-[DEBUG]:-Reading data for table public.tbl_ao from file (table 1 of 1)
20180807:16:31:56 gprestore:mppadmin:mdw:008603-[DEBUG]:-Checking whether segment agents had errors during restore
20180807:16:31:56 gprestore:mppadmin:mdw:008603-[DEBUG]:-Restoring data from backup with timestamp: 20180807162819
20180807:16:31:56 gprestore:mppadmin:mdw:008603-[DEBUG]:-Reading data for table public.test_ao from file (table 1 of 1)
20180807:16:31:56 gprestore:mppadmin:mdw:008603-[DEBUG]:-Checking whether segment agents had errors during restore
20180807:16:31:56 gprestore:mppadmin:mdw:008603-[DEBUG]:-Restoring data from backup with timestamp: 20180807162904
20180807:16:31:56 gprestore:mppadmin:mdw:008603-[DEBUG]:-Reading data for table public.homes2 from file (table 1 of 4)
20180807:16:31:56 gprestore:mppadmin:mdw:008603-[DEBUG]:-Reading data for table public.test2 from file (table 2 of 4)
20180807:16:31:56 gprestore:mppadmin:mdw:008603-[DEBUG]:-Reading data for table public.homes2a from file (table 3 of 4)
20180807:16:31:56 gprestore:mppadmin:mdw:008603-[DEBUG]:-Reading data for table public.test2a from file (table 4 of 4)
20180807:16:31:56 gprestore:mppadmin:mdw:008603-[DEBUG]:-Checking whether segment agents had errors during restore
20180807:16:31:57 gprestore:mppadmin:mdw:008603-[INFO]:-Data restore complete
20180807:16:31:57 gprestore:mppadmin:mdw:008603-[INFO]:-Restoring post-data metadata
20180807:16:31:57 gprestore:mppadmin:mdw:008603-[INFO]:-Post-data metadata restore complete
从增量备份还原时,gprestore还会在gprestore日志文件中列出还原操作中使用的备份。在还原操作期间,如果全量备份或其他所需的增量备份不可用,gprestore将显示错误。如果在创建增量备份时未指定--from-timestamp选项,则gpbackup将使用具有一 致选项集的最新备份。 该工具检查备份历史记录文件以查找具有一致选项集的备份。 如果工具找不到具有一致选项集的备份或历史文件不存在,则gpbackup会显示一条消息,指出必须先创建全量备份才能创建增量。如果在创建增量备份时指定--from-timestamp选项,则gpbackup可确保正在创建的备份选项与指定备份的选项一致。
从增量备份集还原时,gprestore会检查备份并从备份集中最新版本的追加优化表中还原每个追加优化表,并从最新备份还原堆表。增量备份集,全量备份和关联的增量备份必须位于单个设备上。 例如,备份集中的备份必须全部位于文件系统上,或者必须全部位于Data Domain系统上。