Backing up and Restoring your MariaDB Database

You can use the tool Mariabackup to backup and restore your MariaDB database. For more information, see https://mariadb.com/kb/en/mariabackup-overview.

  1. Backup your database by running the following command:

    $ mariabackup --backup \

    --target-dir=/var/mariadb/backup/ \

    --user=mariabackup --password=mypassword

  2. After the backup is complete, prepare the backup for restoration by running the following command: 

    $ mariabackup --prepare \

    --target-dir=/var/mariadb/backup/

  3. Use the --moveback or --copyback commands to restore the database as follows: 

    Note: The --moveback option physically moves the backup files to the new directory, so the original backup files are lost. The --copyback option keeps the original backup files.

    1. Stop the MariaDB service.

    2. Ensure that the directory where you plan to restore the backup is empty.

    3. Run the Mariabackup with your preferred option. For example:

      $ mariabackup --copy-back \

      --target-dir=/var/mariadb/backup/

      Note: This command restores the backup to the same location. If you want to restore the backup on a different VM, you need to share the backup folder to another VM using the SCP command. For example:  scp /var/mariadb/backup user@destination_host:/var/mariadb/backup

    4. If necessary, update the file permissions.

    5. Start the MariaDB service.