## syncer

syncer is a tool for syncing source database data to target database which is compatible with MySQL protocol, like MySQL, TiDB.

## How to use

```
Usage of syncer:
  -L string
        log level: debug, info, warn, error, fatal (default "info")
  -V	prints version and exit
  -b int
    	batch commit count (default 100)
  -c int
    	parallel worker count (default 16)
  -config string
    	path to config file
  -enable-gtid
    	enable gtid mode
  -flavor string
    	use flavor for different MySQL source versions; support "mysql", "mariadb" now; if you replicate from mariadb, please set it to "mariadb" (default "mysql")
  -log-file string
    	log file path
  -log-rotate string
    	log file rotate type, hour/day (default "day")
  -max-retry int
    	maxinum retry when network interruption (default 100)
  -meta string
    	syncer meta info (default "syncer.meta")
  -persistent-dir string
    	syncer history table structures persistent dir; set to non-empty string will choosing history table structure according to column length when constructing DML
  -safe-mode
    	enable safe mode to make syncer reentrant
  -server-id int
    	MySQL slave server ID (default 101)
  -status-addr string
    	status addr
```

## Config
```
# Syncer Configuration.
log-level = "info"

server-id = 101

meta = "./syncer.meta"
worker-count = 16
batch = 100

status-addr = ":8271"
# max-retry is used for retry when network interruption.
max-retry = 100

# Notice: skip-sqls is abandoned, please use skip-ddls instead.
# skip-ddls skip DDL statements which supports regular expression. When there are DDL sqls incompatible with tidb, you should skip them via these rules.
# skip-ddls = ["^CREATE\\s+USER"]

# Notice: skip-events is abandoned, please use skip-dmls instead.
# skip-dmls skip DML statements. type value can be 'insert', 'update', 'delete'.
# skip delete statements in foo.bar table.
# [[skip-dmls]]
# db-name = "foo"
# tbl-name = "bar"
# type = "delete"
# 
# skip all delete statements.
# [[skip-dmls]]
# type = "delete"
# 
# skip all delete statements in all foo.* tables.
# [[skip-dmls]]
# db-name = "foo"
# type = "delete"

## replicate-do-db has priority over replicate-do-table if have same db name
## and we support regular expression , start with '~' declare use regular expression.
#
#replicate-do-db = ["~^b.*","s1"]
#[[replicate-do-table]]
#db-name ="test"
#tbl-name = "log"

#[[replicate-do-table]]
#db-name ="test"
#tbl-name = "~^a.*"

## replicate-ignore-db has priority over replicate-ignore-table if have same db name
## and we support regular expression , start with '~' declare use regular expression.
#
#replicate-ignore-db = ["~^b.*","s1"]
#[[replicate-ignore-table]]
#db-name = "your_db"
#tbl-name = "your_table"

#[[replicate-ignore-table]]
#db-name ="test"
#tbl-name = "~^a.*"


#[[route-rules]]
#pattern-schema = "route_*"
#pattern-table = "abc_*"
#target-schema = "route"
#target-table = "abc"

#[[route-rules]]
#pattern-schema = "route_*"
#pattern-table = "xyz_*"
#target-schema = "route"
#target-table = "xyz"


[from]
host = "127.0.0.1"
user = "root"
password = ""
port = 3306

[to]
host = "127.0.0.1"
user = "root"
password = ""
port = 4000
```

## Example

```
./bin/syncer -config=syncer/config.toml
```

## Notification

now syncer only supports ROW binlog format and mysql GTID. You should make sure table has primary key or index, otherwise while syncer restart,it may inserts some duplicate data.

meta information save the position that had been synchronized. but it maybe not the latest position because syncer saves position information in memory firstly for performance.

syncer supports use regular expression to select database or table. the [Syntax reference](https://github.com/google/re2/wiki/Syntax) show some syntax are not supported.

## License
Apache 2.0 license. See the [LICENSE](../LICENSE) file for details.
