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 detail. Even if at first glance the six steps are simple, together they constitute something that is everything but easy to grasp.
What’s Our Solution
We decided to fix that. As a result, our very own TwinDB Backup tool can take backups, restore them, 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.
How Does It Work
To clone a server, twindb-backup runs XtraBackup on the Master. It streams the backup copy directly to the Slave.
To transfer files over the network, it starts a netcat server on the Slave on a TCP port 9990 by default.
After the copy lands on the Slave, twindb-backup applies the XtrbaBackup redo log, fixes
server_id, starts MySQL, and finally configures the replication.
Now this is what I call simple.
However, the most useful application of this feature probably comes 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"""
In addition, the module can be used in your MySQL automation framework.