|
| 1 | +--- |
| 2 | +title: Back Up TiDB Data to Google Cloud Storage (GCS) Using Dumpling |
| 3 | +summary: Learn how to use Dumpling to back up TiDB cluster data to Google Cloud Storage (GCS). |
| 4 | +--- |
| 5 | + |
| 6 | +# Back Up TiDB Data to Google Cloud Storage (GCS) Using Dumpling |
| 7 | + |
| 8 | +This document describes how to use [Dumpling](https://docs.pingcap.com/tidb/stable/dumpling-overview/) to back up data from a TiDB cluster deployed on Google GKE to [Google Cloud Storage (GCS)](https://cloud.google.com/storage/docs). Dumpling is a data export tool that can export data from TiDB or MySQL in SQL or CSV format for full data backup or export. |
| 9 | + |
| 10 | +## Prepare the Dumpling node pool |
| 11 | + |
| 12 | +You can run Dumpling in an existing node pool or create a dedicated node pool. The following example shows how to create a new node pool. Replace the variables as needed: |
| 13 | + |
| 14 | +- `${clusterName}`: GKE cluster name |
| 15 | + |
| 16 | +```shell |
| 17 | +gcloud container node-pools create dumpling \ |
| 18 | + --cluster ${clusterName} \ |
| 19 | + --machine-type n2-standard-4 \ |
| 20 | + --num-nodes=1 \ |
| 21 | + --node-labels=dedicated=dumpling |
| 22 | +``` |
| 23 | + |
| 24 | +## Deploy the Dumpling job |
| 25 | + |
| 26 | +### Create a credential ConfigMap |
| 27 | + |
| 28 | +Save the `service account key` file downloaded from the Google Cloud Console as `google-credentials.json`, and then create a ConfigMap with the following command: |
| 29 | + |
| 30 | +```shell |
| 31 | +kubectl -n ${namespace} create configmap google-credentials --from-file=google-credentials.json |
| 32 | +``` |
| 33 | + |
| 34 | +### Configure the Dumpling job |
| 35 | + |
| 36 | +The following is a sample configuration file (`dumpling_job.yaml`) for the Dumpling job. Replace the variables as needed: |
| 37 | + |
| 38 | +- `${name}`: job name |
| 39 | +- `${namespace}`: Kubernetes namespace |
| 40 | +- `${version}`: Dumpling image version |
| 41 | +- For Dumpling parameters, refer to the [Option list of Dumpling](https://docs.pingcap.com/tidb/stable/dumpling-overview/#option-list-of-dumpling). |
| 42 | + |
| 43 | +```yaml |
| 44 | +# dumpling_job.yaml |
| 45 | +--- |
| 46 | +apiVersion: batch/v1 |
| 47 | +kind: Job |
| 48 | +metadata: |
| 49 | + name: ${name} |
| 50 | + namespace: ${namespace} |
| 51 | + labels: |
| 52 | + app.kubernetes.io/component: dumpling |
| 53 | +spec: |
| 54 | + template: |
| 55 | + spec: |
| 56 | + nodeSelector: |
| 57 | + dedicated: dumpling |
| 58 | + affinity: |
| 59 | + podAntiAffinity: |
| 60 | + requiredDuringSchedulingIgnoredDuringExecution: |
| 61 | + - labelSelector: |
| 62 | + matchExpressions: |
| 63 | + - key: app.kubernetes.io/component |
| 64 | + operator: In |
| 65 | + values: |
| 66 | + - dumpling |
| 67 | + topologyKey: kubernetes.io/hostname |
| 68 | + containers: |
| 69 | + - name: ${name} |
| 70 | + image: pingcap/dumpling:${version} |
| 71 | + command: |
| 72 | + - /bin/sh |
| 73 | + - -c |
| 74 | + - | |
| 75 | + /dumpling \ |
| 76 | + --host=basic-tidb \ |
| 77 | + --port=4000 \ |
| 78 | + --user=root \ |
| 79 | + --password='' \ |
| 80 | + --threads=16 \ |
| 81 | + --rows=20000 \ |
| 82 | + --filesize=256MiB \ |
| 83 | + --database=test \ |
| 84 | + --filetype=csv \ |
| 85 | + --output=gcs://external/testfolder?credentials-file=/etc/config/google-credentials.json |
| 86 | + volumeMounts: |
| 87 | + - name: google-credentials |
| 88 | + mountPath: /etc/config |
| 89 | + volumes: |
| 90 | + - name: google-credentials |
| 91 | + configMap: |
| 92 | + name: google-credentials |
| 93 | + restartPolicy: Never |
| 94 | + backoffLimit: 0 |
| 95 | +``` |
| 96 | +
|
| 97 | +### Create the Dumpling job |
| 98 | +
|
| 99 | +Run the following commands to create the Dumpling job: |
| 100 | +
|
| 101 | +```shell |
| 102 | +export name=dumpling |
| 103 | +export version=v8.5.1 |
| 104 | +export namespace=tidb-cluster |
| 105 | + |
| 106 | +envsubst < dumpling_job.yaml | kubectl apply -f - |
| 107 | +``` |
| 108 | + |
| 109 | +### Check the Dumpling job status |
| 110 | + |
| 111 | +Run the following command to check the Pod status of the Dumpling job: |
| 112 | + |
| 113 | +```shell |
| 114 | +kubectl -n ${namespace} get pod ${name} |
| 115 | +``` |
| 116 | + |
| 117 | +### View Dumpling job logs |
| 118 | + |
| 119 | +Run the following command to view the logs of the Dumpling job: |
| 120 | + |
| 121 | +```shell |
| 122 | +kubectl -n ${namespace} logs pod ${name} |
| 123 | +``` |
0 commit comments