当前位置:网站首页>使用 BR 恢复 S3 兼容存储上的备份数据
使用 BR 恢复 S3 兼容存储上的备份数据
2022-07-06 07:58:00 【添香小铺】
本文介绍如何将 S3 兼容存储上的 SST 备份数据恢复到 AWS Kubernetes 环境中的 TiDB 集群。
本文使用的恢复方式基于 TiDB Operator 的 Custom Resource Definition (CRD) 实现,底层使用 BR 进行数据恢复。BR 全称为 Backup & Restore,是 TiDB 分布式备份恢复的命令行工具,用于对 TiDB 集群进行数据备份和恢复。
使用场景
当使用 BR 将 TiDB 集群数据备份到 Amazon S3 后,如果需要从 Amazon S3 将备份的 SST(键值对)文件恢复到 TiDB 集群,请参考本文使用 BR 进行恢复。
注意
- BR 只支持 TiDB v3.1 及以上版本。
- BR 恢复的数据无法被同步到下游,因为 BR 直接导入 SST 文件,而下游集群目前没有办法获得上游的 SST 文件。
本文假设将存储在 Amazon S3 上指定路径 spec.s3.bucket 存储桶中 spec.s3.prefix 文件夹下的备份数据恢复到 namespace test2 中的 TiDB 集群 demo2。下面是具体的操作过程。
第 1 步:准备恢复环境
使用 BR 将 S3 兼容存储上的备份数据恢复到 TiDB 前,请按照以下步骤准备恢复环境。
下载文件 backup-rbac.yaml,并执行以下命令在
test2这个 namespace 中创建恢复需要的 RBAC 相关资源:kubectl apply -f backup-rbac.yaml -n test2授予远程存储访问权限。
- 如果要恢复的数据在 Amazon S3 上,可以使用三种权限授予方式授予权限,可参考文档 AWS 账号授权。
- 如果要恢复的数据在其他兼容 S3 的存储上,例如 Ceph、MinIO,可以使用 AccessKey 和 SecretKey 模式授权,可参考文档通过 AccessKey 和 SecretKey 授权。
如果你使用的 TiDB 版本低于 v4.0.8,你还需要进行以下操作。如果你使用的 TiDB 为 v4.0.8 及以上版本,请跳过此步骤。
确保你拥有恢复数据库
mysql.tidb表的SELECT和UPDATE权限,用于恢复前后调整 GC 时间。创建
restore-demo2-tidb-secretsecret 用于存放访问 TiDB 集群的 root 账号和密钥。kubectl create secret generic restore-demo2-tidb-secret --from-literal=password=${password} --namespace=test2
第 2 步:将指定备份数据恢复到 TiDB 集群
根据上一步选择的远程存储访问授权方式,你需要使用下面对应的方法将备份数据恢复到 TiDB:
方法 1: 如果通过了 accessKey 和 secretKey 的方式授权,你可以按照以下说明创建
RestoreCR 恢复集群数据:kubectl apply -f resotre-aws-s3.yamlrestore-aws-s3.yaml文件内容如下:--- apiVersion: pingcap.com/v1alpha1 kind: Restore metadata: name: demo2-restore-s3 namespace: test2 spec: br: cluster: demo2 clusterNamespace: test2 # logLevel: info # statusAddr: ${status_addr} # concurrency: 4 # rateLimit: 0 # timeAgo: ${time} # checksum: true # sendCredToTikv: true # # Only needed for TiDB Operator < v1.1.10 or TiDB < v4.0.8 # to: # host: ${tidb_host} # port: ${tidb_port} # user: ${tidb_user} # secretName: restore-demo2-tidb-secret s3: provider: aws secretName: s3-secret region: us-west-1 bucket: my-bucket prefix: my-folder方法 2: 如果通过了 IAM 绑定 Pod 的方式授权,你可以按照以下说明创建
RestoreCR 恢复集群数据:kubectl apply -f restore-aws-s3.yamlrestore-aws-s3.yaml文件内容如下:--- apiVersion: pingcap.com/v1alpha1 kind: Restore metadata: name: demo2-restore-s3 namespace: test2 annotations: iam.amazonaws.com/role: arn:aws:iam::123456789012:role/user spec: br: cluster: demo2 sendCredToTikv: false clusterNamespace: test2 # logLevel: info # statusAddr: ${status_addr} # concurrency: 4 # rateLimit: 0 # timeAgo: ${time} # checksum: true # Only needed for TiDB Operator < v1.1.10 or TiDB < v4.0.8 to: host: ${tidb_host} port: ${tidb_port} user: ${tidb_user} secretName: restore-demo2-tidb-secret s3: provider: aws region: us-west-1 bucket: my-bucket prefix: my-folder方法 3: 如果通过了 IAM 绑定 ServiceAccount 的方式授权,你可以按照以下说明创建
RestoreCR 恢复集群数据:kubectl apply -f restore-aws-s3.yamlrestore-aws-s3.yaml文件内容如下:--- apiVersion: pingcap.com/v1alpha1 kind: Restore metadata: name: demo2-restore-s3 namespace: test2 spec: serviceAccount: tidb-backup-manager br: cluster: demo2 sendCredToTikv: false clusterNamespace: test2 # logLevel: info # statusAddr: ${status_addr} # concurrency: 4 # rateLimit: 0 # timeAgo: ${time} # checksum: true # Only needed for TiDB Operator < v1.1.10 or TiDB < v4.0.8 to: host: ${tidb_host} port: ${tidb_port} user: ${tidb_user} secretName: restore-demo2-tidb-secret s3: provider: aws region: us-west-1 bucket: my-bucket prefix: my-folder
在配置 restore-aws-s3.yaml 文件时,请参考以下信息:
- 关于兼容 S3 的存储相关配置,请参考 S3 存储字段介绍。
.spec.br中的一些参数为可选项,如logLevel、statusAddr、concurrency、rateLimit、checksum、timeAgo、sendCredToTikv。更多.spec.br字段的详细解释,请参考 BR 字段介绍。- 如果你使用的 TiDB 为 v4.0.8 及以上版本,BR 会自动调整
tikv_gc_life_time参数,不需要在 Restore CR 中配置spec.to字段。 - 更多
RestoreCR 字段的详细解释,请参考 Restore CR 字段介绍。
创建好 Restore CR 后,可通过以下命令查看恢复的状态:
kubectl get rt -n test2 -o wide
边栏推荐
- How to prevent Association in cross-border e-commerce multi account operations?
- On why we should program for all
- Risk planning and identification of Oracle project management system
- How to estimate the number of threads
- ROS learning (IX): referencing custom message types in header files
- MEX有关的学习
- PHP Coding Standard
- Sanzi chess (C language)
- Cf1036c class numbers solution
- WebRTC系列-H.264预估码率计算
猜你喜欢

