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

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

<br />

This page shows you how to manually clone a database cluster in a single server using a local backup.

<br />

The steps on this page assume that the source Kubernetes database cluster is created on Google Kubernetes Engine, and the backup disks are Compute Engine persistent disks. It also assumes that the target AlloyDB Omni single server is installed on a Compute Engine virtual machine (VM).

If you use other environments, refer to the respective documentation to replicate these steps in your environment.

The following workflow explains the cloning steps:

1. Identify the backup disk information, such as the persistent volume name and Compute Engine persistent disk handler, for source database cluster backup disk.
2. Mount the backup disk of the source database cluster to the target server.
3. Use `pgBackRest` commands to verify source backups can be accessed.
4. Use `pgBackRest` commands to restore the backup to the target database cluster.

## Before you begin

- Make sure you have access to the backup disk where your source database cluster backup is stored.
- A single server target AlloyDB Omni database cluster is created. For more information about installing AlloyDB Omni on Kubernetes, see [Install AlloyDB Omni](https://docs.cloud.google.com/alloydb/omni/containers/17.5.0/docs/quickstart.md.txt).
- Ensure you are logged in to the database as the `postgres` user.

## Get source backup disk information

As part of the restore process, determine the backup disk Persistent Volume Claim (PVC) name for your source database cluster. PVCs are used within Kubernetes to manage persistent storage for applications.

The following sample commands help determine the underlying PV name and the Compute Engine persistent disk handler using the backup disk PVC name.

1. Connect to your GKE cluster where you have created the AlloyDB Omni source database cluster:

   ```bash
    kubectl get pvc -n DB_CLUSTER_NAMESPACE | grep DB_CLUSTER_NAME | grep backupdisk
   ```

   Replace the following:
   - `DB_CLUSTER_NAMESPACE`: the Kubernetes namespace for this
     backup. It must match the namespace of the database cluster.

   - `DB_CLUSTER_NAME`: the name of this database cluster---for
     example, `my-db-cluster`.

   The following is the sample response.

   ````bash
     backupdisk-al-fe8c-dbcluster-sample-0   Bound
     pvc-36d8f05d-ef1a-4750-ac01-9bb330c15b3a   10Gi       RWO            standard-rwo   5d21h
     ```
   ````
2. Use the backup disk name from the previous step---for example, `backupdisk-al-fe8c-dbcluster-sample-0`, to find the underlying PV name:

   ```bash
     kubectl get pvc/PVC_NAME -n DB_CLUSTER_NAMESPACE -o jsonpath={.spec.volumeName}
   ```

   Replace the following:
   - `PVC_NAME`: the PVC name of the backup disk from response in the previous step---for example `backupdisk-al-fe8c-dbcluster-sample-0`.
3. Find the underlying Compute Engine persistent disk handler:

   ```bash
     kubectl get pv/$PV_NAME -o json | jq -r .spec.csi.volumeHandle
   ```

   Replace the following:
   - `PV_NAME`: the PV name of the backup disk from response in the previous step.

   The following is the sample response:

   ```bash
     projects/my-project/zones/us-central1-a/disks/pvc-89f91fba-6cd2-4bfa-84ed-cb5969b446c3
   ```
4. Export the backup disk name as a variable used in the next sections:

   ```bash
     export BACKUP_DISK=pvc-89f91fba-6cd2-4bfa-84ed-cb5969b446c3
   ```

## Mount the backup disk to the target server

Assuming that the target server is an AlloyDB Omni server installed on a Compute Engine virtual machine, mount the backup disk to the server.

1. Run the `gcloud compute instances attach-disk` command to mount the disk:

   ```bash
     gcloud compute instances attach-disk GCE_INSTANCE_NAME \
     --disk ${BACKUP_DISK} \
     --zone=$GCE_ZONE
   ```

   Replace the following:
   - `GCE_INSTANCE_NAME`: the name of the instance where your target server is installed in Compute Engine virtual machine.

   - `GCE_ZONE`: the zone where your Compute Engine virtual machine instance exists.

2. Mount the backup disk to the target server:

   ```bash
      lsblk
      mkdir -p /mnt/disks/backupdisk
      mount -o discard,defaults /dev/sdb /mnt/disks/backupdisk
   ```
3. Add a custom bind mount to the AlloyDB Omni `dataplane.conf` file in the `/var/alloydb/config` directory:

   ```bash
     PG_BIND_MOUNTS=/mnt/disks/backupdisk:/mnt/disks/backups:rshared
   ```

For more information about bind mounts in docker, see [Bind mounts](https://docs.docker.com/storage/bind-mounts/).

1. Restart the target server:

### Docker

```bash
  docker restart CONTAINER_NAME
```

Replace `CONTAINER_NAME` with the name of a new AlloyDB Omni container---for example, `my-omni-1`.

### Podman

```bash
  podman restart CONTAINER_NAME
```

Replace `CONTAINER_NAME` with the name of a new AlloyDB Omni container---for example, `my-omni-1`.

## Update the `pgBackRest` configuration file

Update the existing `pgBackRest` file in the backup disk directory with the new repository path.

1. In the target server, go to the `/mnt/disks/backupdisk` directory:

   ```bash
     cd /mnt/disks/backupdisk
   ```
2. Update the `pg1-path` path to a temporary directory in the `pgbackrest.conf` file to avoid overwriting the existing data. The `data-restored` directory is created automatically as part of the restore process:

   ```bash
     sudo sed -i 's|.*pg1-path.*|pg1-path=/mnt/disks/pgsql/data-restored|' pgbackrest.conf
   ```
3. Update the `repo1-path` path to a temporary directory in the `pgbackrest.conf` file:

   ```bash
     sudo sed -i 's|.*repo1-path.*|repo1-path=/mnt/disks/backups/repo|' conf.d/repo1-local-backupplan.conf
   ```

## Verify source backups in target database cluster

Sign in to the target server, and run `pgBackRest` commands to verify that the source database cluster backups are accessible on the target server:

### Docker

```bash
  sudo docker exec CONTAINER_NAME pgbackrest --config-path=/mnt/disks/backups --stanza=db --repo=1 info
```

### Podman

```bash
  sudo podman exec CONTAINER_NAME pgbackrest --config-path=/mnt/disks/backups --stanza=db --repo=1 info
```

The following is a sample response:

        stanza: db
        status: ok
        cipher: none
        db (current)
            wal archive min/max (15): 000000010000000000000002/00000001000000000000000D
            full backup: 20240213-231400F
                timestamp start/stop: 2024-02-13 23:14:00+00 / 2024-02-13 23:17:14+00
                wal start/stop: 000000010000000000000003 / 000000010000000000000003
                database size: 38.7MB, database backup size: 38.7MB
                repo1: backup set size: 4.6MB, backup size: 4.6MB
            incr backup: 20240213-231400F_20240214-000001I
                timestamp start/stop: 2024-02-14 00:00:01+00 / 2024-02-14 00:00:05+00
                wal start/stop: 00000001000000000000000D / 00000001000000000000000D
                database size: 38.7MB, database backup size: 488.3KB
                repo1: backup set size: 4.6MB, backup size: 84.2KB
                backup reference list: 20240213-231400F

The timestamps in the response are used either to restore the full backup or to restore
from a point in time from the recovery window.

## Restore the backup in the target server

After you identify the backup or a point in time you want to restore to, run
`pgBackRest` commands in your target server. For more information
about these commands, see [Restore
Command](https://pgbackrest.org/command.html#command-restore).

The following are some sample `pgBackRest` restore commands:

- Restore from a backup

  ```bash
  pgbackrest --config-path=/mnt/disks/backups --stanza=db --repo=1 restore --set=20240213-231400F --type=immediate --target-action=promote --delta --link-all --log-level-console=info
  ```
- Restore from a point in time

  ```bash
  pgbackrest --config-path=/mnt/disks/backups --stanza=db --repo=1 restore --target="2024-01-22 11:27:22" --type=time --target-action=promote --delta --link-all --log-level-console=info
  ```

## Copy data to target server

After the restore command completes successfully, you can copy the data from the `data-restored` temporary directory to the current AlloyDB data directory.

1. In the target server, stop the database service:

   ### Docker

   ```bash
   docker stop CONTAINER_NAME
   ```

   ### Podman

   ```bash
   podman stop CONTAINER_NAME
   ```
2. Rename the current data directory to another name as a best practice:

   ```bash
     mv ~/alloydb-data/data  ~/alloydb-data/data-old
   ```
3. Rename the `data-restored` temporary directory to current data directory:

   ```bash
     mv ~/alloydb-data/data-restored ~/alloydb-data/data
   ```
4. Update `pg1-path` value in the `postgresql.auto.conf` file to load the restored data:

   ```bash
       vim ~/alloydb-data/data/postgresql.auto.conf
       # Verify postgresql.auto.conf.
       # Do not edit this file manually!
       # It will be overwritten by the ALTER SYSTEM command.
       # Recovery settings generated by pgBackRest restore on 2024-03-13 20:47:11
       restore_command = 'pgbackrest --config-path=/mnt/disks/pgsql --pg1-path=/mnt/disks/pgsql/data --repo=1 --stanza=db archive-get %f "%p"'
       recovery_target = 'immediate'
       recovery_target_action = 'promote'
       recovery_target_timeline = 'current'
   ```
5. In the target server, start the database service:

   ### Docker

   ```bash
   docker start CONTAINER_NAME
   ```

   ### Podman

   ```bash
   podman start CONTAINER_NAME
   ```

After the database service starts, you can connect to the primary instance and run queries to verify that the data is restored from the backup. For more information, see [Connect to AlloyDB Omni on a single server](https://docs.cloud.google.com/alloydb/omni/containers/17.5.0/docs/run-connect.md.txt#connect).

## What's next

- [Clone a database cluster in a single server using a Cloud Storage backup](https://docs.cloud.google.com/alloydb/omni/containers/17.5.0/docs/kubernetes-dr-backup-singleserver-gcs.md.txt)