Stefan Langenmaier
1 year
Andreas Vöst
1 year
Moritz Kraus
1 year
Stefan Xenopol
1 year
Emma Heinle
2 years
Andreas Vöst
4 years

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

Updated . Posted . Visible to the public.

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.

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

Claus-Theodor Riegg
Last edit
Marius Schuller
Tags
License
Source code in this card is licensed under the MIT License.