按需备份
KubeBlocks 支持按需备份。你可以通过指定 --method
来自定义备份方法。本文档以使用备份工具和卷快照为例。
备份工具
下面使用 xtrabackup
备份方法,创建名为 mybackup
的备份。
- kbcli
- kubectl
# 创建备份
kbcli cluster backup mysql-cluster --name mybackup --method xtrabackup
>
Backup mybackup created successfully, you can view the progress:
kbcli cluster list-backups --name=mybackup -n default
# 查看备份
kbcli cluster list-backups --name=mybackup -n default
>
NAME NAMESPACE SOURCE-CLUSTER METHOD STATUS TOTAL-SIZE DURATION CREATE-TIME COMPLETION-TIME EXPIRATION
mybackup default mysql-cluster xtrabackup Completed 4426858 2m8s Oct 30,2023 15:19 UTC+0800 Oct 30,2023 15:21 UTC+0800
# 创建备份
kubectl apply -f - <<-'EOF'
apiVersion: dataprotection.kubeblocks.io/v1alpha1
kind: Backup
metadata:
name: mybackup
namespace: default
annotations:
dataprotection.kubeblocks.io/connection-password: Bw1cR15mzfldc9hzGuK4m1BZQOzha6aBb1i9nlvoBdoE9to4
spec:
backupMethod: xtrabackup
backupPolicyName: mysql-cluster-mysql-backup-policy
EOF
# 查看备份
kubectl get backup mybackup
>
NAME POLICY METHOD REPO STATUS TOTAL-SIZE DURATION CREATION-TIME COMPLETION-TIME EXPIRATION-TIME
mybackup mysql-cluster-mysql-backup-policy xtrabackup my-repo Completed 4426858 2m8s 2023-10-30T07:19:21Z 2023-10-30T07:21:28Z
备注
annotations 中的 dataprotection.kubeblocks.io/connection-password
使用原集群的密码。
卷快照备份
使用云盘快照创建备份的方式与以上命令类似,只需将对应 YAML 中的 backupMethod
或者 kbcli 命令中的 --method
参数设置为 volume-snapshot
即可。
- kbcli
- kubectl
# 创建备份
kbcli cluster backup mysql-cluster --name mybackup --method volume-snapshot
>
Backup mybackup created successfully, you can view the progress:
kbcli cluster list-backups --name=mybackup -n default
# 查看备份
kbcli cluster list-backups --name=mybackup -n default
>
NAME NAMESPACE SOURCE-CLUSTER METHOD STATUS TOTAL-SIZE DURATION CREATE-TIME COMPLETION-TIME EXPIRATION
mybackup default mysql-cluster volume-snapshot Completed 4426858 2m8s Oct 30,2023 15:19 UTC+0800 Oct 30,2023 15:21 UTC+0800
将对应 YAML 中的 backupMethod
参数设置为 volume-snapshot
。
# 创建备份
kubectl apply -f - <<-'EOF'
apiVersion: dataprotection.kubeblocks.io/v1alpha1
kind: Backup
metadata:
name: mybackup
namespace: default
spec:
backupMethod: volume-snapshot
backupPolicyName: mycluster-mysql-backup-policy
EOF
# 查看备份
kubectl get backup mybackup
>
NAME POLICY METHOD REPO STATUS TOTAL-SIZE DURATION CREATION-TIME COMPLETION-TIME EXPIRATION-TIME
mybackup mycluster-mysql-backup-policy volume-snapshot my-repo Completed 4426858 2m8s 2023-10-30T07:19:21Z 2023-10-30T07:21:28Z