How to migrate a cluster¶
This is a guide on how to restore a backup that was made from a different cluster, (i.e. cluster migration via restore).
See How to restore a local backup to perform a basic restore from a local backup
Prerequisites¶
A PostgreSQL deployment scaled down to one unit (scale it up again after the backup is restored)
A backup from the previous cluster in your S3 storage
Passwords from your previous cluster
Apply cluster credentials¶
When you restore a backup from an old cluster, it will restore the password from the previous cluster to your current cluster.
Set the password of your current cluster to the previous cluster’s password:
juju run postgresql/leader set-password username=operator password=<previous cluster password>
juju run postgresql/leader set-password username=replication password=<previous cluster password>
juju run postgresql/leader set-password username=rewind password=<previous cluster password>
juju run postgresql-k8s/leader set-password username=operator password=<previous cluster password>
juju run postgresql-k8s/leader set-password username=replication password=<previous cluster password>
juju run postgresql-k8s/leader set-password username=rewind password=<previous cluster password>
Juju 2.9 users
Remember that juju run <action name> becomes juju run-action <action name> --wait for Juju 2.9.
List backups¶
To view the available backups to restore, use the command list-backups:
juju run postgresql/leader list-backups
juju run postgresql-k8s/leader list-backups
Take note of the backup-id that corresponds to the previous cluster.
Restore backup¶
To restore your current cluster to the state of the previous cluster, the restore command with your backup-id:
juju run postgresql/leader restore backup-id=YYYY-MM-DDTHH:MM:SSZ
juju run postgresql-k8s/leader restore backup-id=YYYY-MM-DDTHH:MM:SSZ
Your restore will then be in progress, once it is complete your cluster will represent the state of the previous cluster.