当前位置:网站首页>使用 BR 备份 TiDB 集群到 GCS
使用 BR 备份 TiDB 集群到 GCS
2022-07-06 21:09:00 【添香小铺】
本文介绍如何将运行在 Kubernetes 上的 TiDB 集群数据备份到 Google Cloud Storage (GCS) 上。
本文使用的备份方式基于 TiDB Operator 的 Custom Resource Definition (CRD) 实现,底层使用 BR 获取集群数据,然后再将数据上传到远端 GCS。BR 全称为 Backup & Restore,是 TiDB 分布式备份恢复的命令行工具,用于对 TiDB 集群进行数据备份和恢复。
使用场景
如果你对数据备份有以下要求,可考虑使用 BR 将 TiDB 集群数据以 Ad-hoc 备份或定时全量备份的方式备份到 GCS 上:
- 需要备份的数据量较大(大于 1 TB),而且要求备份速度较快
- 需要直接备份数据的 SST 文件(键值对)
如有其他备份需求,请参考备份与恢复简介选择合适的备份方式。
注意
- BR 只支持 TiDB v3.1 及以上版本。
- 使用 BR 备份出的数据只能恢复到 TiDB 数据库中,无法恢复到其他数据库中。
Ad-hoc 备份
Ad-hoc 备份支持全量备份与增量备份。
要进行 Ad-hoc 备份,你需要创建一个自定义的 Backup custom resource (CR) 对象来描述本次备份。创建好 Backup 对象后,TiDB Operator 根据这个对象自动完成具体的备份过程。如果备份过程中出现错误,程序不会自动重试,此时需要手动处理。
本文档假设对部署在 Kubernetes test1 这个 namespace 中的 TiDB 集群 demo1 进行数据备份。下面是具体的操作过程。
第 1 步:准备 Ad-hoc 备份环境
下载文件 backup-rbac.yaml,并执行以下命令在
test1这个 namespace 中创建备份需要的 RBAC 相关资源:kubectl apply -f backup-rbac.yaml -n test1授予远程存储访问权限。
参考 GCS 账号授权,授权访问 GCS 远程存储。
如果你使用的 TiDB 版本低于 v4.0.8,你还需要完成以下步骤。如果你使用的 TiDB 为 v4.0.8 及以上版本,请跳过这些步骤。
确保你拥有备份数据库
mysql.tidb表的SELECT和UPDATE权限,用于备份前后调整 GC 时间。创建
backup-demo1-tidb-secretsecret 用于存放访问 TiDB 集群的 root 账号和密钥。kubectl create secret generic backup-demo1-tidb-secret --from-literal=password=<password> --namespace=test1
第 2 步:备份数据到 GCS
创建
BackupCR,将数据备份到 GCS:kubectl apply -f backup-gcs.yamlbackup-gcs.yaml文件内容如下:--- apiVersion: pingcap.com/v1alpha1 kind: Backup metadata: name: demo1-backup-gcs namespace: test1 spec: # backupType: full # Only needed for TiDB Operator < v1.1.10 or TiDB < v4.0.8 from: host: ${tidb-host} port: ${tidb-port} user: ${tidb-user} secretName: backup-demo1-tidb-secret br: cluster: demo1 clusterNamespace: test1 # logLevel: info # statusAddr: ${status-addr} # concurrency: 4 # rateLimit: 0 # checksum: true # sendCredToTikv: true # options: # - --lastbackupts=420134118382108673 gcs: projectId: ${project_id} secretName: gcs-secret bucket: ${bucket} prefix: ${prefix} # location: us-east1 # storageClass: STANDARD_IA # objectAcl: private在配置
backup-gcs.yaml文件时,请参考以下信息:- 自 v1.1.6 版本起,如果需要增量备份,只需要在
spec.br.options中指定上一次的备份时间戳--lastbackupts即可。有关增量备份的限制,可参考使用 BR 进行备份与恢复。 .spec.br中的一些参数是可选的,例如logLevel、statusAddr等。完整的.spec.br字段的详细解释,请参考 BR 字段介绍。spec.gcs中的一些参数为可选项,如location、objectAcl、storageClass。GCS 存储相关配置参考 GCS 存储字段介绍。- 如果你使用的 TiDB 为 v4.0.8 及以上版本, BR 会自动调整
tikv_gc_life_time参数,不需要配置spec.tikvGCLifeTime和spec.from字段。 - 更多
BackupCR 字段的详细解释,请参考 Backup CR 字段介绍。
- 自 v1.1.6 版本起,如果需要增量备份,只需要在
创建好
BackupCR 后,TiDB Operator 会根据BackupCR 自动开始备份。你可以通过以下命令查看备份状态:kubectl get bk -n test1 -owide
备份示例
备份全部集群数据
备份单个数据库的数据
备份单张表的数据
使用表库过滤功能备份多张表的数据
定时全量备份
用户通过设置备份策略来对 TiDB 集群进行定时备份,同时设置备份的保留策略以避免产生过多的备份。定时全量备份通过自定义的 BackupSchedule CR 对象来描述。每到备份时间点会触发一次全量备份,定时全量备份底层通过 Ad-hoc 全量备份来实现。下面是创建定时全量备份的具体步骤:
第 1 步:定时全量备份环境准备
第 2 步:定时备份数据到 GCS
创建
BackupScheduleCR,开启 TiDB 集群的定时全量备份,将数据备份到 GCS:kubectl apply -f backup-schedule-gcs.yamlbackup-schedule-gcs.yaml文件内容如下:--- apiVersion: pingcap.com/v1alpha1 kind: BackupSchedule metadata: name: demo1-backup-schedule-gcs namespace: test1 spec: #maxBackups: 5 #pause: true maxReservedTime: "3h" schedule: "*/2 * * * *" backupTemplate: # Only needed for TiDB Operator < v1.1.10 or TiDB < v4.0.8 from: host: ${tidb_host} port: ${tidb_port} user: ${tidb_user} secretName: backup-demo1-tidb-secret br: cluster: demo1 clusterNamespace: test1 # logLevel: info # statusAddr: ${status-addr} # concurrency: 4 # rateLimit: 0 # checksum: true # sendCredToTikv: true gcs: secretName: gcs-secret projectId: ${project_id} bucket: ${bucket} prefix: ${prefix} # location: us-east1 # storageClass: STANDARD_IA # objectAcl: private从以上
backup-schedule-gcs.yaml文件配置示例可知,backupSchedule的配置由两部分组成。一部分是backupSchedule独有的配置,另一部分是backupTemplate。- 关于
backupSchedule独有的配置项具体介绍,请参考 BackupSchedule CR 字段介绍。 backupTemplate用于指定集群及远程存储相关的配置,字段和 Backup CR 中的spec一样,详细介绍可参考 Backup CR 字段介绍。
- 关于
定时全量备份创建完成后,通过以下命令查看备份的状态:
kubectl get bks -n test1 -owide查看定时全量备份下面所有的备份条目:
kubectl get bk -l tidb.pingcap.com/backup-schedule=demo1-backup-schedule-gcs -n test1
边栏推荐
- CMB's written test - quantitative relationship
- Native MySQL
- What is Ba? How about Ba? What is the relationship between Ba and Bi?
- Ubuntu 20 installation des enregistrements redisjson
- Top 50 hit industry in the first half of 2022
- 运算放大器应用汇总1
- 维护万星开源向量数据库是什么体验
- When QT uses qtooltip mouse to display text, the picture of the button will also be displayed and the prompt text style will be modified
- 【安全攻防】序列化与反序列,你了解多少?
- 海思3559万能平台搭建:RTSP实时播放的支持
猜你喜欢

