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 UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
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)