Back Up and Restore PostgreSQL Snapshots

Use the existing PostgreSQL snapshot from your source Virtual Appliance to perform a backup and restore operation on the destination Virtual Appliance. This process will delete the existing Persistent Volume Claims (PVCs) on the destination Virtual Appliance and replace them with the data from the source Virtual Appliance.

Back Up a PostgreSQL Snapshot

Back up the PostgreSQL data on your source Virtual Appliance by creating a PostgreSQL database snapshot.
  1. Log in to the source Virtual Appliance and run this command:
    1. Create a new snapshot.
      CODE
      appdcli run pg_backup create-snapshot repo3
      Sample Output:
      CODE
      create-snapshot started. Status='backup-20251017062950'

      To view the details of the backup file, run this command:

      CODE
      kubectl get pg-backup -n postgres
      Sample Output:
      CODE
      NAME                              CLUSTER         REPO    DESTINATION   STATUS      TYPE   COMPLETED   AGE
      appd-postgres-backup-nh8b-x4m6z   appd-postgres   repo1                 Succeeded   full   5d13h       5d13h
      backup-20251017062950             appd-postgres   repo3                 Succeeded   incr   3m58s       4m8s
      Note: Do not delete the PVCs in the source Virtual Appliance.
    2. Verify whether the PostgreSQL pods are running in the source Virtual Appliance.
      CODE
      kubectl get pods -npostgres
      Sample Output:
      CODE
      NAME                                     READY   STATUS      RESTARTS   AGE
      appd-postgres-backup-vnml-db8nj          0/1     Completed   0          11m
      appd-postgres-instance-8689-0            4/4     Running     0          5d13h
      appd-postgres-instance-lk4k-0            4/4     Running     0          5d13h
      appd-postgres-instance-m6c2-0            4/4     Running     0          5d13h
      appd-postgres-pgbouncer-b98d7d6b-4f5gp   2/2     Running     0          5d13h
      appd-postgres-pgbouncer-b98d7d6b-bxcmg   2/2     Running     0          5d13h
      appd-postgres-pgbouncer-b98d7d6b-wprx4   2/2     Running     0          5d13h
      appd-postgres-repo-host-0                2/2     Running     0          5d13h

      A default folder is created at /mnt/nfs_share on the NFS server.

  2. Log in to the NFS server and view the backup files.
    CODE
    /mnt/nfs_share# ls -ltr

    Sample Output:

    CODE
    drwxrwxrwx 4 root root 4096 Oct 11 16:26 postgres-appd-postgres-repo3-pvc-576f9c74-c24b-4e2d-9768-8185127ea2d7
    To view the contents in the backup file, run this command:
    CODE
    ls -ltr <Backup-of-PostgreSQL-Folder-VA>
    Sample Output:
    CODE
    drwxr-x--- 3 26 tape 4096 Oct 11 17:19 archive
    drwxr-x--- 3 26 tape 4096 Oct 11 17:19 backup

Restore a PostgreSQL Snapshot

Restore the PostgreSQL snapshot on the destination Virtual Appliance:
  1. Log in to the destination Virtual Appliance and run this command:
    CODE
    appdcli run pg_backup create-snapshot repo3
    Sample Output:
    CODE
    create-snapshot started. Status='backup-20251017062951'
  2. Log in to you NFS server and copy the backup file from your source Virtual Appliance:
    1. Remove the backup file contents on your destination Virtual Appliance.
      CODE
      rm -rf <Backup-of-PostgreSQL-Folder-Destination-VA>/*
    2. Copy the source Virtual Appliance backup file contents to destination Virtual Appliance.
      CODE
      cp -r <Backup-of-PostgreSQL-Folder-Source-VA>/* <Backup-of-PostgreSQL-Folder-Destination-VA>
    3. Update the access and owner permissions for the backup file of the destination Virtual Appliance.
      CODE
      chmod g+rw <Backup-of-PostgreSQL-Folder-Destination-VA> -R
      chown 26:26 <Backup-of-PostgreSQL-Folder-Destination-VA> -R
      Verify the file contents of the copied backup file on the NFS server and Kubernetes Cluster.
      CODE
      kubectl exec -it appd-postgres-repo-host-0 -npostgres -c pgbackrest -- ls -ltr pgbackrest/repo3/backup/db
      Sample Output:
      CODE
      total 8
      drwxrwx--- 3 postgres postgres 4096 Oct 11 17:19 archive
      drwxrwx--- 3 postgres postgres 4096 Oct 11 17:19 backup
  3. Log in to the destination Virtual Appliance console.
    1. Pause the percona pg cluster.
      JSON
      kubectl patch perconapgcluster appd-postgres -n postgres --type='merge' -p '{"spec":{"pause":true}}'
    2. Delete PVCs in the PostgreSQL.
      CODE
      kubectl delete pvc -n postgres -l postgres-operator.crunchydata.com/data=postgres
    3. Restore the PostgreSQL snapshot.
      CODE
      appdcli run pg_backup restore-snapshot repo3
    4. Resume the percona pg cluster.
      JSON
      kubectl patch perconapgcluster appd-postgres -n postgres --type='merge' -p '{"spec":{"pause":false}}'
    5. Verify the pods to check the PostgreSQL instance.
      CODE
      kubectl get pods -npostgres

      Sample Output:

      CODE
      NAME                                     READY   STATUS      RESTARTS   AGE
      appd-postgres-backup-nh8b-t6qmc          0/1     Completed   0          19m
      appd-postgres-instance-8689-0            4/4     Running     0          90s
      appd-postgres-instance-lk4k-0            4/4     Running     0          90s
      appd-postgres-instance-m6c2-0            4/4     Running     0          96s
      appd-postgres-pgbouncer-b98d7d6b-4f5gp   2/2     Running     0          96s
      appd-postgres-pgbouncer-b98d7d6b-bxcmg   2/2     Running     0          96s
      appd-postgres-pgbouncer-b98d7d6b-wprx4   2/2     Running     0          96s
      appd-postgres-repo-host-0                2/2     Running     0          2m3s
    Note:

    After restoring PostgreSQL on the destination Virtual Appliance, the Controller UI displays the data from the Virtual Appliance. Log in to the Controller UI to verify that it displays the correct data.

    Once the destination Virtual Appliance is ready, redirect the traffic from the source Virtual Appliance to this destination Virtual Appliance.