Stream and restore a mariabackup to another host with netcat
If you have a very large datadir in MariaDB and you want to transfer this datadir 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.
- on the destination host
$ mkdir mariabackup $ cd mariabackup $ nc -l 9999 | cat - | mbstream -x
- on the source host
mariabackup --backup --stream=xbstream | nc destination-host 9999
After the streaming of the backup is complete, on the destination host run:
systemctl stop mariadb
rm -r /var/lib/mysql/*
To setup replication afterswards, get the output of:Copy
Prepare and restore the backup:Copy
$ cd .. $ mariabackup --prepare --target-dir ./mariabackup $ mariabackup --move-back --target-dir ./mariabackup
chown -R mysql:mysql /var/lib/mysql/
systemctl start mariadb