Topologies
Operations
Backup And Restores
Custom Secret
Monitoring
This guide demonstrates how to create and validate full backups for a MySQL cluster deployed on KubeBlocks using XtraBackup through both Backup API and Ops API. The Ops API is essentially a wrapper around the Backup API, offering enhanced control and progress monitoring capabilities for backup operations.
We will cover how to restore data from a backup in the Restore From Full Backup guide.
Before proceeding, ensure the following:
kubectl create ns demo
namespace/demo created
KubeBlocks uses a declarative approach for managing MySQL clusters. Below is an example configuration for deploying a MySQL cluster with 2 nodes (1 primary, 1 replicas) in semi-synchronous mode.
Cluster Configuration
kubectl apply -f - <<EOF
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: example-mysql-cluster
namespace: demo
spec:
clusterDef: mysql
topology: semisync
terminationPolicy: WipeOut
componentSpecs:
- name: mysql
serviceVersion: 8.0.35
replicas: 2
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
volumeClaimTemplates:
- name: data
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
EOF
Key Notes:
terminationPolicy: WipeOut
:
terminationPolicy: Delete
, which retains backup data even after the cluster is deleted.Monitor the cluster status until it transitions to Running:
kubectl get cluster example-mysql-cluster -n demo
Example Output:
NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE
example-mysql-cluster mysql Delete Running 36m
List available backup policies and schedules for the cluster:
# List backup policies
kubectl get backuppolicy -n demo
# List backup schedules
kubectl get backupschedule -n demo
Expected Output:
NAME BACKUP-REPO STATUS AGE
example-mysql-cluster-mysql-backup-policy Available 58m
NAME STATUS AGE
example-mysql-cluster-mysql-backup-schedule Available 60m
View supported backup methods in the BackupPolicy CR 'example-mysql-cluster-mysql-backup-policy':
kubectl get backuppolicy example-mysql-cluster-mysql-backup-policy -n demo -oyaml
Available Methods:
The following sections demonstrate how to perform a full backup using the 'xtrabackup' method.
Execute a full backup using the 'xtrabackup' method defined in the backup policy:
kubectl apply -f - <<EOF
apiVersion: dataprotection.kubeblocks.io/v1alpha1
kind: Backup
metadata:
name: example-mysql-cluster-backup
namespace: demo
spec:
# Specifies the backup method name that is defined in the backup policy.
# - xtrabackup
# - volume-snapshot
backupMethod: xtrabackup
backupPolicyName: example-mysql-cluster-mysql-backup-policy
# Determines whether the backup contents stored in the backup repository should be deleted when the backup custom resource(CR) is deleted. Supported values are 'Retain' and 'Delete'.
# - 'Retain' means that the backup content and its physical snapshot on backup repository are kept.
# - 'Delete' means that the backup content and its physical snapshot on backup repository are deleted.
deletionPolicy: Delete
EOF
Check the backup status until it shows 'Completed':
kubectl get backup example-mysql-cluster-backup -n demo -w
Example Output:
NAME POLICY METHOD REPO STATUS TOTAL-SIZE DURATION DELETION-POLICY CREATION-TIME COMPLETION-TIME EXPIRATION-TIME
example-mysql-cluster-backup example-mysql-cluster-mysql-backup-policy xtrabackup s3-repo Running Delete 2025-03-07T01:39:05Z
example-mysql-cluster-backup example-mysql-cluster-mysql-backup-policy xtrabackup s3-repo Completed 1524515 18s Delete 2025-03-07T01:39:05Z 2025-03-07T01:39:23Z
Verify the backup files in the configured S3 bucket:
aws s3 ls s3://kubeblocks-backup-repo/ --recursive
Example Output:
2025-03-07 09:39:10 1524515 demo/example-mysql-cluster-cb1b0f47-e310-4f63-9537-dacb6cbac499/mysql/example-mysql-cluster-backup/example-mysql-cluster-backup.xbstream.zst
2025-03-07 09:39:20 5642 demo/example-mysql-cluster-cb1b0f47-e310-4f63-9537-dacb6cbac499/mysql/example-mysql-cluster-backup/kubeblocks-backup.json
Execute a full backup using the 'xtrabackup' method defined in the backup policy:
kubectl apply -f - <<EOF
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: example-mysql-cluster-backup
namespace: demo
spec:
clusterName: example-mysql-cluster
force: false
backup:
backupPolicyName: example-mysql-cluster-mysql-backup-policy
backupMethod: xtrabackup
deletionPolicy: Delete
retentionPeriod: 1mo
type: Backup
EOF
Execute the following command to monitor the backup operation status in real-time:
kubectl get ops example-mysql-cluster-backup -n demo -w
Expected Output:
NAME TYPE CLUSTER STATUS PROGRESS AGE
example-mysql-cluster-backup Backup example-mysql-cluster Succeed -/- 3m34s
Check the final backup status with:
kubectl get backup -n demo -w
Example Output:
NAME POLICY METHOD REPO STATUS TOTAL-SIZE DURATION DELETION-POLICY CREATION-TIME COMPLETION-TIME EXPIRATION-TIME
backup-demo-example-mysql-cluster-20250307013939 example-mysql-cluster-mysql-backup-policy xtrabackup s3-repo Completed 1549449 18s Delete 2025-03-07T01:39:39Z 2025-03-07T01:39:57Z 2025-04-06T01:39:57Z
Verify the backup files in the configured S3 bucket:
aws s3 ls s3://kubeblocks-backup-repo/ --recursive
Example Output:
2025-03-07 09:39:44 1549449 demo/example-mysql-cluster-cb1b0f47-e310-4f63-9537-dacb6cbac499/mysql/backup-demo-example-mysql-cluster-20250307013939/backup-demo-example-mysql-cluster-20250307013939.xbstream.zst
2025-03-07 09:39:54 5529 demo/example-mysql-cluster-cb1b0f47-e310-4f63-9537-dacb6cbac499/mysql/backup-demo-example-mysql-cluster-20250307013939/kubeblocks-backup.json
This guide demonstrated how to: