Claus-Theodor Riegg
8 years
Andreas Vöst
1 year
Andreas Vöst
1 year
Moritz Kraus
1 year

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

Posted Over 3 years ago. 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
Over 2 years ago
Deleted user #4941
Tags
License
Source code in this card is licensed under the MIT License.