PGO Crunchy Operator uses pgBackRest for managing backups.
pgBackRest - is a backup and restore solution for PostgreSQL databases that offers several features, such as parallel backup and restore, compression, full, differential, and incremental backups, backup rotation and archive expiration, backup integrity and etc. It supports multiple repositories, which can be located locally or remotely via TLS/SSH, or be cloud provided storage as S3/GCS/Azure.
Backup configuration
Backup configuration is done through the spec.backups.pgbackrest parameter. See the example below.
aidboxdb.yaml
spec:backups:pgbackrest:repos: - name:repo1# reposchedules:full:"0 1 * * 0"# Full backup once a week on Sunday at 1 AMincremental:"0 1 * * 1-6"# incremental - from Monday to Saturday at 1 AM gcs:bucket:"<BUCKET_NAME>"# GCS bucket name configuration: - secret:name:pgo-gcs-creds# GCS credentials - configMap:name:pgbackrest-config# pgbackrest configglobal:repo1-path:/backup/aidboxdb# Backup path in bucketrepo1-retention-full-type:time# Retention policy repo1-retention-full:"30"# Delete backups after 30 daysmanual:repoName:repo1options:# Manual backup configuration - '--type=full' - '--compress-level=6' - '--start-fast=y' - '--process-max=20' - '--log-level-console=info'
repos: - Defines a pgBackRest repository. This allows you to configure where and how your backups and WAL archive are stored. You can keep backups in up to four (4) different locations.
apiVersion:v1kind:Secretmetadata:name:pgo-gcs-credsnamespace:aidboxdb-dbdataString:gcs.conf:|- [global] repo1-gcs-key=/etc/pgbackrest/conf.d/gcs-key.jsongcs-key.json:|- <GCP SA JSON access file>
Schedule
In this spec, we define incremental backup from Monday to Saturday and take one full backup every Sunday at 1 AM:
spec:backups:pgbackrest:repos: - name:repo1schedules:full:"0 1 * * 0"# Full backup once a week on Sunday at 1AMincremental:"0 1 * * 1-6"# incremental - from Monday to Saturday at 1AM
Backup retention
Define backup retention policy. In this spec we store all backups for 30 days, after that period - delete them:
spec:backups:pgbackrest:global:repo1-path:/backup/aidboxdb# Backup path in bucketrepo1-retention-full-type:time# Retention policy repo1-retention-full:"30"# Delete backups after 30 days
Create backup
At certain instances, you may find it necessary to perform a singular backup, especially before making significant modifications or updates to an application. To do so, you must first configure the spec.backups.pgbackrest.manual section, which includes details about the type of backup desired and any additional pgBackRest configuration settings required:
spec:backups:pgbackrest:manual:repoName:repo1options:# Manual backup configuration - '--type=full'# Take full backup - '--compress-level=6'# Compress GZ - '--start-fast=y'# Do no wait checkpoint - '--process-max=20'# Max processes to use for compressing and transfer
For creating a manual backup you should annotate postgrescluster resource with postgres-operator.crunchydata.com/pgbackrest-backup annotation:
Sometimes you need to recover your database or clone your production database to the stage environment. Generally in the recovery process, we can define two types of recovery: clone the existing cluster to another environment, PITR - recovery database at a specific point in time.
Clone
To create a new clone of the existing PG cluster you should specify dataSource parameter for the new cluster. In the sample below we create stage cluster as a copy of aidboxdb cluster in aidboxdb-db namespace.