MariaDB Full Backup and Restore with Mariabackup

MariaDB Full Backup and Restore with Mariabackup


You can do both full or incremental backup with Mariabackup. The full backups are complete backup of MariaDB instance in an empty directory and incremental backups are the backup of changes to the data since the last backup. In this blog post we have have explained how perform a full backup and restore with Mariabackup.

Backup MariaDB Server with Mariabackup

You can backup MariaDB Server using Mariabackup using –backup option mentioning the target directory to place backup file with –target-dir option, Please make sure target directory is empty or even it does not exist

The command to perform a full backup in MariaDB using Mariabackup:

$ mariabackup --backup \
   --target-dir=/mdb/mariadb-backup/DB11backup/ \
   --user=mariabackup --password=MariaBkp

How long it takes to complete the backup completely depends on the database / table size you are backing up. The Mariabackup writes the backup files to the target directory and creates one if it does not exist. The backup process aborts with an error if the target directory exists with files in it

Example of a backup directory:

$ ls /mdb/mariadb-backup/DB11backup/

aria_log.0017160311  mysql                   xtrabackup_checkpoints
aria_log_control  performance_schema      xtrabackup_info
backup-my.cnf     test                    xtrabackup_logfile
ibdata1           xtrabackup_binlog_info

Next step – Preparing the backup

The databases files created in the target directory are not point-in-time consistent and so is not reliable for restoration. So before you try restoring the backup just now completed they have to be prepared to make data files consistent. You can do that with –prepare option:

$ mariabackup --prepare \
   --target-dir=/mdb/mariadb-backup/DB11backup/

Restoring the Backup

To restore the backup from the target directory ( where you have stored the backup successfully ) you can either use –copy-back or –move-back options.

  • –copy-back – Allows you to retain the original backup files
  • –move-back – Moves the original backup files to datadir and so the backup files will be lost after completion of restoration

Things to remember before restoring the backup in MariaDB:

  • Stop MariaDB Server process
  • Ensure MariaDB datadir is empty

Restore from the Mariabackup:

$ mariabackup --copy-back \
   --target-dir=/mdb/mariadb-backup/DB11backup/

Even after restoring the backup with Mariabackup it preserves the directory and related file privileges of the backup, So you made need to grant the ownership of the directory to the user and group of MariaDB Server ( typically mysql for both). For example, to change ownership of files to mysql user and group, you should run the following command:

$ chown -R mysql:mysql /var/lib/mysql/
  • Startup MariaDB Server after completing the above step.

Using rsync to restore the backup

You can also restore the backup in MariaDB Server using rsync or cp, In the example below we have copied restoration using rsync:

$ rsync -avrP /mdb/mariadb-backup/DB11backup/ /var/lib/mysql/
$ chown -R mysql:mysql /var/lib/mysql/
$ rm /var/lib/mysql/ib_logfile*

Note: If you are using Mariabackup from versions prior to MariaDB 10.2.10 , You should also remove pre-existing InnoDB redo log files

Recommended links for extra reading – https://minervadb.com/index.php/2020/05/28/choosing-backup-and-dr-strategies-for-your-mariadb-infrastructure/

UA-155183614-1