Topologies
Operations
Backup And Restores
Custom Secret
Monitoring
This guide explains how to restore a new MySQL cluster from an existing backup in KubeBlocks. It showcases two methods: using Cluster Annotation or the Ops API.
The Ops API provides enhanced control and progress monitoring capabilities for restore operations, acting as a wrapper around the Cluster Annotation.
Before restoring, ensure that a full backup is available. The restoration process will use this backup to create a new MySQL cluster.
Run the following command to check the backup status:
kubectl get backup -n demo
Expected 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 Completed 1633717 18s Delete 2025-03-07T03:25:22Z 2025-03-07T03:25:40Z
Extract encrypted credentials for system accounts from the backup metadata:
kubectl get backup -n demo example-mysql-cluster-backup -o jsonpath='{.metadata.annotations.kubeblocks\.io/encrypted-system-accounts}'
Expected Output:
{"mysql":{"kbadmin":"+UbL/HmrnDShZCdoZxpAWxTHT48VKrJBhBqnNDjvwscW2YBBj8biYf1REDA=","kbdataprotection":"zycglr6K6oeRpZlZBeFeTUoxGm+eSIC7bNotnz4UmFCLH8O77JsGM9gf3js=","kbmonitoring":"qX66By8D2ZJdMh5Pe9u149Fev4wVyNchi+U9QkDqPsW6hoVrbew/srZUEmE=","kbprobe":"n2VKC65TGg4N1GVr9en6EOZ0MQEf/DyDdQ0qeK9TbMRO2QMaJvKlpW9Bm5w=","kbreplicator":"1BOeBExnprxNshSCAHVGmBQ8dk+72edxQb1P2/2L2hD4M39cRLhoB60nW9Y=","proxysql":"u6NRl02g7+do5z1SVjhLTUYFqNp860wMQ1pfkH1JpsB/RKxIU6Gds2wNu7I=","root":"0YQW649uCaf0QqgAVDMX8OtNbatKYNlZE1aNRD8C2J8a9xHqPi8="}}
Create a new cluster with restoration configuration referencing the backup, set encryptedSystemAccounts
with the encrypted system account credentials got from last step.
Note: Use " to escape double quotes in the JSON string.
kubectl apply -f - <<EOF
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: example-mysql-cluster-restored
namespace: demo
annotations:
kubeblocks.io/restore-from-backup: '{"mysql":{"encryptedSystemAccounts":"{\"kbadmin\":\"+UbL/HmrnDShZCdoZxpAWxTHT48VKrJBhBqnNDjvwscW2YBBj8biYf1REDA=\",\"kbdataprotection\":\"zycglr6K6oeRpZlZBeFeTUoxGm+eSIC7bNotnz4UmFCLH8O77JsGM9gf3js=\",\"kbmonitoring\":\"qX66By8D2ZJdMh5Pe9u149Fev4wVyNchi+U9QkDqPsW6hoVrbew/srZUEmE=\",\"kbprobe\":\"n2VKC65TGg4N1GVr9en6EOZ0MQEf/DyDdQ0qeK9TbMRO2QMaJvKlpW9Bm5w=\",\"kbreplicator\":\"1BOeBExnprxNshSCAHVGmBQ8dk+72edxQb1P2/2L2hD4M39cRLhoB60nW9Y=\",\"proxysql\":\"u6NRl02g7+do5z1SVjhLTUYFqNp860wMQ1pfkH1JpsB/RKxIU6Gds2wNu7I=\",\"root\":\"0YQW649uCaf0QqgAVDMX8OtNbatKYNlZE1aNRD8C2J8a9xHqPi8=\"}"
,"name":"example-mysql-cluster-backup","namespace":"demo","volumeRestorePolicy":"Parallel"}}'
spec:
terminationPolicy: WipeOut
componentSpecs:
- name: mysql
componentDef: "mysql-8.0"
serviceVersion: 8.0.35
disableExporter: false
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
Watch Pod Initialization:
kubectl get pods -n demo -w
Expected Workflow:
restore-preparedata-XXXXX-<hash> 0/1 Init:0/1 0 6s
restore-preparedata-XXXXX-<hash> 1/1 Running 0 12s
restore-preparedata-XXXXX-<hash> 0/1 Completed 0 20s
These pods copy backup data to Persistent Volumes (PVCs).
example-mysql-cluster-restored-mysql-0 0/4 Pending 0 0s
example-mysql-cluster-restored-mysql-0 4/4 Running 0 20s
Pods initialize with restored data and start MySQL services.
Alternatively, use the Ops API to initiate the restoration process:
kubectl apply -f - <<EOF
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: example-mysql-cluster-restore
namespace: demo
spec:
clusterName: example-mysql-cluster-restored
force: false
restore:
backupName: example-mysql-cluster-backup
backupNamespace: demo
type: Restore
EOF
Monitor the progress of the restoration operation:
kubectl get ops example-mysql-cluster-restore -n demo -w
Expected Output:
NAME TYPE CLUSTER STATUS PROGRESS AGE
example-mysql-cluster-restore Restore example-mysql-cluster-restored Running -/- 55s
example-mysql-cluster-restore Restore example-mysql-cluster-restored Succeed -/- 3m3s
After the restoration process is complete, verify the status of the newly restored cluster:
kubectl get cluster example-mysql-cluster-restored -n demo
Expected Output:
NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE
example-mysql-cluster-restored WipeOut Running 3m2s
To remove all created resources, delete the MySQL cluster along with its namespace:
kubectl delete cluster example-mysql-cluster -n demo
kubectl delete cluster example-mysql-cluster-restored -n demo
kubectl delete ns demo
This guide demonstrated how to restore a MySQL cluster from an existing backup using either the Cluster Annotation or Ops API. By following these steps, you can efficiently restore critical data to a new MySQL cluster in KubeBlocks.