Skip to content
A docker image to dump mysql database on a periodic.
Branch: master
Clone or download
Pull request Compare This branch is 2 commits behind hlj-toys:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

mysql dump with a schedule

A docker image to dump mysql database on a periodic.


There are two methods to run this container.


  • Dump a remote database:
  $ docker run -d \
    -e DUMP_DEBUG="true" \
    -e MYSQL_HOST="x.x.x.x" \
    -e MYSQL_USER="myuser" \
    -e MYSQL_PASSWORD="mypassword" \
    -e MYSQL_DATABASE="dbname" \
    -e OPTIONS="<mysqldump_options>" \
    -e SCHEDULE="dump_schdule" \
    -e RESERVES="dump_file_reserve_number" \
    -v /your/backup-folder:/backups betacz/mysql-dump:latest
  • Dump a database that's running on a container:
  $ docker run -d \
    --link your-mysql-db:db
    -e DUMP_DEBUG="true" \
    -e MYSQL_USER="myuser" \
    -e MYSQL_PASSWORD="mypassword" \
    -e MYSQL_DATABASE="dbname" \
    -e OPTIONS="mysqldump_options" \
    -e SCHEDULE="dump_schdule" \
    -e RESERVES="dump_file_reserve_number" \
    -v /your/backup-folder:/backups betacz/mysql-dump:latest

The dumped file will be named as "db_backup_<timestamp>.gz".

Additional, you can do dump immediately like this:

  $ docker run [options] betacz/mysql-dump:latest dump

The [options] is as same as above.


Some environment variable has default value, so you needn't set all of them in most cases.

  • MYSQL_HOST: Database's hostname or address. If you want to backup a database in container at same host, use "--link your-db:db" instead of.
  • MYSQL_USER: Database's username, default is "cattle".
  • MYSQL_PASSWORD: Database's password, default is "cattle".
  • MYSQL_DATABASE: Database's name, default is "--all-databases" that means all database. you can use "db_mame" to dump only one database or "--databases db1 db2..." to dump multiple databases.
  • OPTIONS: Any mysqldump's options you want to use, no default.
  • SCHEDULE: Explained as shown below. default is "daily".
  • RESERVES: Dump file reserve numbers. default is 7.
  • DUMP_DEBUG: If set "true" then show debug info. default is "false".

Schedule syntax:

  • "hourly": 0 minute every hour.
  • "daily": 02:00 every day.
  • "weekly": 03:00 on Sunday every week.
  • "monthly": 05:00 on 1st every month.
  • "0 5 * * 6": crontab syntax.


If you dump a database that's include secret data, maybe you want to encrypt it.

There is a envrionment variable "ENCRYPT_KEY" can do this as shown below:

   $ docker run -e ENCRYPT_KEY=your-key [other-options] betacz/mysql-dump:latest

The dumped file will be encrypted with AES-256-CBC and named with a '.aes' extension.

Decrypt file is also very simple, see example below:

   $ docker run -e ENCRYPT_KEY=your-key \
     -v /your/backup-folder:/backups \
     -v /your/output:/output
     betacz/mysql-dump:latest \
     decrypt db_backup_<timestamp>.gz.aes /output  

The "decrypt" accepts one or two arguments: decrypt <source file> [dest-folder]. If you don't assign dest-folder, the decrypted file will be saved in same folder with source file.


Released under the MIT License.

Copyright Huang lijun

You can’t perform that action at this time.