KubeBlocks supports configuring scheduled backups for clusters.
Modify the backup field with kubectl as follows.
kubectl edit cluster -n default mycluster
Edit the cluster YAML.
spec:...backup:# Whether to enable automatic backupsenabled:true# UTC timezone, the example below stands for 2 A.M. every MondaycronExpression:018***# Use xtrabackup for backups. If your storage supports snapshot, you can change it to volume-snapshotmethod:xtrabackup# Whether to enable PITRpitrEnabled:false# Retention period for a backup setretentionPeriod:7d# BackupReporepoName:my-repo
In the above YAML file, you can set whether to enable automatic backups and PITR as needed, and also specify backup methods, repo names, retention periods, etc.
--backup-enabled indicates whether to enable scheduled backups.
--backup-method specifies the backup method. You can use the kbcli cluster describe-backup-policy mycluster command to view the supported backup methods.
--backup-repo-name specifies the name of the BackupRepo.
--backup-retention-period specifies the retention period for backups, which is 7 days in the example.
--backup-cron-expression specifies the backup schedule using a cron expression in UTC timezone. Refer to cron for the expression format.
After the scheduled backup is enabled, execute the following command to check if a CronJob object has been created:
kubectl get cronjob
>
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
96523399-mycluster-default-xtrabackup 0 18 * * * False 0 <none> 57m
You can also execute the following command to view cluster information, where the Data Protection: section displays the configuration details of automatic backups.