title | summary | category |
---|---|---|
Restore Data from GCS |
Learn how to restore the backup data from GCS. |
how-to |
This document describes how to restore the TiDB cluster data backed up using TiDB Operator in Kubernetes. For the underlying implementation, loader
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.yaml
and execute the following command to create the role-based access control (RBAC) resources in thetest2
namespace:{{< copyable "shell-regular" >}}
kubectl apply -f backup-rbac.yaml -n test2
-
Create the
restore-demo2-tidb-secret
secret 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.yaml
file has the following content:--- apiVersion: pingcap.com/v1alpha1 kind: Restore metadata: name: demo2-restore namespace: test2 spec: to: host: <tidb-host-ip> port: <tidb-port> user: <tidb-user> secretName: restore-demo2-tidb-secret gcs: projectId: <your-project-id> secretName: gcs-secret path: gcs://<path-to-backup> storageClassName: local-storage storageSize: 1Gi
-
After creating the
Restore
CR, 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 theRestore
CR 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-name
parameter (standard
by 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.