当前位置:网站首页>使用 Dumpling 备份 TiDB 集群数据到 GCS
使用 Dumpling 备份 TiDB 集群数据到 GCS
2022-07-06 21:09:00 【添香小铺】
本文档介绍如何将 Kubernetes 上 TiDB 集群的数据备份到 Google Cloud Storage (GCS) 上。本文档中的“备份”,均是指全量备份(即 Ad-hoc 全量备份和定时全量备份)。
本文档介绍的备份方法基于 TiDB Operator(v1.1 及以上)的 CustomResourceDefinition (CRD) 实现,底层使用 Dumpling 工具获取集群的逻辑备份,然后再将备份数据上传到远端 GCS。
Dumpling 是一款数据导出工具,该工具可以把存储在 TiDB/MySQL 中的数据导出为 SQL 或者 CSV 格式,可以用于完成逻辑上的全量备份或者导出。
使用场景
如果你需要将 TiDB 集群数据以 Ad-hoc 全量备份或定时全量备份的方式备份至 GCS,并且对数据备份有以下要求,可使用本文介绍的备份方案:
- 导出 SQL 或 CSV 格式的数据
- 对单条 SQL 语句的内存进行限制
- 导出 TiDB 的历史数据快照
前置条件
使用 Dumpling 备份 TiDB 集群数据到 GCS 前,确保你拥有备份数据库的以下权限:
mysql.tidb表的SELECT和UPDATE权限:备份前后,Backup CR 需要一个拥有该权限的数据库账户,用于调整 GC 时间- SELECT
- RELOAD
- LOCK TABLES
- REPLICATION CLIENT
Ad-hoc 全量备份
Ad-hoc 全量备份通过创建一个自定义的 Backup custom resource (CR) 对象来描述一次备份。TiDB Operator 根据这个 Backup 对象来完成具体的备份过程。如果备份过程中出现错误,程序不会自动重试,此时需要手动处理。
为了更好地描述备份的使用方式,本文档提供如下备份示例。示例假设对部署在 Kubernetes test1 这个 namespace 中的 TiDB 集群 demo1 进行数据备份,下面是具体操作过程。
第 1 步:Ad-hoc 全量备份环境准备
下载文件 backup-rbac.yaml,并执行以下命令在
test1这个 namespace 中创建备份需要的 RBAC 相关资源:kubectl apply -f backup-rbac.yaml -n test1远程存储访问授权。
参考 GCS 账号授权授权访问 GCS 远程存储。
创建
backup-demo1-tidb-secretsecret。该 secret 存放用于访问 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: from: host: ${tidb_host} port: ${tidb_port} user: ${tidb_user} secretName: backup-demo1-tidb-secret gcs: secretName: gcs-secret projectId: ${project_id} bucket: ${bucket} # prefix: ${prefix} # location: us-east1 # storageClass: STANDARD_IA # objectAcl: private # bucketAcl: private # dumpling: # options: # - --threads=16 # - --rows=10000 # tableFilter: # - "test.*" storageClassName: local-storage storageSize: 10Gi以上示例将 TiDB 集群的数据全量导出备份到 GCS。GCS 配置中的
location、objectAcl、bucketAcl、storageClass项均可以省略。GCS 存储相关配置参考 GCS 存储字段介绍。以上示例中的
.spec.dumpling表示 Dumpling 相关的配置,可以在options字段指定 Dumpling 的运行参数,详情见 Dumpling 使用文档;默认情况下该字段可以不用配置。当不指定 Dumpling 的配置时,options字段的默认值如下:options: - --threads=16 - --rows=10000更多
BackupCR 字段的详细解释参考 Backup CR 字段介绍。创建好
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: from: host: ${tidb_host} port: ${tidb_port} user: ${tidb_user} secretName: backup-demo1-tidb-secret gcs: secretName: gcs-secret projectId: ${project_id} bucket: ${bucket} # prefix: ${prefix} # location: us-east1 # storageClass: STANDARD_IA # objectAcl: private # bucketAcl: private # dumpling: # options: # - --threads=16 # - --rows=10000 # tableFilter: # - "test.*" # storageClassName: local-storage storageSize: 10Gi定时全量备份创建完成后,可以通过以下命令查看定时全量备份的状态:
kubectl get bks -n test1 -owide查看定时全量备份下面所有的备份条目:
kubectl get bk -l tidb.pingcap.com/backup-schedule=demo1-backup-schedule-gcs -n test1
从以上示例可知,backupSchedule 的配置由两部分组成。一部分是 backupSchedule 独有的配置,另一部分是 backupTemplate。backupTemplate 指定集群及远程存储相关的配置,字段和 Backup CR 中的 spec 一样,详细介绍可参考 Backup CR 字段介绍。backupSchedule 独有的配置项具体介绍可参考 BackupSchedule CR 字段介绍。
注意
TiDB Operator 会创建一个 PVC,这个 PVC 同时用于 Ad-hoc 全量备份和定时全量备份,备份数据会先存储到 PV,然后再上传到远端存储。如果备份完成后想要删掉这个 PVC,可以参考删除资源先把备份 Pod 删掉,然后再把 PVC 删掉。
假如备份并上传到远端存储成功,TiDB Operator 会自动删除本地的备份文件。如果上传失败,则本地备份文件将被保留。
边栏推荐
- Principle of attention mechanism
- About Estimation Statistics
- Summer 2022 daily question 1 (1)
- First understand the principle of network
- VHDL implementation of arbitrary size matrix addition operation
- 22.(arcgis api for js篇)arcgis api for js圆采集(SketchViewModel)
- Machine learning notes - bird species classification using machine learning
- QT thread and other 01 concepts
- Open3d mesh filtering
- Top 50 hit industry in the first half of 2022
猜你喜欢

VHDL implementation of arbitrary size matrix addition operation

Enumeration general interface & enumeration usage specification

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

leetcode:面试题 17.24. 子矩阵最大累加和(待研究)

Confirm the future development route! Digital economy, digital transformation, data This meeting is very important

ubuntu20安裝redisjson記錄

tflite模型转换和量化

SQL injection -day15

QT opens a file and uses QFileDialog to obtain the file name, content, etc

QT item table new column name setting requirement exercise (find the number and maximum value of the array disappear)
随机推荐
QT opens a file and uses QFileDialog to obtain the file name, content, etc
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
Lab1 configuration script
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
自适应非欧表征广告检索系统AMCAD
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
机器学习笔记 - 使用机器学习进行鸟类物种分类
Docker部署Mysql8的实现步骤
[dpdk] dpdk sample source code analysis III: dpdk-l3fwd_ 001
Class常量池与运行时常量池
Kotlin Android environment construction
二进制、八进制、十六进制
未来发展路线确认!数字经济、数字化转型、数据...这次会议很重要
How to detect whether the MySQL code runs deadlock +binlog view
[leetcode] 700 and 701 (search and insert of binary search tree)
链表面试常见题
本机mysql
Termux set up the computer to connect to the mobile phone. (knock the command quickly), mobile phone termux port 8022
运算放大器应用汇总1
VHDL implementation of arbitrary size matrix addition operation