1. Introduction
This codelab shows how to configure pgBackRest to back up and restore an AlloyDB Omni RPM deployment using S3-compatible object storage.
Note: In this codelab, you deploy a standalone MinIO binary on the VM to act as a local, lightweight S3-compatible storage endpoint for tutorial and testing purposes. For production workloads, always use a supported, actively maintained S3-compatible storage solution or cloud object storage.
Prerequisites
- Access to a Google Cloud Project and Cloud Shell from Cloud Console.
- Google Cloud SDK (
gcloud) installed and configured.
What you'll learn
- How to set up a Compute Engine VM for AlloyDB Omni RPM.
- How to set up a local S3-compatible object storage server on the VM.
- How to configure pgBackRest to use S3-compatible object storage as a backup repository.
- How to perform, list, and verify backups.
- How to restore data from a backup.
What you'll need
- Obtain a URL link to AlloyDB Omni RPMs. The links are sent to your email which includes the repository URL server. Initialize the following environment variable to keep the URL ready to use during the codelab.
export ALLOYDB_OMNI_REPOSITORY_URL="..." - A working terminal with access to Google Cloud. You can use Cloud Shell for this purpose.
2. Setup and Requirements
Project setup
Create a Google Cloud Project
- In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
- Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.
Start Cloud Shell
Although you can operate Google Cloud remotely from your laptop, in this codelab you use the Google Cloud Shell, a command-line environment running in the cloud.

