GBase 8c Incremental Backup Practice

Cong Li - Sep 3 - - Dev Community

In today's information society, the importance of data cannot be overstated. For enterprises, protecting the integrity and availability of data is crucial. As the core component of data storage, the formulation and implementation of database backup and recovery strategies are key to ensuring data security. This article will detail the practice of incremental backup for the GBase 8c database, helping readers efficiently and reliably perform data backups to ensure data security and business continuity.

1. Overview of Backup Strategies

Before backing up the GBase 8c database, it is essential to determine the appropriate backup strategy. Depending on business needs and data importance, you can choose between full backups and incremental backups.

  • Full backup: Backs up all data.
  • Incremental backup: Only backs up data that has changed since the last backup.

Full backups offer higher disaster recovery availability, while incremental backups save time and storage space, making them especially suitable for environments with large amounts of data and frequent changes.

2. Preparations

Before performing incremental backups, ensure that the database is running correctly, and shut down unnecessary applications to reduce interference during the backup process. Also, check whether the backup storage device has sufficient capacity and whether the network connection is stable.

3. Configuring Incremental Backup

1) Enable the enable_cbm_tracking Parameter to Track Changes in Data Pages

Log in to the database, check, and set the parameter to on:

show enable_cbm_tracking;
alter system set enable_cbm_tracking=on;
Enter fullscreen mode Exit fullscreen mode

2) Initialize the Backup Directory

Create a backup path, for example, /home/gbase/backup:

gs_probackup init -B /home/gbase/backup
Enter fullscreen mode Exit fullscreen mode

Check the backup path:

tree -L 3 /home/gbase/backup
Enter fullscreen mode Exit fullscreen mode

3) Add a Backup Instance

Syntax:

gs_probackup add-instance -B backup-path                       ## Backup path
                         -D pgdata-path                       ## Data directory path
                         --instance=instance_name             ## Instance name (user-defined)
                         [-E external-directories-paths]      ## Other directories to back up
                         [--remote-proto=protocol]            ## Remote operation protocol (only SSH supported)
                         [--remote-host=destination]          ## Remote host IP or hostname
                         [--remote-path=path]                 ## Remote host's gs_probackup installation directory
                         [--remote-user=username]             ## User for SSH connection to remote host
                         [--remote-port=port]                 ## Port for SSH connection to remote host (default 22)
                         [--ssh-options=ssh_options]          ## SSH command line parameters
                         [--help]                             ## Show help information
Enter fullscreen mode Exit fullscreen mode

Example of adding an instance:

gs_probackup add-instance -B /home/gbase/backup -D /opt/database/install/data/dn --instance gs_bak2023_inst
Enter fullscreen mode Exit fullscreen mode

View backup files:

gs_probackup show -B /home/gbase/backup
Enter fullscreen mode Exit fullscreen mode

4) Perform Full and Incremental Backups

Both full and incremental backups follow the syntax below:

