dsteinkopf / backup-all-mysql

Docker image to do automatic backups of a mysql DB.
https://nerdblog.steinkopf.net/2017/04/backup-all-mysql-docker-image-fuer-einfaches-backup/
GNU General Public License v2.0
14 stars 8 forks source link

Regular backup an DB found in the mysql linked as "mysql" to the voloume /var/dbdumps.

Setup

You have to:

Environment

MYSQLDUMP_ADD_OPTS, MYSQL_CONNECTION_PARAMS, MYSQL_HOST, MYSQL_USER , MYSQL_PASSWORD, can be used with suffix _FILE, if stored in a file . This is usefull for docker secrets (only available for swarm mode), or to hide sensitive data in general ( like MYSQL_PASSWORD ) .

Example : MYSQL_PASSWORD_FILE=/run/secrets/mysql-root Will read the file /run/secrets/mysql-root, and copy the content in the env var MYSQL_PASSWORD

Monitoring

For an easy monitoring of successful backup an error file /var/dbdumps/errorslastrun.log is created (in volume /var/dbddumps. This file contains errors if there were any - it is empty if everything was ok.

So to monitor correct backup you should

Usage example

In docker-compose.yml:

mysql-backup:

  image: dsteinkopf/backup-all-mysql:latest
  environment:
    - BACKUP_INTERVAL=20000
    - BACKUP_FIRSTDELAY=3600
  links:
    - mysql
  restart: always
  volumes:
    - /opt/dockervolumes/wordpress/mysql-backup:/var/dbdumps
    - /etc/localtime:/etc/localtime
    - /etc/timezone:/etc/timezone

In docker-compose.yml, for swarm, with secrets ( secrets is already setup ) :

version: '3.2'

services:
  backup:
    image: dsteinkopf/backup-all-mysql:latest
    environment:
      - BACKUP_INTERVAL=21600 #6h
      - BACKUP_FIRSTDELAY=3600
      - MYSQL_HOST=mariadb
      - MYSQL_ENV_MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql-pwd
    restart: always
    volumes:
      - /opt/dockervolumes/wordpress/mysql-backup:/var/dbdumps
      - /etc/localtime:/etc/localtime
      - /etc/timezone:/etc/timezone
    secrets:
      - mysql-pwd

  mariadb:
    image: mariadb:latest
    secrets:
      - mysql-pwd
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD_FILE: /run/secrets/mysql-pwd

secrets:
  mysql-pwd:
    external: true

-> for example found in my Zabbix Setup (German language)