Restoring Outside Crunchy Bridge

The cb CLI tool includes the ability to generate credentials for access to PGBackrest base backups and WAL files to use for creating a new replica of your database on a self-hosted server.

This example starts with a base Alma Linux 8.6 image.

  1. Install PostgreSQL - The major PostgreSQL version that is being restored to needs to match the major PostgreSQL version from which the backup was made. The backup in this case is using PostgreSQL 14. Appropriate installers and/or repositories can be found here on the PostgreSQL download page. This example restores a PostgreSQL 14 backup onto a server running Alma Linux 8.6:
# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Disable the Alma default PostgreSQL modules:
sudo yum -y module disable postgresql

# Install PostgreSQL and PGBackrest:
sudo yum install -y postgresql14-server pgbackrest
  1. Create PGBackrest config via cb CLI tool:
$ cb backup token --format=pgbackrest wmb5md6hm5avjfc7zqs4hr63xq > /etc/pgbackrest.conf
  1. The PGBackrest backup stanza is the first line of the generated configuration. Retrieve that and then list backups to ensure connectivity:
$ export STANZA="$(head -n1 < /etc/pgbackrest.conf  | sed -E 's/\[(.*)\]/\1/g')"
$ pgbackrest info --stanza=$STANZA
stanza: untz7xp4xnhtlf774im4jzfzyi
    status: ok
    cipher: none

    db (current)
        wal archive min/max (14): 000000010000000000000001/000000010000000000000004

        full backup: 20220606-142020F
            timestamp start/stop: 2022-06-06 09:20:20 / 2022-06-06 09:21:32
            wal start/stop: 000000010000000000000002 / 000000010000000000000003
            database size: 25.3MB, database backup size: 25.3MB
            repo1: backup set size: 4.8MB, backup size: 4.8MB
  1. Begin restore of backup stanza to target directory:
$ export STANZA="$(head -n1 < /etc/pgbackrest.conf  | sed -E 's/\[(.*)\]/\1/g')"
$ pgbackrest restore --stanza=$STANZA --pg1-path=/var/lib/pgsql/14/data/ --archive-mode=off

💡Hint

  • To restore the backup and remain in recovery mode as a hot standby after startup, use the --type=standby option.
  • To restore to a specific point in time use --type=time --target='2022-06-01 16:00:00+00
  1. Ensure proper configuration of Postgres and its extensions. Of note:
    1. The restored conf.d folder has server or instance-specific configurations that may no longer apply to the restored instance.
    2. Any extensions that are required by the database should also be installed. Some extensions are not available outside of Crunchy Bridge (ie, pgpodman) and so should be removed from shared_preload_libraries.
  2. Start the instance. Once recovery is complete the instance will become available.
sudo systemctl start postgresql-14