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
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:
Field | Description |
---|
backupName | Backup file name |
clusterUid | Unique identifier for the cluster |
configBackupStorage | Backup storage configuration |
executeNode | Node executing the backup |
finishLsn | LSN position at the end of the backup |
finishTime | Time when the backup is completed |
lastModified | Last modified time of the backup |
pgVersion | PostgreSQL version |
startLsn | LSN position at the start of the backup |
startTime | Time when the backup starts |
state | Backup status |
Precautions
- The backup storage configuration must be completed before creating a backup.
- The restore operation will create a new PostgreSQL instance.
- Backups will be automatically deleted after the retention period expires.
- Do not perform write operations on the source cluster during the restore process.
- Ensure that the storage class of the target cluster is compatible with that of the source cluster.
- Verify sufficient storage space is available before initiating backups.
- Test restore procedures regularly to ensure backup validity.
- Consider enabling backup encryption for sensitive data.