Skip to the content.

MySQL backup Docker

Build Status Docker Stars Docker Pulls GitHub release (latest by date) GitHub

This is a docker image for MySQL backup. It is based on Alpine Linux and uses MySQL Client and MySQLDUMP to dump your database.

Download size of this image is:

Image Size

Docker hub image: funnyzak/mysql-backup

Docker Pull Command: docker pull funnyzak/mysql-backup:latest

Attention: Current version is not compatible old version, please use tag 0.1.1 if you want to use old version.

Features

Configuration

The following environment variables are used to configure the container:

Required

The following environment variables are required:

Optional

The following environment variables are optional:

Pushoo

If you want to receive message with pushoo, you need to set PUSHOO_PUSH_PLATFORMS and PUSHOO_PUSH_TOKENS.

For more details, please refer to pushoo-cli.

Usage

Simple

For example, you want to backup database dbname1 and dbname2 every day at 00:00, and delete expired dump files after 180 days.

docker run -d --name mysql-backup \
  -e DB_DUMP_CRON="0 0 * * *" \
  -e DB_HOST="localhost" \
  -e DB_PORT=3306 \
  -e DB_USER="root" \
  -e DB_PASSWORD="root" \
  -e DB_NAMES="dbname1 dbname2" \
  -e DB_DUMP_OPTS="--single-transaction --quick --lock-tables=false" \
  -e EXPIRE_HOURS=4320 \

Compose

For example, you want to backup database cms_new every day at 00:00, and delete expired dump files after 180 days.

version: '3'
services:
  dbback:
    image: funnyzak/mysql-backup
    privileged: false
    container_name: app-db-backup
    tty: true
    mem_limit: 1024m
    environment:
        - TZ=Asia/Shanghai
        - LANG=C.UTF-8
        # Cron
        - DB_DUMP_CRON=0 0 * * *
        # MySQL Connection
        - DB_HOST=192.168.50.21
        - DB_NAMES=cms_new
        - DB_USER=root
        - DB_PASSWORD=helloworld
        - DB_PORT=1009
        - DUMP_OPTS=--single-transaction
        # Expire Hours
        - EXPIRE_HOURS=4320
        # COMMAND
        - STARTUP_COMMAND=echo "startup"
        - BEFORE_DUMP_COMMAND=echo "before dump"
        - AFTER_DUMP_COMMAND=echo "after dump"
        # optional
        - DB_DUMP_TARGET_DIR_PATH=/backup
        - DB_DUMP_BY_SCHEMA=true
        - DB_FILE_EXTENSION=sql
        - COMPRESS_EXTENSION=zip
        - DUMP_AT_STARTUP=true
        # pushoo 
        - SERVER_NAME=app-db-backup
        - PUSHOO_PUSH_PLATFORMS=dingtalk,bark
        - PUSHOO_PUSH_TOKENS=dingtalk:xxxx,bark:xxxx
    restart: on-failure
    volumes:
      - ./bak/mysql_db:/backup

For more details, please refer to the docker-compose.yml file.

Contribution

If you have any questions or suggestions, please feel free to submit an issue or pull request.

License

MIT License © 2022 funnyzak