当前位置:网站首页>使用 TiDB Lightning 恢复 S3 兼容存储上的备份数据
使用 TiDB Lightning 恢复 S3 兼容存储上的备份数据
2022-07-06 07:58:00 【添香小铺】
本文档介绍如何将 Kubernetes 上通过 TiDB Operator 备份的数据恢复到 TiDB 集群。
本文使用的恢复方式基于 TiDB Operator v1.1 及以上的 CustomResourceDefinition (CRD) 实现,底层通过使用 TiDB Lightning TiDB-backend 来恢复数据。
TiDB Lightning 是一款将全量数据高速导入到 TiDB 集群的工具,可用于从本地盘、Google Cloud Storage (GCS) 或 Amazon S3 云盘读取数据。目前,TiDB Lightning 支持三种后端:Importer-backend、Local-backend、TiDB-backend。本文介绍的方法使用 TiDB-backend。关于这三种后端的区别和选择,请参阅 TiDB Lightning 文档。如果要使用 Importer-backend 或者 Local-backend 导入数据,请参阅使用 TiDB Lightning 导入集群数据。
以下示例将兼容 S3 的存储(指定路径)上的备份数据恢复到 TiDB 集群。
使用场景
如果你需要从兼容 S3 的存储导出备份数据到 TiDB 集群,并对数据恢复有以下要求,可使用本文介绍的恢复方案:
- 希望以较低资源占用率和较低网络带宽占用进行恢复,并能接受 50 GB/小时的恢复速度
- 要求导入集群时满足 ACID
- 要求备份期间 TiDB 集群仍可对外提供服务
恢复前的准备
在进行数据恢复前,你需要准备恢复环境,并拥有数据库的相关权限。
准备恢复环境
下载文件 backup-rbac.yaml,并执行以下命令在
test2这个 namespace 中创建恢复所需的 RBAC 相关资源:kubectl apply -f backup-rbac.yaml -n test2远程存储访问授权。
如果从 Amazon S3 恢复集群数据,可以使用三种权限授予方式授予权限,参考 AWS 账号授权授权访问兼容 S3 的远程存储;使用 Ceph 作为后端存储测试恢复时,是通过 AccessKey 和 SecretKey 模式授权,设置方式可参考通过 AccessKey 和 SecretKey 授权。
创建
restore-demo2-tidb-secretsecret,该 secret 存放用来访问 TiDB 集群的 root 账号和密钥:kubectl create secret generic restore-demo2-tidb-secret --from-literal=user=root --from-literal=password=${password} --namespace=test2
获取所需的数据库权限
使用 TiDB Lightning 将 Amazon S3 上的备份数据恢复至 TiDB 集群前,确保你拥有备份数据库的以下权限:
| 权限 | 作用域 |
|---|---|
| SELECT | Tables |
| INSERT | Tables |
| UPDATE | Tables |
| DELETE | Tables |
| CREATE | Databases, tables |
| DROP | Databases, tables |
| ALTER | Tables |
将指定备份数据恢复到 TiDB 集群
注意
由于 rclone 存在问题,如果使用 Amazon S3 存储备份,并且 Amazon S3 开启了 AWS-KMS 加密,需要在本节示例中的 yaml 文件里添加如下 spec.s3.options 配置以保证备份恢复成功:
spec: ... s3: ... options: - --ignore-checksum
本节提供了存储访问的多种方法。只需使用符合你情况的方法即可。
- 通过 AccessKey 和 SecretKey 授权的方式由 Ceph 恢复数据的方法
- 通过 AccessKey 和 SecretKey 授权的方式从 Amazon S3 恢复数据的方法
- 通过绑定 IAM 与 Pod 的方式从 Amazon S3 恢复数据的方法
- 通过绑定 IAM 与 ServiceAccount 的方式从 Amazon S3 恢复数据的方法
创建 Restore customer resource (CR),将指定备份数据恢复至 TiDB 集群。
方法 1:创建 Restore custom resource (CR),通过 AccessKey 和 SecretKey 授权的方式将指定的备份数据由 Ceph 恢复至 TiDB 集群。
kubectl apply -f restore.yamlrestore.yaml文件内容如下:--- apiVersion: pingcap.com/v1alpha1 kind: Restore metadata: name: demo2-restore namespace: test2 spec: backupType: full to: host: ${tidb_host} port: ${tidb_port} user: ${tidb_user} secretName: restore-demo2-tidb-secret s3: provider: ceph endpoint: ${endpoint} secretName: s3-secret path: s3://${backup_path} # storageClassName: local-storage storageSize: 1Gi方法 2:创建 Restore custom resource (CR),通过 AccessKey 和 SecretKey 授权的方式将指定的备份数据由 Amazon S3 恢复至 TiDB 集群。
kubectl apply -f restore.yamlrestore.yaml文件内容如下:--- apiVersion: pingcap.com/v1alpha1 kind: Restore metadata: name: demo2-restore namespace: test2 spec: backupType: full to: host: ${tidb_host} port: ${tidb_port} user: ${tidb_user} secretName: restore-demo2-tidb-secret s3: provider: aws region: ${region} secretName: s3-secret path: s3://${backup_path} # storageClassName: local-storage storageSize: 1Gi方法 3:创建 Restore custom resource (CR),通过 IAM 绑定 Pod 授权的方式将指定的备份数据恢复至 TiDB 集群。
kubectl apply -f restore.yamlrestore.yaml文件内容如下:--- apiVersion: pingcap.com/v1alpha1 kind: Restore metadata: name: demo2-restore namespace: test2 annotations: iam.amazonaws.com/role: arn:aws:iam::123456789012:role/user spec: backupType: full to: host: ${tidb_host} port: ${tidb_port} user: ${tidb_user} secretName: restore-demo2-tidb-secret s3: provider: aws region: ${region} path: s3://${backup_path} # storageClassName: local-storage storageSize: 1Gi方法 4:创建 Restore custom resource (CR),通过 IAM 绑定 ServiceAccount 授权的方式将指定的备份数据恢复至 TiDB 集群。
kubectl apply -f restore.yamlrestore.yaml文件内容如下:--- apiVersion: pingcap.com/v1alpha1 kind: Restore metadata: name: demo2-restore namespace: test2 spec: backupType: full serviceAccount: tidb-backup-manager to: host: ${tidb_host} port: ${tidb_port} user: ${tidb_user} secretName: restore-demo2-tidb-secret s3: provider: aws region: ${region} path: s3://${backup_path} # storageClassName: local-storage storageSize: 1Gi
创建好
RestoreCR 后,可通过以下命令查看恢复的状态:kubectl get rt -n test2 -owide
以上示例将兼容 S3 的存储(spec.s3.path 路径下)中的备份数据恢复到 TiDB 集群 spec.to.host。有关兼容 S3 的存储的配置项,可以参考 S3 字段介绍。
更多 Restore CR 字段的详细解释参考Restore CR 字段介绍。
注意
TiDB Operator 会创建一个 PVC,用于数据恢复,备份数据会先从远端存储下载到 PV,然后再进行恢复。如果恢复完成后想要删掉这个 PVC,可以参考删除资源先把恢复 Pod 删掉,然后再把 PVC 删掉。
边栏推荐
- onie支持pice硬盘
- [非线性控制理论]9_非线性控制理论串讲
- 【T31ZL智能视频应用处理器资料】
- The difference between TS Gymnastics (cross operation) and interface inheritance
- 你想知道的ArrayList知识都在这
- Position() function in XPath uses
- 23. Update data
- A Closer Look at How Fine-tuning Changes BERT
- Codeforces Global Round 19(A~D)
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
猜你喜欢

Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
![[computer skills]](/img/30/2a4506adf72eb4cb188dd64cce417d.jpg)
[computer skills]

