黄东旭解析 TiDB 的核心优势
440
2024-03-25
Kubernetes 上 TiDB 集群的数据备份到持久卷上。本文描述的持久卷,指任何 Kubernetes 支持的持久卷类型。本文以备份数据到网络文件系统存储为例。
如果你对数据备份有以下要求,可考虑使用 BR 将 TiDB 集群数据以 Ad-hoc 备份(只执行一次)或 定时快照备份(执行多次)的方式备份至持久卷:
需要备份的数据量较大,而且要求备份速度较快
需要直接备份数据的 SST 文件(键值对)
注意
BR 只支持 TiDB v3.1 及以上版本。
使用 BR 备份出的数据只能恢复到 TiDB 数据库中,无法恢复到其他数据库中
d-hoc 备份支持快照备份与增量备份。Ad-hoc 备份通过创建一个自定义的 Backup custom resource (CR) 对象来描述一次备份。TiDB Operator 根据这个 Backup 对象来完成具体的备份过程。如果备份过程中出现错误,程序不会自动重试,此时需要手动处理。
本文档对K8S集群中命名空间为tidb下的lqb数据库集群进行备份,具体操作如下:
---kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata: name: tidb-backup-manager labels: app.kubernetes.io/component: tidb-backup-manager rules: - apiGroups: [""] resources: ["events"] verbs: ["*"] - apiGroups: ["pingcap.com"] resources: ["backups", "restores"] verbs: ["get", "watch", "list", "update"]---kind: ServiceAccount apiVersion: v1 metadata: name: tidb-backup-manager---kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: tidb-backup-manager labels: app.kubernetes.io/component: tidb-backup-manager subjects:- kind: ServiceAccount name: tidb-backup-manager roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: tidb-backup-manager
[root@k8s-master]# kubectl apply -f backup-rbac.yaml -ntidb role.rbac.authorization.k8s.io/tidb-backup-manager created serviceaccount/tidb-backup-manager created rolebinding.rbac.authorization.k8s.io/tidb-backup-manager created
spec: tikv: baseImage: pingcap/tikv replicas: 4 maxFailoverCount: 6#下边是配置tikv挂载nfs additionalVolumes: - name: nfs nfs: server: 172.16.5.194 path: /home/k8s-nfs additionalVolumeMounts: - name: nfs mountPath: /nfs requests: cpu: "6c" storage: 12Gi memory: "400Mi" limits: cpu: "6c" memory: "12Gi" mountClusterClientSecret: false storageClassName: "local-hostpath"
1. 创建备份的自定义资源CR,将数据备份到共享存储卷##以下以备份yz数据库为例[root@k8s-master backup]# cat backup-nfs.yaml---apiVersion: pingcap.com/v1alpha1 kind: Backup metadata: name: demo1-backup-nfs namespace: tidb spec: tableFilter: - "yz.*" br: cluster: yz clusterNamespace: tidb local: prefix: backup-nfs volume: name: nfs nfs: server: 172.16.5.194 path: /home/k8s-nfs volumeMount: name: nfs mountPath: /nfs2. 创建应用配置 [root@k8s-master]# kubectl apply -f backup-nfs.yaml backup.pingcap.com/demo1-backup-nfs created 3.查看备份状态和备份文件 [root@k8s-master]# kubectl get bk -n tidb -owide -w NAME TYPE MODE STATUS BACKUPPATH BACKUPSIZE COMMITTS LOGTRUNCATEUNTIL STARTED COMPLETED AGE demo1-backup-nfs snapshot Running local:///nfs/backup-nfs 57s demo1-backup-nfs snapshot Complete local:///nfs/backup-nfs 2.8 GB 439178019024666631 68s 0s 72s [root@k8s-master]ls /home/k8s-nfs/backup-nfs/de 1 20001 39461 4 backup.lock backupmeta checkpoint.meta checkpoints
---apiVersion: pingcap.com/v1alpha1 kind: Backup metadata: name: demo1-backup-nfs namespace: test1 spec: br: cluster: demo1 clusterNamespace: test1 local: prefix: backup-nfs volume: name: nfs nfs: server: ${nfs_server_ip} path: /home/k8s-nfs volumeMount: name: nfs mountPath: /nfs
---apiVersion: pingcap.com/v1alpha1 kind: Backup metadata: name: demo1-backup-nfs namespace: test1 spec: tableFilter: - "db1.*" br: cluster: demo1 clusterNamespace: test1 local: prefix: backup-nfs volume: name: nfs nfs: server: ${nfs_server_ip} path: /home/k8s-nfs volumeMount: name: nfs mountPath: /nfs
---apiVersion: pingcap.com/v1alpha1 kind: Backup metadata: name: demo1-backup-nfs namespace: test1 spec: tableFilter: - "db1.table1" br: cluster: demo1 clusterNamespace: test1 local: prefix: backup-nfs volume: name: nfs nfs: server: ${nfs_server_ip} path: /home/k8s-nfs volumeMount: name: nfs mountPath: /nfs
---apiVersion: pingcap.com/v1alpha1 kind: Backup metadata: name: demo1-backup-nfs namespace: test1 spec: tableFilter: - "db1.table1" - "db1.table2" br: cluster: demo1 clusterNamespace: test1 local: prefix: backup-nfs volume: name: nfs nfs: server: ${nfs_server_ip} path: /home/k8s-nfs volumeMount: name: nfs mountPath: /nfs
[root@k8s-master backup]# kubectl get bks -n tidb -owide NAME SCHEDULE MAXBACKUPS LASTBACKUP LASTBACKUPTIME AGE demo1-backup-schedule-nfs */2 * * * * 9s NAME SCHEDULE MAXBACKUPS LASTBACKUP LASTBACKUPTIME AGE demo1-backup-schedule-nfs */2 * * * * 46s demo1-backup-schedule-nfs */2 * * * * demo1-backup-schedule-nfs-2024-02-02t10-16-00 6s 89s demo1-backup-schedule-nfs */2 * * * * demo1-backup-schedule-nfs-2024-02-02t10-18-00 6s 3m29s demo1-backup-schedule-nfs */2 * * * * demo1-backup-schedule-nfs-2024-02-02t10-20-00 6s 5m29s demo1-backup-schedule-nfs */2 * * * * demo1-backup-schedule-nfs-2024-02-02t10-22-00 6s 7m29s demo1-backup-schedule-nfs */2 * * * * demo1-backup-schedule-nfs-2024-02-02t10-24-00 6s 9m29s [root@k8s-master ~]# ls /home/k8s-nfs/backup-nfs/yz-pd.tidb-2379-2024-02-02t10-16-00/ 1 20001 39461 4 backup.lock backupmeta checkpoint.meta checkpoints
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。