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 Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)