A Closer Look at How Fine-tuning Changes BERT

Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center

NFT smart contract release, blind box, public offering technology practice -- jigsaw puzzle
![[factorial inverse], [linear inverse], [combinatorial counting] Niu Mei's mathematical problems](/img/6d/282d904810807810adb06b071fb39b.jpg)
[factorial inverse], [linear inverse], [combinatorial counting] Niu Mei's mathematical problems

让学指针变得更简单(三)

数据治理:主数据的3特征、4超越和3二八原则

"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

861. Score after flipping the matrix

The State Economic Information Center "APEC industry +" Western Silicon Valley will invest 2trillion yuan in Chengdu Chongqing economic circle, which will surpass the observation of Shanghai | stable

Pre knowledge reserve of TS type gymnastics to become an excellent TS gymnastics master
随机推荐
How to estimate the number of threads
Data governance: misunderstanding sorting
C语言自定义类型:结构体
Flash return file download
WebRTC系列-H.264预估码率计算
你想知道的ArrayList知识都在这
Easy to use tcp-udp_ Debug tool download and use
数据治理:主数据的3特征、4超越和3二八原则
Machine learning - decision tree
Luogu p1836 number page solution
指针和数组笔试题解析
二叉树创建 & 遍历
JS select all and tab bar switching, simple comments
"Friendship and righteousness" of the center for national economy and information technology: China's friendship wine - the "unparalleled loyalty and righteousness" of the solidarity group released th
P3047 [usaco12feb]nearby cows g (tree DP)
Circuit breaker: use of hystrix
esRally国内安装使用避坑指南-全网最新
解决方案:智慧工地智能巡檢方案視頻監控系統
数据治理:微服务架构下的数据治理
珠海金山面试复盘