Operations
Backup And Restores
Custom Secret
tpl
This guide demonstrates two methods to restore a MongoDB cluster from backup in KubeBlocks:
Before proceeding, ensure the following:
kubectl create ns demo
namespace/demo created
Before restoring, ensure that there is a full backup available. The restoration process will use this backup to create a new MongoDB cluster.
Completed
stateFind available full backups:
kubectl get backup -n demo -l dataprotection.kubeblocks.io/backup-type=Full,app.kubernetes.io/instance=mongo-cluster # get the list of full backups
Pick ONE of the Backups whose status is Completed
.
Create a new cluster with restore configuration:
Key parameters:
kubeblocks.io/restore-from-backup
annotationapiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: mongo-cluster-restored
namespace: demo
annotations:
# NOTE: replace <FULL_BACKUP_NAME> with your backup
kubeblocks.io/restore-from-backup: '{"mongodb":{"name":"<FULL_BACKUP_NAME>","namespace":"demo","volumeRestorePolicy":"Parallel"}}'
spec:
terminationPolicy: Delete
clusterDef: mongodb
topology: replicaset
componentSpecs:
- name: mongodb
serviceVersion: "6.0.16"
replicas: 3
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
Track restore progress with:
# Watch restore status
kubectl get restore -n demo -w
# Watch cluster status
kubectl get cluster -n demo -w
Create restore request via OpsRequest API:
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: mongo-cluster-restore
namespace: demo
spec:
clusterName: mongo-cluster-restored
force: false
restore:
backupName: <FULL_BACKUP_NAME>
backupNamespace: demo
type: Restore
Monitor restore status:
# Watch restore status
kubectl get restore -n demo -w
# Watch cluster status
kubectl get cluster -n demo -w
Confirm successful restoration:
kubectl get cluster mongo-cluster-restored -n demo
Example Output:
NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE
mongo-cluster-restored mongodb Delete Running 3m3s
To remove all created resources, delete the MongoDB cluster along with its namespace:
kubectl delete cluster mongo-cluster -n demo
kubectl delete cluster mongo-cluster-restored -n demo
kubectl delete ns demo
This guide covered two restoration methods:
Cluster Annotation - Simple YAML-based approach
OpsRequest API - Enhanced operational control