Operations
Backup And Restores
Custom Secret
Monitoring
tpl
This guide demonstrates how to configure a PostgreSQL cluster on KubeBlocks with:
This combination provides comprehensive data protection with minimal recovery point objectives (RPO).
Point-In-Time Recovery (PITR) allows you to restore a database to a specific moment in time by combining full backups with continuous binlog/wal/archive log backups.
For details on restoring data from both full backups and continuous binlog backups, refer to the Restore From PITR guide.
Before proceeding, ensure the following:
kubectl create ns demo
namespace/demo created
Backup Repository Configured:
BackupRepo
BackupRepo
status is Ready
Cluster is Running:
Running
stateKubeBlocks PostgreSQL supports these backup methods:
Feature | Method | Description |
---|---|---|
Full Backup | pg-basebackup | Uses pg_basebackup , a PostgreSQL utility to create a base backup |
Full Backup | wal-g | Uses wal-g to create a full backup (requires WAL-G configuration) |
Continuous Backup | postgresql-pitr | Uploads PostgreSQL Write-Ahead Logging (WAL) files periodically to the backup repository, usually paired with pg-basebackup |
Continuous Backup | wal-g-archive | Uploads PostgreSQL Write-Ahead Logging (WAL) files periodically to the backup repository, usually paired with wal-g |
Deploy a 2-node PostgreSQL replication cluster (1 primary, 1 secondary) and specify backup information.
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: pg-cluster
namespace: demo
spec:
terminationPolicy: Delete
clusterDef: postgresql
topology: replication
componentSpecs:
- name: postgresql
serviceVersion: 16.4.0
labels:
apps.kubeblocks.postgres.patroni/scope: pg-cluster-postgresql
disableExporter: true
replicas: 2
resources:
limits:
cpu: "0.5"
memory: "0.5Gi"
requests:
cpu: "0.5"
memory: "0.5Gi"
volumeClaimTemplates:
- name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
backup:
retentionPeriod: 7d
# for full backup
method: pg-basebackup # full backup methnod name
enabled: true
cronExpression: 0 18 * * * # full backup scheuler
# for continuous backup
continuousMethod: wal-g-archive # continuous backup method, paired with method wal-g
pitrEnabled: true # enable continous method or not
repoName: s3-repo # specify backuprepo, if not specified, the BackupRepo annotated as `default` will be used.
Key Configuration Fields Explained
Field | Value | Description |
---|---|---|
backup.enabled | true | Enables scheduled backups |
method | pg-basebackup | Full backup method using PostgreSQL's native utility |
cronExpression | 0 18 * * * | Daily full backup at 6PM UTC |
retentionPeriod | 7d | Retains backups for 7 days |
repoName | s3-repo | Backup repository name (S3-compatible storage) |
pitrEnabled | true | Enables continuous WAL archiving for PITR |
continuousMethod | wal-g-archive | Method for continuous WAL archiving |
Monitor the cluster status until it transitions to the Running state:
kubectl get cluster pg-cluster -n demo -w
Example Output:
NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE
pg-cluster postgresql Delete Creating 50s
pg-cluster postgresql Delete Running 4m2s
Once the cluster status becomes Running, your PostgreSQL cluster is ready for use.
Verify continuous backup operation with these commands:
# get continuous backup
kubectl get backup -l app.kubernetes.io/instance=pg-cluster,dataprotection.kubeblocks.io/backup-type=Continuous -n demo
# get pod working for continuous backup
kubectl get pod -l app.kubernetes.io/instance=pg-cluster,dataprotection.kubeblocks.io/backup-type=Continuous -n demo
KubeBlocks automatically creates a BackupSchedule
resource. Inspect the configuration:
kubectl get backupschedule pg-cluster-postgresql-backup-schedule -n demo -oyaml
Example Output:
apiVersion: dataprotection.kubeblocks.io/v1alpha1
kind: BackupSchedule
...
spec:
backupPolicyName: pg-cluster-postgresql-backup-policy
schedules:
- backupMethod: pg-basebackup
cronExpression: 0 18 * * *
enabled: true #
retentionPeriod: 7d
- backupMethod: wal-g-archive
cronExpression: '*/5 * * * *'
enabled: true # set to `true` to enable continuous backup
retentionPeriod: 8d # set the retention period to your need
Full Backups (pg-basebackup):
Continuous Backups (wal-g-archive):
This guide covered:
Key Benefits: