Back up and restore the database
With the default cnpg database the chart can archive the write-ahead log continuously and take scheduled base backups to an object store. Together they give you point-in-time recovery. Backups are off by default.
The chart supports Google Cloud Storage today (through the CloudNativePG built-in Barman object store).
What you need
Section titled “What you need”- A bucket, for example
gs://my-vesicle-backups. - A Google service account with these permissions on the bucket: object read/write/delete (for example Storage Object Admin) and bucket metadata read (for example Storage Legacy Bucket Reader). Without the bucket permission, archiving fails with an access error on
storage.buckets.get. - A JSON key for that service account, stored in a Kubernetes Secret.
The chart does not create the credentials Secret. Create it yourself, in the release namespace:
kubectl -n vss create secret generic postgres-backup \ --from-file=gcsCredentials=./service-account-key.jsonThe Secret key is gcsCredentials by default. Change it with database.cnpg.backup.credentialsSecret.key. If you keep secrets in a store, create the Secret with the External Secrets Operator: declare the ExternalSecret under extraObjects in your values, and reference the Secret it produces.
On GKE with Workload Identity, set database.cnpg.backup.gkeEnvironment: true and no credentials Secret is needed.
Turn it on
Section titled “Turn it on”database: cnpg: backup: enabled: true destinationPath: gs://my-vesicle-backups/production retentionPolicy: 30d schedule: "0 0 2 * * *" # six fields, seconds first, UTC: daily at 02:00 credentialsSecret: name: postgres-backupOther settings: walCompression and dataCompression (default gzip).
Check that it works
Section titled “Check that it works”kubectl -n vss get cluster,backup,scheduledbackupkubectl -n vss get cluster vss-postgres -o jsonpath='{range .status.conditions[*]}{.type}={.status} {.message}{"\n"}{end}'You want ContinuousArchiving=True, and the first Backup ending in the phase completed. A backup stuck in walArchivingFailing means the archiver cannot write to the bucket: check the permissions above, then delete the stuck Backup object so a new one can start. The scheduled job takes the first backup right after you enable it.
One folder per cluster
Section titled “One folder per cluster”A cluster must be the only writer of its folder in the bucket. If the folder already holds files from another cluster, archiving fails with Expected empty archive. This happens when you reinstall and the old data is still there. Either empty the folder, or set a new folder name:
database: cnpg: backup: serverName: vss-postgres-2 # default: the cluster namePick a new serverName every time you recreate the database, and keep the old folder until you no longer need it.
Restore
Section titled “Restore”A restore creates a new cluster from the bucket. It never overwrites a running one. Use it for disaster recovery, or when a database must be recreated.
database: cnpg: backup: enabled: true destinationPath: gs://my-vesicle-backups/production serverName: vss-postgres-2 # NEW name: never the folder you restore from credentialsSecret: name: postgres-backup recovery: enabled: true sourceServerName: vss-postgres # the folder to restore from # backupName: <a specific Backup> # default: the latest # targetTime: "2026-11-28 09:30:00+00" # replay the log up to this momentSteps:
- Remove the broken database:
helm uninstalldeletes the database cluster. The generated Secrets and the NATS volumes stay. - Install again with the values above, under the same release name.
- When the new cluster is healthy, log in and check your data.
The recovery block applies only when the cluster is created. Keep it in your values while the restored cluster exists: if the cluster is ever recreated without it, you get an empty database.
NATS keeps its own state (durable queues and media) and is not part of the database backup. After a restore, check that message sync works, and rehearse the whole procedure in a spare environment before you need it.
Good practice
Section titled “Good practice”- Practise a restore in a spare environment before you rely on backups.
- Back up before every upgrade and wait for the
Backupto complete. - Add a lifecycle rule on the bucket for old objects.
retentionPolicyremoves expired backups, but a rule is a second line of defence. - Use a separate service account and bucket per environment.
- Back up the federation signing key separately: it is not in the database (see Install with Helm).