Restore Data from GCS
This document describes how to restore the TiDB cluster data backed up using TiDB Operator in Kubernetes.
The restore method described in this document is implemented based on CustomResourceDefinition (CRD) in TiDB Operator v1.1 or later versions. For the underlying implementation, TiDB Lightning TiDB-backend is used to perform the restore.
TiDB Lightning supports three backends: Importer-backend, Local-backend, and TiDB-backend. For the differences of these backends and how to choose backends, see TiDB Lightning Backends. To import data using Importer-backend or Local-backend, see Import Data.
This document shows an example in which the backup data stored in the specified path on Google Cloud Storage (GCS) is restored to the TiDB cluster.
Prerequisites
Download
backup-rbac.yamland execute the following command to create the role-based access control (RBAC) resources in thetest2namespace:kubectl apply -f backup-rbac.yaml -n test2Grant permissions to the remote storage.
Refer to GCS account permissions.
Create the
restore-demo2-tidb-secretsecret which stores the root account and password needed to access the TiDB cluster:kubectl create secret generic restore-demo2-tidb-secret --from-literal=user=root --from-literal=password=${password} --namespace=test2
Required database account privileges
| Privileges | Scope |
|---|---|
| SELECT | Tables |
| INSERT | Tables |
| UPDATE | Tables |
| DELETE | Tables |
| CREATE | Databases, tables |
| DROP | Databases, tables |
| ALTER | Tables |
Restore process
Create the restore custom resource (CR) and restore the backup data to the TiDB cluster:
kubectl apply -f restore.yamlThe
restore.yamlfile has the following content:--- apiVersion: pingcap.com/v1alpha1 kind: Restore metadata: name: demo2-restore namespace: test2 spec: to: host: ${tidb_host} port: ${tidb_port} user: ${tidb_user} secretName: restore-demo2-tidb-secret gcs: projectId: ${project_id} secretName: gcs-secret path: gcs://${backup_path} # storageClassName: local-storage storageSize: 1GiThe example above restores data from the
spec.gcs.pathpath on GCS to thespec.to.hostTiDB cluster. For more information about GCS configuration, refer to GCS fields.For more information about the
RestoreCR fields, refer to Restore CR fields.After creating the
RestoreCR, execute the following command to check the restore status:kubectl get rt -n test2 -owide
Troubleshooting
If you encounter any problem during the restore process, refer to Common Deployment Failures.