The Percona Postgres Operator uses a Custom Resource Definition called PgTask to manage backups and restore executions.
This way manually scheduled tasks can be done declaratively by creating a configuration file of kind PgTask.
You need to be familiar with the following tasks:
pgtasks is a general purpose CRD that accepts a type of task that is needed to run against a cluster (e.g. take a backup) and tracks the state of said task through its workflow. More information can be found here.
A PgTask can be used for either creating Backups or restoring backups. While the Building Block comes with predefined Backup-Tasks (daily, weekly and monthly), you can also do manual backups.
To create a manual backup the configuration file for a PgTask is as follows:
#manual-backup.yaml
apiVersion: pg.percona.com/v1
kind: Pgtask
metadata:
labels:
pg-cluster: pg-db
pgouser: admin
name: backrest-backup-manual-pg-db
namespace: syseleven-pg-operator
spec:
name: backrest-backup-manual-pg-db
parameters:
backrest-command: backup
backrest-opts: --type=full --repo1-retention-full=1
backrest-s3-verify-tls: "false" #it is assumed you did not provide the certificate of your s3-bucket
backrest-storage-type: "s3"
job-name: backrest-backup-manual-pg-db
pg-cluster: pg-db
tasktype: backrest
You can execute the manual backup with kubectl apply -f manual-backup.yaml
.
Restoring is similar to the backup task:
#restore.yaml
apiVersion: pg.percona.com/v1
kind: Pgtask
metadata:
labels:
pg-cluster: pg-db
pgouser: admin
name: cluster1-backrest-restore
namespace: syseleven-pg-operator
spec:
name: cluster1-backrest-restore
namespace: syseleven-pg-operator
parameters:
backrest-restore-from-cluster: pg-db
backrest-restore-opts: --set=20230227-161526F #can be retrieved via s3cmd
backrest-storage-type: s3
backrest-s3-verify-tls: "false"
tasktype: restore
To retrieve your last known backup you can use the s3cmd-CLI:
#get the s3-bucket-name of your backup
s3cmd ls
#we assume the name of your s3 bucket is pg-db-backup-1
s3cmd get s3://pg-db-backup-1/backrestrepo/pg-db-backrest-shared-repo/backup/db/backup.info
With one entry, preferrably the latest one in the section [backup:current]
you can edit the key value pair spec.parameters.backrest-restore-opts: --set=$YOUR_BACKUP_ID
.
Now a similar command kubectl apply -f restore.yaml
executes the restore-workflow.