From 3f680953fcf7156686ac3e7d1779fa3d89835065 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 16 Nov 2021 16:58:02 +1100 Subject: [PATCH] mariadb: add Mariabackup (and restore) mechanism Closes: #MariaDB/mariadb-docker/issues/390 --- mariadb/content.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/mariadb/content.md b/mariadb/content.md index a342561ffc5ad..cdb6a2c9d995f 100644 --- a/mariadb/content.md +++ b/mariadb/content.md @@ -190,3 +190,54 @@ For restoring data. You can use the `docker exec` command with the `-i` flag, si ```console $ docker exec -i some-%%REPO%% sh -c 'exec mysql -uroot -p"$MARIADB_ROOT_PASSWORD"' < /some/path/on/your/host/all-databases.sql ``` + +## Creating backups with Mariabackup + +To perform a backup using Mariabackup, an additional volume for the backup needs to be included when the container is started like this: + +```console +$ docker run --name some-%%REPO%% -v /my/own/datadir:/var/lib/mysql -v /my/own/backupdir:/backup -e MARIADB_ROOT_PASSWORD=my-secret-pw -d %%IMAGE%%:latest +``` + +Mariabackup will run as the `mysql` user in the container, so the permissions on `/backup` will need to ensure that it can be written to by this user: + + +```console +$ docker exec some-%%REPO%% chown mysql: /backup +``` + +To perform the backup: + +``console +$ docker exec some-%%REPO%% gosu mysql mariabackup --backup --target-dir=/backup --user=root --password=my-secret-pw +``` + +If you wish to take a copy of the `/backup` you can do so without stopping the container or getting an inconsistent backup. + +```console +$ docker exec some-%%REPO%% gosu tar -cf - /backup | xz > backup.tar.xz +``` + +## Restore backups with Mariabackup + +These steps restore the backup made with Mariabackup. + +At some point before doing the restore, the backup needs to be prepared. Here `/my/own/backupdir` contains a previous backup. Perform the prepare like this: + +```console +$ docker run --rm -v /my/own/backupdir:/backup %%IMAGE%%:latest gosu mysql mariabackup --prepare --target-dir=/backup +``` + +Now that the image is prepared, start the container with both the data and the backup volumes and restore the backup: + +```console +$ docker run --rm -v /my/own/newdatadir:/var/lib/mysql -v /my/own/backupdir:/backup %%IMAGE%%:latest gosu mysql mariabackup --copy-back --target-dir=/backup +``` + +With `/my/own/newdatadir` containing the restored backup, start normally as this is an initialized data directory: + +```console +$ docker run --name some-%%REPO%% -v /my/own/newdatadir:/var/lib/mysql -d %%IMAGE%%:latest +``` + +For further information on Mariabackup, see the [Mariabackup Knowledge Base](https://mariadb.com/kb/en/mariabackup-overview/).