MariaDB Full Backup and Restore with mariabackup

If you have a large database you will soon discover that mysqldump takes a long time, thankfully MariaDB comes with its own backup program ‘mariabackup’.
You can get more information and guides about Mariabackup on the MariaDB website.
Generating a backup is quite simple and there are several different ways to do it, I like to gzip everything into a single file so its easier to work with instead of having a directory of files for a single backup.
You can use the below command to take a full backup of your MariaDB data:
[user@linux ~]$ mariabackup --user=root --password=PASSWORD --backup --stream=xbstream | gzip > BACKUPFILENAME.gz
Unfortunately restoring the database has a few more steps.
First move the backup.gz file into a new empty directory to work in then run the following command:
[user@linux ~]$ gunzip -c backup_22_03_2020.gz | mbstream -x
We then have to prepare the backup for restoration, to do this we have to run this command:
[user@linux ~]$ mariabackup --prepare --target-dir=/home/user/tmpnewdir
Once that’s done we can restore:
[user@linux ~]$ mariabackup --copy-back --target-dir=/home/user/tmpnewdir
Once complete permissions may not be correct so you may want to run the following:
[user@linux ~]$ chown -R mysql:mysql /var/lib/mysql/
Done! Your MariaDB data should be restored, you can see why I still prefer to use mysqldump on small databases since its easier to work with and restore.