- Open the Google Cloud console and click the Cloud Shell icon on the top right toolbar.You can also open the Cloud Shell in one of the following ways:
- If you're using the Google Cloud console, press G and then S.
- Click this link.
It typically takes a few moments to provision and connect to the environment. When this operation completes, you see something similar to the following:
{: width="624"}
3. Create the Compute Engine VM
In this section, you create a single Compute Engine (GCE) virtual machine (VM) using the gcloud command-line tool. You use a Rocky Linux 9 image, which is fully compatible with AlloyDB Omni RPMs.
- Define environment variables for your project ID, VM name, machine type, zone, and region.
export PROJECT="your-project-id" export INSTANCE_NAME="alloydb-omni-pgbackrest" export MACHINE_TYPE="e2-standard-4" export ZONE="us-central1-c" export REGION="us-central1" - Sign in with using your Google Cloud account user, and configure the default project.
gcloud auth login gcloud config set project $PROJECT - Create a firewall rule to allow SSH connections to your VM.
gcloud compute firewall-rules create allow-ssh-alloydb-omni \ --project=$PROJECT \ --direction=INGRESS \ --action=allow \ --rules=tcp:22 \ --source-ranges="0.0.0.0/0" - Since the VM is created without a public IP address, configure a Cloud Router and Cloud NAT gateway to let the VM access external package repositories and download required software.
gcloud compute routers create alloydb-omni-router \ --project=$PROJECT \ --network=default \ --region=$REGION gcloud compute routers nats create alloydb-omni-nat \ --project=$PROJECT \ --router=alloydb-omni-router \ --region=$REGION \ --nat-all-subnet-ip-ranges \ --auto-allocate-nat-external-ips - Ensure that your VPC network has a valid default internet gateway route. In some shared or playground environments, default routes are occasionally removed by cleanup scripts. This route is required for Cloud NAT to forward outbound traffic to the internet.
gcloud compute routes create default-internet-route \ --project=$PROJECT \ --network=default \ --destination-range=0.0.0.0/0 \ --next-hop-gateway=default-internet-gateway - Create the Compute Engine VM instance with Rocky Linux 9 and a 20GB balanced persistent disk. For enhanced security, use the
--no-addressflag so the VM is not assigned a public IP address.gcloud compute instances create $INSTANCE_NAME \ --project=$PROJECT \ --zone=$ZONE \ --machine-type=$MACHINE_TYPE \ --image-family=rocky-linux-9 \ --image-project=rocky-linux-cloud \ --boot-disk-size=20GB \ --boot-disk-type=pd-balanced \ --no-address - After the VM is created, verify the VM's status.
gcloud compute instances list --filter="name=$INSTANCE_NAME" --project=$PROJECT
4. Set up S3-compatible object storage
In this section, you connect to your VM, prepare the environment, and set up a local S3-compatible object storage server (minio) along with an S3 client (mc) to host your backup bucket.
- Connect to the VM over SSH using Identity-Aware Proxy (IAP). Since the VM doesn't have a public IP address,
gcloudwill automatically tunnel the SSH connection through IAP.gcloud compute ssh $INSTANCE_NAME --zone=$ZONE --project=$PROJECT --tunnel-through-iap - Install
policycoreutils-python-utilspackage so that the SELinux policy can be configured later if needed.sudo dnf install -y policycoreutils-python-utils - Download the S3-compatible server binary (
minio).curl -L -o minio \ https://github.com/minio/minio/releases/download/RELEASE.2024-05-10T01-41-38Z/minio.linux-amd64.RELEASE.2024-05-10T01-41-38Z chmod +x minio sudo mv minio /usr/local/bin/ - Create a data directory for the object storage server.
sudo mkdir -p /var/lib/s3-storage/data - Start the S3-compatible server in the background with example credentials. Note that the secret key must be at least 8 characters long.
export MINIO_ROOT_USER="s3admin" export MINIO_ROOT_PASSWORD="s3password" nohup sudo env MINIO_ROOT_USER="$MINIO_ROOT_USER" \ MINIO_ROOT_PASSWORD="$MINIO_ROOT_PASSWORD" \ /usr/local/bin/minio server /var/lib/s3-storage/data \ --console-address ":9001" \ > s3-server.log 2>&1 & - Verify that the S3-compatible server is running.
ps aux | grep minio - Download and install the S3 client (
mc) to manage buckets.curl -L -o mc \ https://github.com/minio/mc/releases/download/RELEASE.2024-05-09T17-04-24Z/mc.linux-amd64.RELEASE.2024-05-09T17-04-24Z chmod +x mc sudo mv mc /usr/local/bin/ - Configure the S3 client alias (
s3repo) and create a bucket namedalloydb-backups.mc alias set s3repo http://localhost:9000 s3admin s3password mc mb s3repo/alloydb-backups
5. Install AlloyDB Omni
In this section, you install and configure AlloyDB Omni.
- Define environment variables on the VM for the data directory, your AlloyDB Omni repository URL, and a strong password for the PostgreSQL
postgresadministrator user. Replace the URL with the one you received from the signup form. Note: Passing passwords using environment variables on the command line (e.g.,export PGDATA="/var/lib/alloydbomni" export ALLOYDB_OMNI_REPOSITORY_URL="..." export PGPASSWORD="YourStrongPassword123!"PGPASSWORD=$PGPASSWORD) is used here for simplicity in the codelab, but it can expose the password in process listings. In production, use more secure methods such as a.pgpassfile or a secret manager. - Create the data directory where AlloyDB Omni will store its database files.
sudo mkdir -p $PGDATA - Configure the YUM repository on your VM by creating the repository configuration file.
sudo tee /etc/yum.repos.d/alloydbomni.repo << EOF [alloydbomni] name=alloydbomni baseurl=$ALLOYDB_OMNI_REPOSITORY_URL enabled=1 repo_gpgcheck=0 gpgcheck=1 gpgkey=https://dl.google.com/linux/linux_signing_key.pub EOF - Update the YUM cache.
sudo yum makecache - Install version 18 of the AlloyDB Omni RPM package.
sudo dnf install -y alloydbomni18 - Initialize the AlloyDB Omni database instance.
sudo PGPASSWORD=$PGPASSWORD PGDATA=$PGDATA /usr/lib/postgresql/18/bin/alloydbomni18-setup initdb - Temporarily disable SELinux enforcing mode to facilitate setup, as per standard codelab practices.
sudo setenforce 0 - Prepare the AlloyDB Omni database instance.
sudo PGPASSWORD=$PGPASSWORD PGDATA=$PGDATA /usr/lib/postgresql/18/bin/alloydbomni18-setup preparedb - Enable and start the AlloyDB Omni
systemdservice.sudo systemctl enable alloydbomni18 sudo systemctl start alloydbomni18 - Verify that the AlloyDB Omni service is active and running successfully.
sudo systemctl status alloydbomni18
6. Configure pgBackRest
In this section, you install pgBackRest from the AlloyDB Omni Common repository, configure /etc/pgbackrest/pgbackrest.conf to use your S3-compatible object storage bucket as a backup repository, and enable WAL archiving in AlloyDB Omni.
- Define an environment variable on the VM for your AlloyDB Omni Common repository URL. Replace the URL with the one you received from the signup form.
export ALLOYDB_OMNI_COMMON_REPOSITORY_URL="..." - Configure the pgBackRest YUM repository and install
pgbackrest-2.58.0.sudo tee /etc/yum.repos.d/pgbackrest.repo <<EOF [pgbackrest] name=Google Alloydb Omni Orchestrator baseurl=$ALLOYDB_OMNI_COMMON_REPOSITORY_URL enabled=1 repo_gpgcheck=0 gpgcheck=0 gpgkey=https://dl.google.com/linux/linux_signing_key.pub EOF sudo dnf install -y pgbackrest-2.58.0 - Create the spool and log directories for pgBackRest and assign ownership to the
postgresuser.sudo mkdir -p /var/log/pgbackrest sudo mkdir -p /var/lib/pgbackrest sudo chown -R postgres:postgres /var/log/pgbackrest sudo chown -R postgres:postgres /var/lib/pgbackrest - Create
/etc/pgbackrest/pgbackrest.confand configure strict file permissions.sudo mkdir -p /etc/pgbackrest/conf.d sudo tee /etc/pgbackrest/pgbackrest.conf <<EOF [global] spool-path=/var/lib/pgbackrest lock-path=/var/lib/pgbackrest # S3 Repository details repo1-type=s3 repo1-s3-endpoint=http://localhost:9000 repo1-s3-bucket=alloydb-backups repo1-s3-key=s3admin repo1-s3-key-secret=s3password repo1-s3-region=us-east-1 repo1-s3-uri-style=path repo1-path=/pgbackrest # Retention policy repo1-retention-full=3 repo1-retention-full-type=count repo1-retention-diff=16 # Force immediate checkpoint during backup start start-fast=y # Logging log-path=/var/log/pgbackrest log-level-console=info log-level-file=info # Compression compress-type=zst # Asynchronous WAL archiving archive-async=y archive-push-queue-max=1024MB archive-get-queue-max=256MB archive-missing-retry=y [global:archive-push] process-max=2 [global:archive-get] process-max=2 [omni] pg1-user=postgres pg1-socket-path=/tmp pg1-path=$PGDATA EOF sudo chown postgres:postgres /etc/pgbackrest/pgbackrest.conf sudo chmod 640 /etc/pgbackrest/pgbackrest.conf - Initialize the pgBackRest stanza as the
postgresuser. Confirm thatsudo -u postgres pgbackrest --stanza=omni stanza-createstanza-create command end: completed successfullyis shown in the output. - Configure AlloyDB Omni archiving parameters using
psql.sudo -u postgres /usr/lib/postgresql/18/bin/psql \ -c "ALTER SYSTEM SET archive_mode = 'on';" \ -c "ALTER SYSTEM SET archive_command = 'pgbackrest --stanza=omni archive-push %p';" \ -c "ALTER SYSTEM SET wal_level = 'replica';" \ -c "ALTER SYSTEM SET max_wal_senders = 10;" - Restart the AlloyDB Omni service to apply the archiving changes.
sudo systemctl restart alloydbomni18 - Verify pgBackRest configuration integrity and connectivity.
Confirm thatsudo -u postgres pgbackrest --stanza=omni checkcheck command end: completed successfullyis shown in the output.
7. Perform Backup
In this section, you use pgBackRest to perform a full backup and a differential backup of your AlloyDB Omni database to S3-compatible object storage.
- Trigger a full backup using
pgbackrest.sudo -u postgres pgbackrest \ --stanza=omni \ --type=full backup - Trigger a differential backup using
pgbackrest. Note: Other supported backup types includesudo -u postgres pgbackrest \ --stanza=omni \ --type=diff backupincr(incremental).
8. List and Verify Backups
In this section, you list the backups and verify that they completed successfully.
- List the backups using the
pgbackrest infocommand. Confirm that the output showssudo -u postgres pgbackrest \ --stanza=omni infostatus: okalong with backup information for each backup command you executed:- Full backup:
full backup:(for example,F 20260908-093545F) - Diff backup:
diff backup:(for example,F_ D 20260908-093545F_20260908-094016D)
- Full backup:
- Verify the backup files stored in the bucket using the S3 client (
mc). You should seemc ls s3repo/alloydb-backups/pgbackrest/backup,archive, andstanza.infoin the output.
9. Restore Data from Backup
In this section, you stop the AlloyDB Omni database service and restore data from a specific backup using pgbackrest.
Caution: Restoring stops your database and overwrites all of your database data.
- Define an environment variable for the backup ID that you want to restore from. Replace the value with the backup ID shown in your
pgbackrest infooutput.export BACKUPID="20260908-093545F" - Stop the AlloyDB Omni service and verify that it is inactive.
Confirm that the output showssudo systemctl stop alloydbomni18 sudo systemctl status alloydbomni18Active: inactive. - Run
pgbackrest restorewith the--deltaoption to restore the database from the selected backup. Confirm thatsudo -u postgres pgbackrest \ --stanza=omni \ --set=$BACKUPID \ --delta restorerestore command end: completed successfullyis shown in the output. - Start the AlloyDB Omni service and verify that it is active and running.
Confirm that the output showssudo systemctl start alloydbomni18 sudo systemctl status alloydbomni18Active: active (running).
10. Cleanup and Survey
After you finish the codelab, you can clean up the Google Cloud resources to avoid incurring unwanted charges.
- Disconnect from your SSH session on the VM to return to your local Cloud Shell terminal.
exit - Delete the Compute Engine VM instance.
gcloud compute instances delete $INSTANCE_NAME --zone=$ZONE --project=$PROJECT --quiet - Delete the firewall rule created for SSH access.
gcloud compute firewall-rules delete allow-ssh-alloydb-omni --project=$PROJECT --quiet - Delete the Cloud NAT gateway and Cloud Router.
gcloud compute routers nats delete alloydb-omni-nat --router=alloydb-omni-router --region=$REGION --project=$PROJECT --quiet gcloud compute routers delete alloydb-omni-router --region=$REGION --project=$PROJECT --quiet - Delete the custom route.
gcloud compute routes delete default-internet-route --project=$PROJECT --quiet
11. Congratulations
Congratulations on completing the codelab! You successfully configured pgBackRest to back up and restore an AlloyDB Omni RPM deployment using S3-compatible object storage.
What we've covered
- How to set up a Compute Engine VM for AlloyDB Omni RPM.
- How to set up an S3-compatible object storage bucket.
- How to configure pgBackRest with an S3-compatible repository.
- How to perform, list, and verify full and differential backups.
- How to restore data from a backup using pgBackRest.
For more information, see the AlloyDB Omni overview.