alloydbctl
and
Ansible to manage the backups. AlloyDB Omni manages backups through custom resource definitions (CRDs):
-
BackupPlan: each database cluster can have one or moreBackupPlanCRDs with different configurations and schedules. -
Backup: initiates backups based on yourBackupPlanCRDs.
Before you begin
Before you set up and configure pgBackRest, ensure that you have the following:
- Cloud Storage bucket : AlloyDB Omni stores backups in Cloud Storage buckets. For information on how to create buckets, see Create a bucket .
Create a backup plan
To create a backup plan, complete the following steps:
-
Create a
BackupPlanCRD using the following format:BackupPlan : metadata : name : BACKUP_PLAN_NAME spec : dbclusterRef : DBCLUSTER_NAME backupLocation : type : GCS gcsOptions : bucket : BUCKET_NAME key : BUCKET_FOLDERReplace the following variables:
-
BACKUP_PLAN_NAME: name for thisBackupPlanCRD. For example,my-backup-plan-1. -
DBCLUSTER_NAME: name of your database cluster that you defined in Create a cluster . -
BUCKET_NAME: name of the Cloud Storage bucket you created in Before you begin . -
BUCKET_FOLDER: path to the directory in Cloud Storage that backups should write to. You must provide an absolute path, which begins with/.
-
-
If you're using Ansible, create a playbook for your
BackupPlanCRD.- name : BACKUP_PLAN_PLAYBOOK_NAME hosts : localhost vars : ansible_user : ANSIBLE_USER ansible_ssh_private_key_file : ANSIBLE_SSH_PRIVATE_KEY_FILE ansible_become : true roles : - role : google.alloydbomni_orchestrator.backupReplace the following variables:
-
BACKUP_PLAN_PLAYBOOK_NAME: name of your Ansible playbook. For example,My BackupPlan. -
ANSIBLE_USER: OS user that Ansible uses to log into your AlloyDB Omni nodes. -
ANSIBLE_SSH_PRIVATE_KEY_FILE: private key Ansible uses to connect to your AlloyDB Omni nodes using SSH.
-
-
Apply your
BackupPlanresource.alloydbctlalloydbctl apply -d " DEPLOYMENT_SPEC " -r " BACKUP_PLAN_CRD "Replace the following variables:
-
DEPLOYMENT_SPEC: path to the deployment specification you created in Install AlloyDB Omni components . -
BACKUP_PLAN_CRD: path to theBackupPlanCRD you created in step one.
Ansible
ansible-playbook BACKUP_PLAN_PLAYBOOK -i " DEPLOYMENT_SPEC " \ -e resource_spec = " BACKUP_PLAN_CRD "Replace the following variables:
-
BACKUP_PLAN_PLAYBOOK: path to the playbook that you created for yourBackupPlanCRD in step two. -
DEPLOYMENT_SPEC: path to the deployment specification you created in Install AlloyDB Omni components . -
BACKUP_PLAN_CRD: path to theBackupPlanCRD you created in step one.
-
-
Confirm that the status field,
status.phase, for yourBackupPlanCRD isReady. If the CRD is not ready, wait until it is.alloydbctlalloydbctl get -d " DEPLOYMENT_SPEC " -t BackupPlan -n BACKUP_PLAN_NAME -o yamlAnsible
ansible-playbook status.yaml -i " DEPLOYMENT_SPEC " -e resource_type = BackupPlan \ -e resource_name = BACKUP_PLAN_NAME
Delete a backup plan
To delete a backup plan, use either of the following methods:
alloydbctl
alloydbctl
delete
-d
" DEPLOYMENT_SPEC
"
-t
BackupPlan
-n
BACKUP_PLAN_NAME
Replace the following variables:
-
DEPLOYMENT_SPEC: path to the deployment specification you created in Install AlloyDB Omni components . -
BACKUP_PLAN_NAME: name of theBackupPlanCRD to delete.
Ansible
-
Create a playbook for deleting the
BackupPlanCRD.- name : BACKUP_PLAN_DELETE_PLAYBOOK_NAME hosts : localhost vars : ansible_user : ANSIBLE_USER ansible_ssh_private_key_file : ANSIBLE_SSH_PRIVATE_KEY_FILE ansible_become : true roles : - role : google.alloydbomni_orchestrator.deleteReplace the following variables:
-
BACKUP_PLAN_DELETE_PLAYBOOK_NAME: name of your Ansible playbook. -
ANSIBLE_USER: OS user that Ansible uses to log into your AlloyDB Omni nodes. -
ANSIBLE_SSH_PRIVATE_KEY_FILE: private key Ansible uses to connect to your AlloyDB Omni nodes using SSH.
-
-
Run
ansible-playbookto delete theBackupPlanCRD.ansible-playbook BACKUP_PLAN_DELETE_PLAYBOOK_NAME -i " DEPLOYMENT_SPEC " -e resource_type = BackupPlan \ -e resource_name = BACKUP_PLAN_NAMEReplace the following variables:
-
BACKUP_PLAN_DELETE_PLAYBOOK_NAME: path to the playbook that you created for deleting theBackupPlanCRD in the previous step. -
DEPLOYMENT_SPEC: path to the deployment specification you created in Install AlloyDB Omni components . -
BACKUP_PLAN_NAME: name of theBackupPlanCRD to delete.
-
Create a backup
To create and initiate a backup, complete the following steps:
-
Create a
BackupCRD using the following format:Backup : metadata : name : BACKUP_NAME spec : backupPlanRef : BACKUP_PLAN_NAME dbclusterRef : DBCLUSTER_NAMEReplace the following variables:
-
BACKUP_NAME: name for thisBackupCRD. For example,my-backup-1. -
BACKUP_PLAN_NAME: name for thisBackupPlanCRD. For example,my-backup-plan-1. -
DBCLUSTER_NAME: name of your database cluster that you defined in Create a cluster .
-
-
If you're using Ansible, create a playbook for your
BackupCRD.- name : BACKUP_PLAYBOOK_NAME hosts : localhost vars : ansible_user : ANSIBLE_USER ansible_ssh_private_key_file : ANSIBLE_SSH_PRIVATE_KEY_FILE ansible_become : true roles : - role : google.alloydbomni_orchestrator.backupReplace the following variables:
-
BACKUP_PLAYBOOK_NAME: name of your Ansible playbook. For example,My Backup. -
ANSIBLE_USER: OS user that Ansible uses to log into your AlloyDB Omni nodes. -
ANSIBLE_SSH_PRIVATE_KEY_FILE: private key Ansible uses to connect to your AlloyDB Omni nodes using SSH.
-
-
Apply your
BackupCRD.alloydbctlalloydbctl apply -d " DEPLOYMENT_SPEC " -r " BACKUP_CRD "Replace the following variables:
-
DEPLOYMENT_SPEC: path to the deployment specification you created in Install AlloyDB Omni components . -
BACKUP_CRD: path to theBackupCRD you created in step one.
Ansible
ansible-playbook BACKUP_PLAYBOOK -i " DEPLOYMENT_SPEC " \ -e resource_spec = " BACKUP_CRD "Replace the following variables:
-
BACKUP_PLAYBOOK: path to the playbook that you created for yourBackupCRD in step two. -
DEPLOYMENT_SPEC: path to the deployment specification you created in Install AlloyDB Omni components . -
BACKUP_CRD: path to theBackupCRD you created in step one.
-
-
Confirm that the status field,
status.phase, for yourBackupCRD isSucceeded. If the CRD has not succeeded, wait until it is.alloydbctlalloydbctl get -d " DEPLOYMENT_SPEC " -t Backup -n BACKUP_NAME -o yamlAnsible
ansible-playbook status.yaml -i " DEPLOYMENT_SPEC " -e resource_type = Backup \ -e resource_name = BACKUP_NAME -
Confirm that the backup files landed in your Cloud Storage bucket by searching your bucket for
/backup/db.
Delete a backup
To delete a backup, run one of the following commands:
alloydbctl
alloydbctl
delete
-d
" DEPLOYMENT_SPEC
"
-t
Backup
-n
BACKUP_NAME
Replace the following variables:
-
DEPLOYMENT_SPEC: path to the deployment specification you created in Install AlloyDB Omni components . -
BACKUP_NAME: name of theBackupCRD to delete.
Ansible
-
Create a playbook for deleting the
BackupCRD.- name : BACKUP_DELETE_PLAYBOOK_NAME hosts : localhost vars : ansible_user : ANSIBLE_USER ansible_ssh_private_key_file : ANSIBLE_SSH_PRIVATE_KEY_FILE ansible_become : true roles : - role : google.alloydbomni_orchestrator.deleteReplace the following variables:
-
Delete Backup: name of your Ansible playbook. -
ANSIBLE_USER: OS user that Ansible uses to log into your AlloyDB Omni nodes. -
ANSIBLE_SSH_PRIVATE_KEY_FILE: private key Ansible uses to connect to your AlloyDB Omni nodes using SSH.
-
-
Run
ansible-playbookto delete theBackupCRD.ansible-playbook DELETE_BACKUP_PLAYBOOK -i " DEPLOYMENT_SPEC " -e resource_type = Backup \ -e resource_name = BACKUP_NAMEReplace the following variables:
-
DELETE_BACKUP_PLAYBOOK: path to the playbook that you created for deleting theBackupCRD in the previous step. -
DEPLOYMENT_SPEC: path to the deployment specification you created in Install AlloyDB Omni components . -
BACKUP_NAME: name of theBackupCRD to delete.
-
Restore from a backup
To restore data from a backup into your database cluster, complete one of the following sets of instructions:
-
Restore in a high availability cluster.
-
Restore in a standalone cluster.
High availability cluster
To restore data for a highly available database cluster, complete the following instructions:
-
If
availability.enableAutoFailoverandavailability.enableAutoHealare set totruein yourDBClusterspecification file, set them tofalse.DBCluster : metadata : my-db-cluster name : spec : databaseVersion : 18.1.0 mode : "" availability : ... enableAutoFailover : false enableAutoHeal : false ... -
Identify the primary node by displaying the contents of the
db-rolefile on each database node. The primary node containsDATABASE_ROLE_PRIMARY.sudo cat /var/lib/alloydbomni/nm/kvstore/db-roleTo automate this process for multiple nodes and output the results to your control node, see the following shell script.
SSH_USER = SSH_USER DB_NODES = " DB_NODES " SSH_OPTIONS = " SSH_OPTIONS " DB_ROLE = /var/lib/alloydbomni/nm/kvstore/db-role for node in $DB_NODES ; do ssh $SSH_OPTIONS ${ SSH_USER } @ ${ node } "hostname ; sudo cat ${ DB_ROLE } ; echo" doneReplace the following variables:
-
SSH_USER: SSH user used to connect to your database nodes. -
DB_NODES: space-separated list of the hostnames or IP addresses of your database nodes. -
SSH_OPTIONS: SSH options that you use to connect to your database nodes. For example,"-o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=5".
-
-
Stop the AlloyDB Omni service on all database nodes.
sudo systemctl stop alloydbomni18 -
On each standby node, delete the contents of the data directory.
sudo rm -rf PGDATA_DIRReplace
PGDATA_DIRwith the path to the data directory. This is the value defined in theprimarySpec.resources.disksfield of yourDBClusterresource with the nameDataDisk. -
On the primary node, execute the
pgbackrestcommand to restore from a backup. The example shows executing by switching to thepostgresuser.sudo -u postgres pgbackrest restore \ --log-level-console = info \ --stanza = db \ --delta \ --target-action = promote \ --type = immediate \ --set = BACKUP_IDReplace
BACKUP_IDwith the backup identifier. You can find this value in thestatus.backupIDfield of theBackupCRD. -
Start the AlloyDB Omni service on the primary node.
sudo systemctl start alloydbomni18 -
Confirm that the AlloyDB Omni service status is
active. If it not active, then wait for it to be active.sudo systemctl status alloydbomni18 -
Start the AlloyDB Omni service on all standby nodes.
sudo systemctl start alloydbomni18 -
Confirm that the AlloyDB Omni service on each standby node is
active. If they're not active, wait for them to be active. -
If you modified either
availability.enableAutoFailoveroravailability.enableAutoHeal, then revert them to their previous values.
Standalone cluster
-
Stop the AlloyDB Omni service and mask it to prevent restarts.
sudo systemctl stop alloydbomni18sudo systemctl mask alloydbomni18 -
Run the
pgbackrestcommand to restore from a backup.sudo -u postgres pgbackrest restore \ --log-level-console = info \ --stanza = db \ --delta \ --target-action = promote \ --type = immediate \ --set = BACKUP_IDReplace
BACKUP_IDwith the backup identifier. -
Unmask and start the AlloyDB Omni service.
sudo systemctl unmask alloydbomni18sudo systemctl start alloydbomni18 -
Verify that the service is running.
sudo systemctl status alloydbomni18
Limitations
The following limitations apply:
-
Only Cloud Storage buckets are supported to back up your data and restore from it.
-
BackupCRD supports creating backups of type"full". The other types,"incr"and"diff", are not supported. -
Scheduled backups are not supported. To configure scheduled backups, automate the creation of
Backupspecifications using an automation system of your choice. -
Automatic restore is not supported. You must follow the manual instructions to restore your data.
-
To delete backups, delete the
BackupCRD.

