|
| 1 | +--- |
| 2 | +title: 使用 Dumpling 备份 TiDB 数据到 Google Cloud Storage (GCS) |
| 3 | +summary: 本文介绍如何使用 Dumpling 将 TiDB 集群数据备份到 Google Cloud Storage (GCS)。 |
| 4 | +--- |
| 5 | + |
| 6 | +# 使用 Dumpling 备份 TiDB 数据到 Google Cloud Storage (GCS) |
| 7 | + |
| 8 | +本文档介绍如何使用 [Dumpling](https://docs.pingcap.com/zh/tidb/stable/dumpling-overview/) 将部署在 Google GKE 上的 TiDB 集群数据备份到 [Google Cloud Storage (GCS)](https://cloud.google.com/storage/docs)。Dumpling 是一款数据导出工具,可将 TiDB 或 MySQL 中的数据导出为 SQL 或 CSV 格式,用于全量数据备份或导出。 |
| 9 | + |
| 10 | +## 准备 Dumpling 节点池 |
| 11 | + |
| 12 | +你可以在现有节点池中运行 Dumpling,也可以创建一个专用节点池。以下命令示例展示了如何创建一个新的节点池。请根据实际情况替换以下变量: |
| 13 | + |
| 14 | +- `${clusterName}`:GKE 集群名称 |
| 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 | +## 部署 Dumpling Job |
| 25 | + |
| 26 | +### 创建凭证 ConfigMap |
| 27 | + |
| 28 | +将从 Google Cloud Console 下载的 `service account key` 文件保存为 `google-credentials.json`,然后使用以下命令创建 ConfigMap: |
| 29 | + |
| 30 | +```shell |
| 31 | +kubectl -n ${namespace} create configmap google-credentials --from-file=google-credentials.json |
| 32 | +``` |
| 33 | + |
| 34 | +### 配置 Dumpling Job |
| 35 | + |
| 36 | +Dumpling Job 的配置文件 (`dumpling_job.yaml`) 示例如下。使用前,请替换以下变量: |
| 37 | + |
| 38 | +- `${name}`:Job 名称 |
| 39 | +- `${namespace}`:Kubernetes 命名空间 |
| 40 | +- `${version}`:Dumpling 镜像版本 |
| 41 | +- Dumpling 的相关参数,请参考 [Dumpling 主要选项表](https://docs.pingcap.com/zh/tidb/stable/dumpling-overview/#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 | +### 创建 Dumpling Job |
| 98 | +
|
| 99 | +执行以下命令创建 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 | +### 查看 Dumpling Job 状态 |
| 110 | + |
| 111 | +运行以下命令查看 Dumpling Job 的 Pod 状态: |
| 112 | + |
| 113 | +```shell |
| 114 | +kubectl -n ${namespace} get pod ${name} |
| 115 | +``` |
| 116 | + |
| 117 | +### 查看 Dumpling Job 日志 |
| 118 | + |
| 119 | +运行以下命令查看 Dumpling Job 的日志输出: |
| 120 | + |
| 121 | +```shell |
| 122 | +kubectl -n ${namespace} logs pod ${name} |
| 123 | +``` |
0 commit comments