21. Delete data

数字经济时代,如何保障安全?

MEX有关的学习
![[redis] Introduction to NoSQL database and redis](/img/95/229d7a08e94245f2733b8c59201cff.png)
[redis] Introduction to NoSQL database and redis

成为优秀的TS体操高手 之 TS 类型体操前置知识储备
![[untitled]](/img/38/bc025310b9742b5bf0bd28c586ec0d.jpg)
[untitled]

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

Mex related learning
随机推荐
"Designer universe": "benefit dimension" APEC public welfare + 2022 the latest slogan and the new platform will be launched soon | Asia Pacific Financial Media
【Redis】NoSQL数据库和redis简介
Go learning notes (3) basic types and statements (2)
. Net 6 learning notes: what is NET Core
"Designer universe" Guangdong responds to the opinions of the national development and Reform Commission. Primary school students incarnate as small community designers | national economic and Informa
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
The Vice Minister of the Ministry of industry and information technology of "APEC industry +" of the national economic and information technology center led a team to Sichuan to investigate the operat
Parameter self-tuning of relay feedback PID controller
Risk planning and identification of Oracle project management system
Wonderful use of TS type gymnastics string
[Yugong series] February 2022 U3D full stack class 010 prefabricated parts
07- [istio] istio destinationrule (purpose rule)
MFC sends left click, double click, and right click messages to list controls
Solution: système de surveillance vidéo intelligent de patrouille sur le chantier
Step by step guide to setting NFT as an ens profile Avatar
Webrtc series-h.264 estimated bit rate calculation
DataX self check error /datax/plugin/reader/_ drdsreader/plugin. Json] does not exist
octomap averageNodeColor函数说明
成为优秀的TS体操高手 之 TS 类型体操前置知识储备
Generator Foundation