horgh-replicator
                                
                                
                                
                                    horgh-replicator copied to clipboard
                            
                            
                            
                        Golang binlog replication from MySQL to MySQL, PostgreSQL, Vertica, Clickhouse
Mysql binlog replicator
Based on JackShadow/go-binlog-example
Site
See full docs here
Master types
- MySQL
 
Slave types
- MySQL
 - PostgreSQL
 - Yandex ClickHouse
 - HP Vertica
 
Quick start
See quick start tutorial here
Testing
- Copy 
src/.env.disttosrc/.envand set credentials. - Configure your my MySQL master as 
examples/master/mysql.conf. Don't forget to setbinlog_do_db=<master_db_name>and restart MySQL service. - Create databases and tables as 
examples/sql/. - Start Docker as 
make start-dev - Run as 
cd srcandgo run main.go listenin docker container. - Copy 
examples/configs/user.jsonandexamples/configs/post.jsontosrc/system/configs - Execute 
cd srcandgo run main.go load 
Add tables to replicator
- Use 
create-model <table>to create json config for your table. - Create table on slave.
 - Set 
<table>toTABLEparam insrc/.env - Use 
build-slaveto copy table data from master and set start position of log for table listener. 
Custom handlers for field value
- Create 
plugins/user/<plugin_name>/handler.golikeplugins/system/set_value/handler.go - Execute 
go build -buildmode=plugin -o plugins/user/<plugin_name>/handler.so plugins/user/<plugin_name>/handler.go - Add to field description in your 
src/system/configs/<model>.json 
"beforeSave": {
  "handler": "user/<plugin_name>",
  "params": [
    "***"
  ]
}
System handlers
- If you want to set custom field value use 
system/set_valueashandlerparam. Don't forget to setparams: ["<value>"] 
Tools
set-position <table> <binlog_name> <binlog_position>set start position of log for table listenerloadstart loader for replication testing (for default tables user and post)create-model <table>create model json-file by master table structurebuild-slavecreate master table dump, restore this dump in slave, set start position of log for table listenerdestroy-slavetruncate table, set empty position of log for table listener
Modes
- 
Prod mode: build app and execute listener.
Use
make build-prodandmake start-prodto start andmake stop-prodto stop. - 
Dev mode: provides the opportunity for manual start and debug.
Use
make start-devto start andmake stop-devto stop.