title | summary | category |
---|---|---|
使用 BR 工具恢复 GCS 上的备份数据 |
介绍如何使用 BR 工具将存储在 GCS 上的备份数据恢复到 TiDB 集群。 |
how-to |
本文描述了如何将存储在 Google Cloud Storage (GCS) 上的备份数据恢复到 Kubernetes 环境中的 TiDB 集群。底层通过使用 BR
来进行集群恢复。
本文使用的恢复方式基于 TiDB Operator 新版(v1.1 及以上)的 CustomResourceDefinition (CRD) 实现。
以下示例将存储在 GCS 上指定路径的集群备份数据恢复到 TiDB 集群。
-
下载文件
backup-rbac.yaml
,并执行以下命令在test2
这个 namespace 中创建恢复所需的 RBAC 相关资源:{{< copyable "shell-regular" >}}
kubectl apply -f backup-rbac.yaml -n test2
-
创建
gcs-secret
secret。该 secret 存放用于访问 GCS 的凭证。google-credentials.json
文件存放用户从 GCP console 上下载的 service account key。具体操作参考 GCP 官方文档。{{< copyable "shell-regular" >}}
kubectl create secret generic gcs-secret --from-file=credentials=./google-credentials.json -n test1
-
创建
restore-demo2-tidb-secret
secret,该 secret 存放用来访问 TiDB 集群的 root 账号和密钥:{{< copyable "shell-regular" >}}
kubectl create secret generic restore-demo2-tidb-secret --from-literal=user=root --from-literal=password=<password> --namespace=test2
-
创建 restore custom resource (CR),将指定的备份数据恢复至 TiDB 集群:
{{< copyable "shell-regular" >}}
kubectl apply -f restore.yaml
restore.yaml
文件内容如下:--- apiVersion: pingcap.com/v1alpha1 kind: Restore metadata: name: demo2-restore-gcs namespace: test2 spec: # backupType: full br: cluster: demo2 clusterNamespace: test2 # logLevel: info # statusAddr: ${status-addr} # concurrency: 4 # rateLimit: 0 # checksum: true # sendCredToTikv: true to: host: ${tidb_host} port: ${tidb_port} user: ${tidb_user} secretName: restore-demo2-tidb-secret gcs: projectId: ${project-id} secretName: gcs-secret bucket: ${bucket} prefix: ${prefix} # location: us-east1 # storageClass: STANDARD_IA # objectAcl: private
-
创建好
Restore
CR 后,通过以下命令查看恢复的状态:{{< copyable "shell-regular" >}}
kubectl get rt -n test2 -owide
以上示例将存储在 GCS 上指定路径 spec.gcs.bucket
存储桶中 spec.gcs.prefix
文件夹下的备份数据恢复到 TiDB 集群 spec.to.host
。关于 BR、GCS 的配置项可以参考 backup-gcs.yaml 中的配置。
更多 Restore
CR 字段的详细解释如下:
-
.spec.metadata.namespace
:Restore
CR 所在的 namespace。 -
.spec.to.host
:待恢复 TiDB 集群的访问地址。 -
.spec.to.port
:待恢复 TiDB 集群访问的端口。 -
.spec.to.user
:待恢复 TiDB 集群的访问用户。 -
.spec.to.tidbSecretName
:待备份 TiDB 集群.spec.to.user
用户的密码所对应的 secret。 -
.spec.to.tlsClientSecretName
:指定备份使用的存储证书的 Secret。如果 TiDB 集群已开启 TLS,但是不想使用文档中创建的
${cluster_name}-cluster-client-secret
恢复备份,可以通过这个参数为恢复备份指定一个 Secret,可以通过如下命令生成:{{< copyable "shell-regular" >}}
kubectl create secret generic ${secret_name} --namespace=${namespace} --from-file=tls.crt=${cert_path} --from-file=tls.key=${key_path} --from-file=ca.crt=${ca_path}