| title | Restore Data from GCS |
|---|---|
| summary | Learn how to restore the backup data from GCS. |
| category | how-to |
This document describes how to restore the TiDB cluster data backed up using TiDB Operator in Kubernetes. For the underlying implementation, TiDB Lightning is used to perform the restoration.
The restoration method described in this document is implemented based on CustomResourceDefinition (CRD) in TiDB Operator v1.1 or later versions. For the restoration method implemented based on Helm Charts, refer to Back up and Restore TiDB Cluster Data Based on Helm Charts.
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.
-
Download
backup-rbac.yamland execute the following command to create the role-based access control (RBAC) resources in thetest2namespace:{{< copyable "shell-regular" >}}
kubectl apply -f backup-rbac.yaml -n test2
-
Create the
restore-demo2-tidb-secretsecret which stores the root account and password needed to access the TiDB cluster:{{< copyable "shell-regular" >}}
kubectl create secret generic restore-demo2-tidb-secret --from-literal=user=root --from-literal=password=${password} --namespace=test2
-
Create the restore custom resource (CR) and restore the backup data to the TiDB cluster:
{{< copyable "shell-regular" >}}
kubectl apply -f restore.yaml
The
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: 1Gi
-
After creating the
RestoreCR, execute the following command to check the restoration status:{{< copyable "shell-regular" >}}
kubectl get rt -n test2 -owide
In the above example, the backup data stored in the specified spec.gcs.path path on GCS is restored to the spec.to.host TiDB cluster. For the configuration of GCS, refer to backup-gcs.yaml.
More Restore CRs are described as follows:
.spec.metadata.namespace: the namespace where theRestoreCR is located..spec.to.host: the address of the TiDB cluster to be restored..spec.to.port: the port of the TiDB cluster to be restored..spec.to.user: the accessing user of the TiDB cluster to be restored..spec.to.tidbSecretName: the secret of the credential needed by the TiDB cluster to be restored..spec.storageClassName: the persistent volume (PV) type specified for the restoration. If this item is not specified, the value of thedefault-backup-storage-class-nameparameter (standardby default, specified when TiDB Operator is started) is used by default..spec.storageSize: the PV size specified for the restoration. This value must be greater than the size of the backed up TiDB cluster.