You can use the tool Mariadb-backup (formerly called mariabackup) to backup and restore your MariaDB database. For more information, see https://mariadb.com/docs/server/server-usage/backup-and-restore/mariadb-backup.

You can use either the --copy-back or --move-back options to restore your backup. The --copy-back option allows you to keep your original backup files and copies the new backup files to a different location. The --move-back option moves the backup from the target directory to the data directory.

  1. Backup your database by running the following command:

    $ mariabackup --backup \

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

    --encrypted-backup --user=mariabackup --password=mypassword\

    Note: Ensure that the target directory is empty before you begin.

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

    $ mariabackup --prepare \

    --use-memory=124M --target-dir=/var/mariadb/backup/

    Note: The --use-memory command defines the buffer pool size that is used during the preparation stage. If you see errors while preparing a backup, try increasing the buffer pool size.

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

    1. Stop the MariaDB service using the following command:  systemctl stop mariadb

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

    3. Run the Mariadb-backup command with your preferred option. For example:

      $ mariabackup --copy-back \

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

    4. If necessary, update the file permissions using the chown -R mysql:mysql /var/lib/mysql/ command.

    5. Start the MariaDB service using the systemctl start mariadb command.