Select a documentation version: <button class="button button-with-icon cloud-select-dropdown__button button-primary" aria-haspopup="true">15.5.5</button>

- [Current (18.4.0)](https://docs.cloud.google.com/alloydb/omni/containers/current/docs/restore-pgbackrest.md.txt)
- [18.4.0](https://docs.cloud.google.com/alloydb/omni/containers/18.4.0/docs/restore-pgbackrest.md.txt)
- [18.3.0](https://docs.cloud.google.com/alloydb/omni/containers/18.3.0/docs/restore-pgbackrest.md.txt)
- [18.1.0](https://docs.cloud.google.com/alloydb/omni/containers/18.1.0/docs/restore-pgbackrest.md.txt)
- [17.10.0](https://docs.cloud.google.com/alloydb/omni/containers/17.10.0/docs/restore-pgbackrest.md.txt)
- [17.9.0](https://docs.cloud.google.com/alloydb/omni/containers/17.9.0/docs/restore-pgbackrest.md.txt)
- [17.7.0](https://docs.cloud.google.com/alloydb/omni/containers/17.7.0/docs/restore-pgbackrest.md.txt)
- [17.5.0](https://docs.cloud.google.com/alloydb/omni/containers/17.5.0/docs/restore-pgbackrest.md.txt)
- [16.14.0](https://docs.cloud.google.com/alloydb/omni/containers/16.14.0/docs/restore-pgbackrest.md.txt)
- [16.13.0](https://docs.cloud.google.com/alloydb/omni/containers/16.13.0/docs/restore-pgbackrest.md.txt)
- [16.11.0](https://docs.cloud.google.com/alloydb/omni/containers/16.11.0/docs/restore-pgbackrest.md.txt)
- [16.9.0](https://docs.cloud.google.com/alloydb/omni/containers/16.9.0/docs/restore-pgbackrest.md.txt)
- [16.8.0](https://docs.cloud.google.com/alloydb/omni/containers/16.8.0/docs/restore-pgbackrest.md.txt)
- [16.3.0](https://docs.cloud.google.com/alloydb/omni/containers/16.3.0/docs/restore-pgbackrest.md.txt)
- [15.18.0](https://docs.cloud.google.com/alloydb/omni/containers/15.18.0/docs/restore-pgbackrest.md.txt)
- [15.17.0](https://docs.cloud.google.com/alloydb/omni/containers/15.17.0/docs/restore-pgbackrest.md.txt)
- [15.15.0](https://docs.cloud.google.com/alloydb/omni/containers/15.15.0/docs/restore-pgbackrest.md.txt)
- [15.13.0](https://docs.cloud.google.com/alloydb/omni/containers/15.13.0/docs/restore-pgbackrest.md.txt)
- [15.12.0](https://docs.cloud.google.com/alloydb/omni/containers/15.12.0/docs/restore-pgbackrest.md.txt)
- [15.7.1](https://docs.cloud.google.com/alloydb/omni/containers/15.7.1/docs/restore-pgbackrest.md.txt)
- [15.7.0](https://docs.cloud.google.com/alloydb/omni/containers/15.7.0/docs/restore-pgbackrest.md.txt)
- [15.5.5](https://docs.cloud.google.com/alloydb/omni/containers/15.5.5/docs/restore-pgbackrest.md.txt)
- [15.5.4](https://docs.cloud.google.com/alloydb/omni/containers/15.5.4/docs/restore-pgbackrest.md.txt)
- [15.5.2](https://docs.cloud.google.com/alloydb/omni/containers/15.5.2/docs/restore-pgbackrest.md.txt)

<br />

This page shows you how to restore an AlloyDB Omni cluster using a backup created with [pgBackRest](https://pgbackrest.org/), the open-source backup solution included with the AlloyDB Omni Docker container.

<br />

Because AlloyDB Omni is compatible with PostgreSQL,
the data-restoration commands and techniques described by [the pgBackRest manual](https://pgbackrest.org/user-guide-index.html)
apply to AlloyDB Omni as well. This page demonstrates a selection
of common recovery tasks, with examples of relevant commands.

For more information about configuring pgBackRest to work with AlloyDB Omni, see
[Set up pgBackRest for AlloyDB Omni](https://docs.cloud.google.com/alloydb/omni/containers/15.5.5/docs/set-up-pgbackrest.md.txt).


> [!CAUTION]
> The information on this page applies only to AlloyDB Omni for containers. It does not apply to AlloyDB Omni for Kubernetes.

<br />

See [Back up and restore in Kubernetes](https://docs.cloud.google.com/alloydb/omni/containers/15.5.5/docs/backup-kubernetes.md.txt) for Kubernetes-based information.

## Before you begin

Before configuring AlloyDB Omni to work with pgBackrest, you need to have [AlloyDB Omni installed and running](https://docs.cloud.google.com/alloydb/omni/containers/15.5.5/docs/install.md.txt) on a server that you control.

- A target database server, running the same major version of AlloyDB Omni as the backup you want to restore. For more information about installing AlloyDB Omni, see [Install AlloyDB Omni](https://docs.cloud.google.com/alloydb/omni/containers/15.5.5/docs/install.md.txt).

- A pgBackRest backup repository containing at least one backup of the source AlloyDB Omni database.

- Enough free disk space on the target server to hold the restored database.

## Overview

To perform an AlloyDB Omni restore using pgBackRest, run
[the `pgbackrest restore` command](https://pgbackrest.org/command.html#command-restore). The parameters that you
provide the command vary depending upon your situation.

In general, you
run the `pgbackrest restore` command with flags that provide the following information:

- The location of your `pgbackrest.conf` file.
- The name of pgBackRest backup repository that you want to restore to. These repositories are named and defined in the `pgbackrest.conf` file.
- The location on the local file system to write the restored data to.
- An identifier of the particular backup or point in time that you want to restore from.

When running the containerized `pgbackrest restore` commands, remember to use file
system paths from the container's point of view. For example, the path
to your AlloyDB Omni data directory is always `/var/lib/postgresql/data`,
no matter its location on your host server. For more information, see
[A note about file system paths](https://docs.cloud.google.com/alloydb/omni/containers/15.5.5/docs/set-up-pgbackrest.md.txt#paths).

## Perform a point-in-time restore

This example restores data from a pgBackRest repository, naming a particular
point in time to restore to. If you have defined multiple repositories in
the target environment's `pgbackrest.conf` file, then pgBackRest chooses
the repository to restore from based on availability, expected speed, and other factors.

The example assumes the following:

- You have a `pgbackrest.conf` file located at the
  top level of your target AlloyDB Omni data directory. This makes
  the file available to the containerized `pgbackrest` as
  `/var/lib/postgresql/data`.

- [You have enabled continuous backups](https://docs.cloud.google.com/alloydb/omni/containers/15.5.5/docs/set-up-pgbackrest.md.txt#continuous) with your pgBackRest configuration.

1. In the target environment, perform a PITR restore, specifying a timestamp to restore to:

   ### Docker

   ```bash
   docker exec CONTAINER_NAME pgbackrest \
     --config-path=/var/lib/postgresql/data \
     --stanza=STANZA \
     --type=time \
     --pg1-path=/var/lib/postgresql/data/data-RESTORED \
     --target="TIMESTAMP" \
     restore
   ```

   Replace the following:
   - `CONTAINER_NAME`: the name that you assigned to the AlloyDB Omni container when you installed it---for example, `my-omni`.

   - `STANZA`: the configuration stanza, defined by the `pgbackrest.conf` file,
     to apply to this restore---for example, `omni`.

   - `TIMESTAMP`: the time to restore to---for example, `2024-02-22 19:50:00`.

   ### Podman

   ```bash
   podman exec CONTAINER_NAME pgbackrest \
     --config-path=/var/lib/postgresql/data \
     --stanza=STANZA \
     --type=time \
     --pg1-path=/var/lib/postgresql/data/data-RESTORED \
     --target="TIMESTAMP" \
     restore
   ```

   Replace the following:
   - `CONTAINER_NAME`: the name that you assigned to the AlloyDB Omni container when you installed it---for example, `my-omni`.

   - `STANZA`: the configuration stanza, defined by the `pgbackrest.conf` file,
     to apply to this restore---for example, `omni`.

   - `TIMESTAMP`: the time to restore to---for example, `2024-02-22 19:50:00`.

2. On the target environment, stop the container using the following command:

   ### Docker

   ```bash
   docker container stop CONTAINER_NAME
   ```

   ### Podman

   ```bash
   podman container stop CONTAINER_NAME
   ```
3. Rename the `data` subdirectory of your data directory,
   as a safety precaution:

   ```bash
   cd DATA_DIR
   sudo mv data data-OLD
   ```

   Replace `DATA_DIR` with the file system path to your AlloyDB Omni
   data directory.
4. Move the restored data into place, and clean up `postgresql.auto.conf`:

   ```bash
   sudo mv data-RESTORED data
   sudo sed -i 's|data-RESTORED|data|' data/postgresql.auto.conf
   ```
5. Start the AlloyDB Omni container with the database server:

   ### Docker

   ```bash
   docker container start CONTAINER_NAME
   ```

   ### Podman

   ```bash
   podman container start CONTAINER_NAME
   ```

You can now connect to your database using `psql` and confirm that the data
has been restored as you expect. If so, you can delete the `data-OLD` copy
of the `data` subdirectory that you created earlier.

For more information about PITR in pgBackRest, see [Point-in-Time Recovery](https://pgbackrest.org/user-guide.html#pitr).
For more information about preparing
a `pgbackrest.conf` file for use with AlloyDB Omni, see [Set up pgBackRest for AlloyDB Omni](https://docs.cloud.google.com/alloydb/omni/containers/15.5.5/docs/set-up-pgbackrest.md.txt).

## Other options

The `pgbackrest restore` command is very flexible, with an array of options and
features that you can control through passing in different command-line options. These include the following:

- Limiting a restore only to changed files.
- Restoring only selected databases.

For a complete guide to performing restores in pgBackRest, see [Restore](https://pgbackrest.org/user-guide.html#restore).