Probability formula

Codeworks 5 questions per day (1700 average) - day 7

你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?

20. (ArcGIS API for JS) ArcGIS API for JS surface collection (sketchviewmodel)

U.S. Air Force Research Laboratory, "exploring the vulnerability and robustness of deep learning systems", the latest 85 page technical report in 2022

API data interface of A-share index component data

List interview common questions

22.(arcgis api for js篇)arcgis api for js圆采集(SketchViewModel)

22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)

Basic concepts of Huffman tree
随机推荐
Class常量池与运行时常量池
未来发展路线确认!数字经济、数字化转型、数据...这次会议很重要
qt-线程等01概念
二叉搜索树的实现
ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
Kbone与小程序跨端开发的一些思考
Flutter3.0, the applet is not only run across mobile applications
How to customize the shortcut key for latex to stop running
20. (ArcGIS API for JS) ArcGIS API for JS surface collection (sketchviewmodel)
. Net interface can be implemented by default
代码质量管理
海思万能平台搭建:颜色空间转换YUV2RGB
Native MySQL
24. (ArcGIS API for JS) ArcGIS API for JS point modification point editing (sketchviewmodel)
枚举通用接口&枚举使用规范
API data interface of A-share index component data
红米k40s root玩机笔记
Top 50 hit industry in the first half of 2022
Probability formula
Kotlin Android environment construction