Scheduled backup
KubeBlocks supports configuring scheduled backups for clusters.
- kbcli
- kubectl
kbcli cluster update mysql-cluster --backup-enabled=true \
--backup-method=xtrabackup --backup-repo-name=my-repo \
--backup-retention-period=7d --backup-cron-expression="0 18 * * *"
--backup-enabled
indicates whether to enable scheduled backups.--backup-method
specifies the backup method. You can use thekbcli cluster describe-backup-policy mysql-cluster
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.
Modify the backup field with kubectl as follows.
kubectl edit cluster -n default mysql-cluster
>
spec:
...
backup:
# Whether to enable automatic backups
enabled: true
# UTC timezone, the example below stands for 2 A.M. every Monday
cronExpression: 0 18 * * *
# Use xtrabackup for backups. If your storage supports snapshot, you can change it to volume-snapshot
method: xtrabackup
# Whether to enable PITR
pitrEnabled: false
# Retention period for a backup set
retentionPeriod: 7d
# BackupRepo
repoName: 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.
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-mysql-cluster-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.
kbcli cluster describe mysql-cluster
>
...
Data Protection:
BACKUP-REPO AUTO-BACKUP BACKUP-SCHEDULE BACKUP-METHOD BACKUP-RETENTION
my-repo Enabled 0 18 * * * xtrabackup 7d