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:

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:

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:

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:

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:

  • 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:

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 – MariaDB Backup Strategies