# TiDB Lightning 的使用 - 断点续传

__*Lightning 使用*__
__*Lightning 断点续传*__

```
[checkpoint]
# Whether to enable checkpoints.
# While importing data, TiDB Lightning records which tables have been imported, so
# even if TiDB Lightning or some other component crashes, you can start from a known
# good state instead of restarting from scratch.
enable = true

# Where to store the checkpoints.
#  - file:  store as a local file (requires v2.1.1 or later)
#  - mysql: store into a remote MySQL-compatible database
driver = "file"

# The schema name (database name) to store the checkpoints
# Enabled only when `driver = "mysql"`.
# schema = "tidb_lightning_checkpoint"

# The data source name (DSN) indicating the location of the checkpoint storage.
#
# For the "file" driver, the DSN is a path. If the path is not specified, Lightning would
# default to "/tmp/CHECKPOINT_SCHEMA.pb".
#
# For the "mysql" driver, the DSN is a URL in the form of "USER:PASS@tcp(HOST:PORT)/".
# If the URL is not specified, the TiDB server from the [tidb] section is used to
# store the checkpoints. You should specify a different MySQL-compatible
# database server to reduce the load of the target TiDB cluster.
#dsn = "/tmp/tidb_lightning_checkpoint.pb"

# Whether to keep the checkpoints after all data are imported. If false, the
# checkpoints are deleted. Keeping the checkpoints can aid debugging but
# might leak metadata about the data source.
# keep-after-success = false
```
-------------------------------------------------------------
大量的数据导入一般耗时数小时至数天,长时间运行的进程会有一定机率发生非正常中断。如果每次重启都从头开始,就会浪费掉之前已成功导入的数据。为此,TiDB Lightning 提供了"断点续传"的功能,即使 tidb-lightning 崩溃,在重启时仍然接着之前的进度继续工作。

TiDB Lightning 支持两种存储方式:本地文件或 MySQL 数据库。

若 driver = "file",断点会存放在一个本地文件,其路径由 dsn 参数指定。由于断点会频繁更新,建议将这个文件放到写入次数不受限制的盘上,例如 RAM disk。
若 driver = "mysql",断点可以存放在任何兼容 MySQL 5.7 或以上的数据库中,包括 MariaDB 和 TiDB。在没有选择的情况下,默认会存在目标数据库里。

目标数据库在导入期间会有大量的操作,若使用目标数据库来存储断点会加重其负担,甚至有可能造成通信超时丢失数据。因此,强烈建议另外部署一台兼容 MySQL 的临时数据库服务器。此数据库也可以安装在 tidb-lightning 的主机上。导入完毕后可以删除。