Public | Automated Build

Last pushed: 10 months ago
Short Description
Docker image for backing up and restoring mariadb
Full Description


Docker image for backing up and restoring mariadb

Quick start


Scheduled Backup

This will backup your data each day at 3am

Docker Engine

docker run \
  -v ./backup:/backup \
  -e TIMEZONE="Europe/Berlin" \
  -e SCHEDULE="0 0 3 * *" \
  -e BACKUP_METHOD="mysqldump" \
  -e MYSQL_HOST=mysql \
  -e MYSQL_DATABASE=database \
  -e MYSQL_USER=user \
  -e MYSQL_PASSWORD=pass \
  -t db-backup \
  --detach zeenly/mariadb-backup

Docker Compose

        image: zeenlym/mariadb-backup
            - TIMEZONE=Europe/Berlin
            - SCHEDULE=0 0 3 * *
            - BACKUP_METHOD=mysqldump
            - MYSQL_HOST=mysql
            - MYSQL_DATABASE=database
            - MYSQL_USER=user
            - MYSQL_PASSWORD=pass
            - ./backup:/backup

Manual backup

To backup manually juste exec cmd backup

docker run ... zeenly/mariadb-backup backup

or from running container

docker exec db-backup backup


To restore backup juste exec cmd restore. You will be asking which backup to restore. Il you want the latest add --latest swith.

docker run ... -i -t zeenly/mariadb-backup restore

or from running container

docker exec -it db-backup restore

Don't forget the -it switch

Advance usage

Environment variables

There is no default environment variables, you must set them.



  • MYSQL_HOST : [required] Set mysql host
  • MYSQL_USER : [required] Use this mysql user
  • MYSQL_PASSWORD : [optional] user password
  • MYSQL_DATABASE : [optional] Database to backup


  • BACKUP_METHOD : [required] Choose backup method. Example mysqldump
  • BACKUP_OPTS : [optional] Additional argument to pass to backup method


  • RESTORE_OPTS : [optional] Additional argument to pass to restore

    Restore use BACKUP_METHOD var too


mdbtool is the main python program to backup and restore data. It support plugins so you can choose your way to backup and restore mysql dumps.

Run mdbtool -h for more help.

Backup Method

Only mysqldump is available by default. You may want to add your own by reading Make Your Own Plugin.


This plugins use mysqldump to backup data and save backup files in 7z format into /backup folder. You should mount volume for /backup in order to persist your data in host filesystem.

You can disable compression with --no-compress switch

You can pass arguments directly to mysqldump after the + argument

# Get mysqldump binary help
mdbtool backup mysqldump + --help

Run mdbtool backup mysql -h for more help on this plugin.


You are this far away because you want to develop your own backup method.

Make Your Own Plugin

All mdbtool plugins are stored in /usr/local/mdbtool/plugins directory.

Each plugin should have this architecture:

  • myplugin : plugin directory
  • myplugin/ : python implementation
  • myplugin/ : module for handling backup
  • myplugin/ : module for handling restoration

Plugins may have there own files in their directory. and are both entrypoint. In order for your plugin to be recognize by the plugin system you define the main function :

def main(args):
    ''' Plugin entry point, args is specific plugin args. To get full args use sys.argv.
    pass is optional but this projet was born in order to give both backup and restoration of mariadb database

If your plugin is correct it should appreaded with the command mdbtool backup --list

If you need example see mysqldump plugin

Use your plugin

Now your plguin is created you can make your Dockerfile

FROM zeenly/mariadb-backup

COPY myplugin /usr/local/mdbtool/plugins/myplugin

Then enjoy

Docker Pull Command
Source Repository