gs_probackup backup -B backup-path --instance=instance_name [-D pgdata-path]
   -b backup-mode                                       ## Backup mode: FULL (full backup) / PTRACK (incremental backup)
   [-C]                                                 ## -C specifies checkpoint mode as spread (scheduled), default is fast
   [-S slot-name] [--temp-slot]                         ## -S specifies physical replication slot name (default pg_probackup_slot), --temp-slot creates a temporary physical replication slot for streaming to ensure WAL segments required during backup are available
   [--backup-pg-log]                                    ## Backup log directory (default not backed up)
   [-j threads_num]                                     ## Number of parallel threads
   [--progress]                                         ## Show progress
   [--no-validate]                                      ## Skip auto-validation after backup
   [--skip-block-validation]                            ## Disable block-level validation to speed up backups
   [-E external-directories-paths]                      ## Other directories to back up
   [--no-sync]                                          ## Do not sync backup files to disk to improve write performance
   [--note=text]                                        ## Backup note
   [--archive-timeout=timeout]                          ## Timeout for streaming, in seconds (default 300)
   [--log-level-console=log-level-console]              ## Log level for console output, default is info, set to off to disable
   [--log-level-file=log-level-file]                    ## Log level for log file output, default off
   [--log-filename=log-filename]                        ## Name of the log file to create (strftime format example: pg_probackup-%u.log), default is pg_probackup.log
   [--error-log-filename=error-log-filename]            ## Filename for error logs
   [--log-directory=log-directory]                      ## Log directory for gs_probackup
   [--log-rotation-size=log-rotation-size]              ## Log rotation size (default unit KB, supports KB, MB, GB, TB), log rotates when size exceeds threshold, default 0 (disabled)
   [--log-rotation-age=log-rotation-age]                ## Max lifetime of a single log file (default unit min, supports ms, s, min, h, d), default 0 means disable time-based rotation
   [--delete-expired]                                   ## Delete backups not meeting retention policy defined in pg_probackup.conf
   [--delete-wal]                                       ## Delete unnecessary WAL files
   [--merge-expired]                                    ## Merge the oldest incremental backup with its expired parent backup that meets retention policy
   [--retention-redundancy=retention-redundancy]        ## Number of full backups to retain (default 0, disable setting)
   [--retention-window=retention-window]                ## Number of days to retain (default 0, disable setting)
   [--wal-depth=wal-depth]                              ## Number of valid backups for PITR on each timeline (default 0, disable setting)
   [--dry-run]                                          ## Show current status of all available backups, do not delete or merge expired backups
   [--ttl=interval]                                     ## Backup retention time from recovery time (supports ms, s, min, h, d (default s))
   [--expire-time=time]                                 ## Fixed expiration timestamp for backups (e.g., --expire-time='2020-01-01 00:00:00+03')
   [--compress-algorithm=compress-algorithm][--compress-level=compress-level][--compress]   ## Compression parameters: algorithm (zlib/pglz/none) / level (0~9, default 1) / compression (equivalent to zlib+1 compression level)
   [-d dbname] [-h host] [-p port] [-U username] [-w] [-W password]                         ## Connection info: database name / hostname / port / user / password
   [--remote-proto=protocol] [--remote-host=destination]
   [--remote-path=path] [--remote-user=username]
   [--remote-port=port] [--ssh-options=ssh_options]
   [--help]
Enter fullscreen mode Exit fullscreen mode

(a) Example of performing a full backup:

gs_probackup backup -B /home/gbase/gs_bak2021 --instance gs_bak2021_inst -b full -D /gauss/data/db1 -d mydb -p 26000 --progress \
Enter fullscreen mode Exit fullscreen mode

Sample output:

> --log-directory=/home/gbase/gs_bak2021/log  --log-rotation-size=10GB --log-rotation-age=30d  --log-level-file=info  --log-filename=full_20210111.log \
> --retention-redundancy=2 \
> --compress  \
> --note='This is full backup set.'
Enter fullscreen mode Exit fullscreen mode

(b) Example of performing an incremental backup:

gs_probackup backup -B /home/gbase/gs_bak2021 --instance gs_bak2021_inst -b PTRACK -D /gauss/data/db1 -d mydb -p 26000 --progress \
Enter fullscreen mode Exit fullscreen mode

Sample output:

> --log-directory=/home/gbase/gs_bak2021/log  --log-rotation-size=10GB --log-rotation-age=30d  --log-level-file=info  --log-filename=incr2_20210111.log \
> --delete-expired --delete-wal \
> --retention-redundancy=2 \
> --compress  \
> --note='This is the second incremental backup set.'
Enter fullscreen mode Exit fullscreen mode

5) Full Restore

Example of executing a full restore:

gs_probackup restore -B /home/gbase/backup/backup2023/ --instance=pg_test -D /opt/database/install/data/dn -i S6S7HT --progress -j 4 
Enter fullscreen mode Exit fullscreen mode

Where -i specifies the backup file ID, S6S7HT is the ID of the full backup.

4. Management and Maintenance of Backup Data

1) Regularly check the validity of backup data by performing recovery tests to verify the reliability of backup files.
2) Encrypt backup data to enhance data security.
3) Implement off-site storage strategies for backup data to prevent total data loss in the event of a local disaster.

Incremental backups reduce the time and resources needed for backups, improving efficiency. However, during data recovery, the most recent full backup must be restored first, followed by each incremental backup in sequence, which may extend recovery time. By practicing incremental backups for the GBase 8c database, data security can be effectively ensured while also improving backup efficiency. Nevertheless, any backup strategy should be tailored to the specific business scenario and data characteristics to optimize the data protection plan.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player