Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: add mydumper #923

Merged
merged 11 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -659,24 +659,24 @@ TiDB 设计的目标就是针对 MySQL 单台容量限制而被迫做的分库

#### 3.6.1 TiDB 主要备份方式?

目前 TiDB 主要依赖 mydumper 逻辑导出进行备份,具体可以参考 [https://github.com/maxbube/mydumper](https://github.com/maxbube/mydumper),虽然 TiDB 也支持使用 MySQL 官方的 mysqldump 工具来进行数据的备份恢复工作,但相比于 mydumper/loader,性能会慢很多,大量数据的备份恢复会花费很多时间,这里我们并不推荐
目前,推荐的备份方式是使用 [PingCAP fork 的 mydumper](tools/mydumper.md)。尽管 TiDB 也支持使用 MySQL 官方工具 `mysqldump` 进行数据备份、恢复,但其性能低于 [`mydumper`](tools/mydumper.md)/[`loader`](tools/loader.md),并且该工具备份、恢复大量数量时,要耗费更多时间

使用 mydumper 导出来的数据文件尽可能的小, 最好不要超过 64M, 可以设置参数 -F 64;

loader的 -t 参数可以根据 TiKV 的实例个数以及负载进行评估调整,例如 3 个 TiKV 的场景, 此值可以设为 3 * (1 ~ n),当 TiKV 负载过高,loader 以及 TiDB 日志中出现大量 `backoffer.maxSleep 15000ms is exceeded` 可以适当调小该值,当 TiKV 负载不是太高的时候,可以适当调大该值。
loader 的 -t 参数可以根据 TiKV 的实例个数以及负载进行评估调整,例如 3 个 TiKV 的场景, 此值可以设为 3 * (1 ~ n),当 TiKV 负载过高,loader 以及 TiDB 日志中出现大量 `backoffer.maxSleep 15000ms is exceeded` 可以适当调小该值,当 TiKV 负载不是太高的时候,可以适当调大该值。

## 四、数据、流量迁移

### 4.1 全量数据导出导入

#### 4.1.1 Mydumper 工具
#### 4.1.1 Mydumper

具体可以参考 [https://github.com/maxbube/mydumper](https://github.com/maxbube/mydumper)。
参见 [mydumper 使用文档](tools/mydumper.md)。

#### 4.1.2 Loader 工具

具体可以参考 [https://www.pingcap.com/docs-cn/tools/loader/](tools/loader.md)。
#### 4.1.2 Loader

参见 [Loader 使用文档](tools/loader.md)。

#### 4.1.3 如何将一个运行在 MySQL 上的应用迁移到 TiDB 上?

TiDB 支持绝大多数 MySQL 语法,一般不需要修改代码。我们提供了一个[检查工具](https://github.com/pingcap/tidb-tools/tree/master/checker),用于检查 MySQL 中的 Schema 是否和 TiDB 兼容。
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
- [故障诊断](trouble-shooting.md)
+ TiDB 周边工具
- [Syncer](tools/syncer.md)
- [mydumper](tools/mydumper.md)
- [Loader](tools/loader.md)
- [TiDB-Binlog](tools/tidb-binlog-kafka.md)
- [PD Control](tools/pd-control.md)
Expand Down
4 changes: 2 additions & 2 deletions op-guide/backup-restore.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ cd tidb-enterprise-tools-latest-linux-amd64

`mydumper` 是一个强大的数据备份工具,具体可以参考 [https://github.com/maxbube/mydumper](https://github.com/maxbube/mydumper)。

我们使用 `mydumper` 从 TiDB 导出数据进行备份,然后用 `loader` 将其导入到 TiDB 里面进行恢复。
可使用 [`mydumper`](../tools/mydumper.md) 从 TiDB 导出数据进行备份,然后用 [`loader`](../tools/loader.md) 将其导入到 TiDB 里面进行恢复。

> **注意**:虽然 TiDB 也支持使用 MySQL 官方的 `mysqldump` 工具来进行数据的备份恢复工作,但相比于 `mydumper`/`loader`,性能会慢很多,大量数据的备份恢复会花费很多时间,这里我们并不推荐
> **注意**:必须使用企业版工具集包的 `mydumper`,不要使用你的操作系统的包管理工具提供的 `mydumper`。`mydumper` 的上游版本并不能对 TiDB 进行正确处理 ([#155](https://github.com/maxbube/mydumper/pull/155))。由于使用 `mysqldump` 进行数据备份和恢复都要耗费许多时间,这里也并不推荐

### `mydumper`/`loader` 全量备份恢复最佳实践

Expand Down
45 changes: 45 additions & 0 deletions tools/mydumper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: mydumper 使用文档
summary: 使用 mydumper 从 TiDB 导出数据。
category: tools
---

# mydumper 使用文档

## mydumper 简介

`mydumper` 是 [mydumper](https://github.com/maxbube/mydumper) 的 fork 项目,并添加了一些针对 TiDB 的功能。推荐使用此工具对 TiDB 进行逻辑备份。
kennytm marked this conversation as resolved.
Show resolved Hide resolved

[下载 Binary](http://download.pingcap.org/tidb-enterprise-tools-latest-linux-amd64.tar.gz)。

## 相比于普通的 mydumper,此工具有哪些改进之处?

+ 使用 `tidb_snapshot` 而非 `FLUSH TABLES WITH READ LOCK` 提供备份一致性
+ `INSERT` 语句中包含隐藏的 `_tidb_rowid` 列
+ [允许设置](../op-guide/history-read.md#操作流程) `tidb_snapshot` 的值(即可备份不同时间点的数据)

### 新添参数

```bash
-z, --tidb-snapshot: 设置 tidb_snapshot 用于备份
默认值:NOW()-INTERVAL 1 SECOND
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value has been recently changed to the output of SHOW MASTER STATUS 🙂

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created pingcap/docs#693 to handle the defaults change.

此参数可设为 TSO 时间或有效的 datetime 时间。例如:-z "2016-10-08 16:45:26"
```

### 使用举例

命令行参数:

```bash
./bin/mydumper -h 127.0.0.1 -u root -P 4000
```

## FAQ

### PingCAP 的 mydumper 的源码是否可获取?

PingCAP 的 mydumper 源码 [位于 GitHub](https://github.com/pingcap/mydumper)。

### 未来是否计划让 PingCAP 对 mydumper 的改动合并到上游?

是的,PingCAP 团队计划将对 mydumper 的改动合并到上游。参见 [PR #155](https://github.com/maxbube/mydumper/pull/155)。