How to setup a replication slave with TwinDB Backup tool
Setting up a replication slave is pretty straightforward, yet cumbersome process that needs a lot of attention to details. Look, even if the six steps are simple, together they constitute something I cannot call simple.
We decided to fix that. Our TwinDB Backup tool can take backups, can restore them, can copy files over the network. If we put that together we can get a one line command to fire up a replica from a live master. And we did it in the recent TwinDB Backup release.
$ twindb-backup --version
$ twindb-backup clone mysql --help
Usage: twindb-backup clone mysql [OPTIONS] [SOURCE] DESTINATION
Clone mysql backup on remote server and make it a slave. By default it
will take a slave from a local MySQL on port 3306.
Source and destinations are strings hostname:port. E.g. 10.10.10.10:3306.
If port isn't specified 3306 will be assumed.
--netcat-port INTEGER Use this TCP port for netcat file transfers
between clone source and destination.
--replication-user TEXT Replication MySQL user. [default: repl]
--replication-password TEXT Replication MySQL password. [default:
--help Show this message and exit.
To clone a server twindb-backup runs XtraBackup on the Master. It streams the backup copy directly to the Slave.
For files transfer over the network it starts netcat server on the Slave on TCP port 9990 by default.
After the copy lands to the Slave twindb-backup applies the XtrbaBackup redo log, fixes
server_id, starts MySQL and configures replication.
That I call simple.
However the most useful application of this feature comes probably with the twindb-backup python module.
def clone_mysql(cfg, source, destination, # pylint: disable=too-many-arguments
"""Clone mysql backup of remote machine and stream it to slave"""
The module can be used in your MySQL automation framework.