Read more

HowTo: Clone a MariaDB database with mariabackup, mbstream and netcat

Claus-Theodor Riegg
August 27, 2020Software engineer at makandra GmbH

If you have a very large datadir in MariaDB and you want to transfer the data to another host (e.g. for replication) you may want to avoid storing it locally and copying it between the hosts.

Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot

You can stream the backup directly via netcat.

Transferring the stream data

  1. On the destination host
$ mkdir mariabackup
$ cd mariabackup
$ nc -l 9999 | cat - | mbstream -x
  1. On the source host
$ mariabackup --backup --stream=xbstream | nc destination-host 9999

Restoring the backup

After the streaming of the backup is complete, on the destination host run:

  1. # systemctl stop mariadb

  2. # rm -r /var/lib/mysql/*

  3. To setup replication afterwards, get the output of:

    # cat xtrabackup_binlog_info
    
  4. Prepare and restore the backup:

    $ cd ..
    $ mariabackup --prepare --target-dir ./mariabackup
    $ mariabackup --move-back --target-dir ./mariabackup
    
  5. # chown -R mysql:mysql /var/lib/mysql/

  6. # systemctl start mariadb

Posted by Claus-Theodor Riegg to makandra Operations (2020-08-27 10:30)