Skip to content

Commit 5ce6c3a

Browse files
committed
mariadb: add Mariabackup (and restore) mechanism
gosu mysql -> --user mysql suggestion thanks @yosifkit Closes: #MariaDB/mariadb-docker/issues/390
1 parent b452643 commit 5ce6c3a

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

mariadb/content.md

+50
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,53 @@ 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+
```console
205+
$ docker exec some-%%REPO%% chown mysql: /backup
206+
```
207+
208+
To perform the backup:
209+
210+
```console
211+
$ docker exec --user mysql some-%%REPO%% mariabackup --backup --target-dir=/backup --user=root --password=my-secret-pw
212+
```
213+
214+
If you wish to take a copy of the `/backup` you can do so without stopping the container or getting an inconsistent backup.
215+
216+
```console
217+
$ docker exec --user mysql some-%%REPO%% tar -cf - /backup | xz > backup.tar.xz
218+
```
219+
220+
## Restore backups with Mariabackup
221+
222+
These steps restore the backup made with Mariabackup.
223+
224+
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:
225+
226+
```console
227+
$ docker run --user mysql --rm -v /my/own/backupdir:/backup %%IMAGE%%:latest mariabackup --prepare --target-dir=/backup
228+
```
229+
230+
Now that the image is prepared, start the container with both the data and the backup volumes and restore the backup:
231+
232+
```console
233+
$ docker run --user mysql --rm -v /my/own/newdatadir:/var/lib/mysql -v /my/own/backupdir:/backup %%IMAGE%%:latest mariabackup --copy-back --target-dir=/backup
234+
```
235+
236+
With `/my/own/newdatadir` containing the restored backup, start normally as this is an initialized data directory:
237+
238+
```console
239+
$ docker run --name some-%%REPO%% -v /my/own/newdatadir:/var/lib/mysql -d %%IMAGE%%:latest
240+
```
241+
242+
For further information on Mariabackup, see the [Mariabackup Knowledge Base](https://mariadb.com/kb/en/mariabackup-overview/).

0 commit comments

Comments
 (0)