How-To
Manual Backup and Restore¶
Perform on-demand backups and restore PostgreSQL clusters from backups.
Trigger Manual Backup¶
Create a Backup resource:
apiVersion: postgresql.cnpg.io/v1
kind: Backup
metadata:
name: myapp-postgres-manual-backup
namespace: myapp
spec:
cluster:
name: myapp-postgres
method: barmanObjectStore # Backup to S3
Apply and monitor:
kubectl apply -f backup.yaml
kubectl get backup myapp-postgres-manual-backup -n myapp -w
Restore from Backup¶
Full Cluster Restore¶
Create a new cluster from an existing backup:
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: myapp-postgres-restored
namespace: myapp
spec:
instances: 2
bootstrap:
recovery:
source: myapp-postgres-backup
externalClusters:
- name: myapp-postgres-backup
barmanObjectStore:
destinationPath: s3://myapp-postgres-backup-kup6s/
endpointURL: https://fsn1.your-objectstorage.com
s3Credentials:
accessKeyId:
name: myapp-postgres-s3-creds
key: ACCESS_KEY_ID
secretAccessKey:
name: myapp-postgres-s3-creds
key: SECRET_ACCESS_KEY
storage:
size: 10Gi
storageClass: longhorn-redundant-app
Point-in-Time Recovery (PITR)¶
Restore to a specific timestamp:
spec:
bootstrap:
recovery:
source: myapp-postgres-backup
recoveryTarget:
targetTime: "2025-11-02 12:00:00.000000+00"
Verify Restore¶
Check cluster status after restore:
kubectl get cluster myapp-postgres-restored -n myapp
kubectl logs myapp-postgres-restored-1 -n myapp