Backup & Restore

Database backup and recovery are vital functions for ensuring data security and business continuity. By regularly backing up the database, data can be quickly restored in the event of data loss, corruption, or operational errors, thereby minimizing business disruption and data loss.

Prerequisites

Before performing a backup, please declare storage location. You may choose one of the following two methods.

  • Persistent Volume Claim (PVC, Kubernetes PersistentVolumeClaim): A persistent volume claim encapsulates the request configuration for storage resources and automatically matches suitable persistent volumes in the cluster based on the requested access mode, storage size, and other information.

  • External S3 Storage: S3 (Amazon Simple Storage Service) is an object storage service provided by Amazon. If you need to back up data to your own S3 bucket, please confirm with the administrator that the S3 storage has been integrated into your project.

Procedure

CLI
Web Console
  1. Configure Storage Location
  • Using PVC for storage
kubectl patch mysql -n <namespace> <name> --type='merge' --patch '
spec:
  pxc:
    backup:
      storages:
        <storageName>:
          type: filesystem
          volume:
            persistentVolumeClaim:
              accessModes:
                - ReadWriteOnce
              resources:
                requests:
                  storage: <size>Gi
              storageClassName: <storageClass>
  • Using S3 for storage Create S3 secret
kubectl -n <namespace> create secret generic <backupSecretName> --from-literal=AWS_ACCESS_KEY_ID=$(accessKeyId) --from-literal=AWS_SECRET_ACCESS_KEY=$(secretAccessKey)

Configure S3 storage

kubectl patch mysql -n $namespace $name --type='merge' --patch '
spec:
  pxc:
    backup:
      storages:
        <storageName>:
          type: s3
          s3:
            bucket: <bucket>
            credentialsSecret: <backupSecretName>
            endpointUrl: <endpointUrl>
  1. Automatic Backup Add the automatic backup configuration in the CR's spec.pxc.backup, where the schedule field defines the backup cycle. The <storageName> field refers to the backup storage name created in Step 1.
kubectl patch mysql -n $namespace $name --type='merge' --patch '
spec:
  pxc:
    backup:
      schedule:
      - keep: 5
        name: daily-backup
        schedule: 0 0 * * *
        storageName: <storageName>
'
  1. Manual Backup
kubectl -n <namespace> apply -f - <<EOF
apiVersion: pxc.percona.com/v1
kind: PerconaXtraDBClusterBackup
metadata:
  labels:
    cluster: <name>
    trigger.type: manual
  name: <backupName>
  namespace: <namespace>
spec:
  pxcCluster: <name>
  storageName: <storageName>
EOF
  1. Check Backup Status
kubectl get PerconaXtraDBClusterBackup -n <namespace> <backupName> 
  1. Restore Using Backup
apiVersion: pxc.percona.com/v1
kind: PerconaXtraDBClusterRestore
metadata:
  labels:
    cluster: <name>
  name: <restoreName>
  namespace: <namespace>
spec:
  backupName: <backupName>
  pxcCluster: <name>
EOF