Skip to content

Commit 8403629

Browse files
committed
mariadb: add Mariabackup (and restore) mechanism
Closes: #MariaDB/mariadb-docker/issues/390
1 parent 9dd29a2 commit 8403629

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

mariadb/content.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,54 @@ For restoring data. You can use the `docker exec` command with the `-i` flag, si
190190
```console
191191
$ docker exec -i some-%%REPO%% sh -c 'exec mysql -uroot -p"$MARIADB_ROOT_PASSWORD"' < /some/path/on/your/host/all-databases.sql
192192
```
193+
194+
## Creating backups with Mariabackup
195+
196+
To perform a backup using Mariabackup, an additional volume for the backup needs to be included when the container is started like this:
197+
198+
```console
199+
$ 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
200+
```
201+
202+
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:
203+
204+
205+
```console
206+
$ docker exec some-%%REPO%% chown mysql: /backup
207+
```
208+
209+
To perform the backup:
210+
211+
``console
212+
$ docker exec some-%%REPO%% gosu mysql mariabackup --backup --target-dir=/backup --user=root --password=my-secret-pw
213+
```
214+
215+
If you wish to take a copy of the `/backup` you can do so without stopping the container or getting an inconsistent backup.
216+
217+
```console
218+
$ docker exec some-%%REPO%% gosu tar -cf - /backup | xz > backup.tar.xz
219+
```
220+
221+
## Restore backups with Mariabackup
222+
223+
These steps restore the backup made with Mariabackup.
224+
225+
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:
226+
227+
```console
228+
$ docker run --rm -v /my/own/backupdir:/backup %%IMAGE%%:latest gosu mysql mariabackup --prepare --target-dir=/backup
229+
```
230+
231+
Now that the image is prepared, start the container with both the data and the backup volumes and restore the backup:
232+
233+
```console
234+
$ 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
235+
```
236+
237+
With `/my/own/newdatadir` containing the restored backup, start normally as this is an initialized data directory:
238+
239+
```console
240+
$ docker run --name some-%%REPO%% -v /my/own/newdatadir:/var/lib/mysql -d %%IMAGE%%:latest
241+
```
242+
243+
For further information on Mariabackup, see the [Mariabackup Knowledge Base](https://mariadb.com/kb/en/mariabackup-overview/).

0 commit comments

Comments
 (0)