Backup and Restore

Function Introduction

Provides storage-based physical backup and restore capabilities to ensure data security. It supports manually triggering backups and restoring to new instances.

Procedure

CLI
Web Console

Configure Backup Storage

# Example: Configure backup storage for instance 'my-pg-instance'
kubectl patch postgresql my-pg-instance -n my-namespace --type='merge' -p '
spec:
  backup:
    retainDay: 7
    storage:
      name: my-s3-config
      bucket: my-backup-bucket
      namespace: storage-namespace
'

Create Backup

# Example: Create a backup named 'my-backup' for cluster 'my-pg-cluster'
cat <<EOF | kubectl create -f -
apiVersion: middleware.alauda.io/v1
kind: PostgresBackup
metadata:
  name: my-backup
  namespace: my-namespace
spec:
  cluster: my-pg-cluster
  executeNode: my-pg-cluster-0  # Optional: Specify the pod to execute the backup
EOF

View Backup Status

kubectl get postgresbackup <backup-name> -n <namespace> -o yaml

Restore Database

cat <<EOF | kubectl create -f -
apiVersion: middleware.alauda.io/v1
kind: PostgresRestore
metadata:
  name: <restore-instance-name>
  namespace: <namespace>
spec:
  backupCluster:
    name: <backup-pg-cluster-name>
    uid: <backup-pg-cluster-uid>
    storage:
      name: <storage-name>
      namespace: <storage-namespace>
      bucket: <s3-bucket-name>
  targetCluster: |
    apiVersion: acid.zalan.do/v1
    kind: postgresql
    metadata:
      name: <new-instance-name>
      namespace: <new-instance-namespace>
    spec:
      enableExporter: true
      enablePgpool2: false
      numberOfInstances: 2
      postgresql:
        version: "14"
      resources:
        limits:
          cpu: "1"
          memory: 2Gi
        requests:
          cpu: "1"
          memory: 2Gi
      teamId: ACID
      volume:
        size: 20Gi
        storageClass: sc-topolvm
  timestamp: "2023-07-26T14:36:38+00:00"  # Point-in-time to restore
EOF

Backup Status Description

Descriptions of backup status fields:

FieldDescription
backupNameBackup file name
clusterUidUnique identifier for the cluster
configBackupStorageBackup storage configuration
executeNodeNode executing the backup
finishLsnLSN position at the end of the backup
finishTimeTime when the backup is completed
lastModifiedLast modified time of the backup
pgVersionPostgreSQL version
startLsnLSN position at the start of the backup
startTimeTime when the backup starts
stateBackup status

Precautions

  1. The backup storage configuration must be completed before creating a backup.
  2. The restore operation will create a new PostgreSQL instance.
  3. Backups will be automatically deleted after the retention period expires.
  4. Do not perform write operations on the source cluster during the restore process.
  5. Ensure that the storage class of the target cluster is compatible with that of the source cluster.
  6. Verify sufficient storage space is available before initiating backups.
  7. Test restore procedures regularly to ensure backup validity.
  8. Consider enabling backup encryption for sensitive data.