Regular backup an DB found in the mysql linked as "mysql" to the voloume /var/dbdumps
.
You have to:
dsteinkopf/backup-all-mysql
mysql
to you db to be backed up./var/dbdumps
.BACKUP_INTERVAL
(in seconds).BACKUP_FIRSTDELAY
to delay the very first backup to be done by n seconds. The idea behind this is to prevent existing backups to be overwritten in case of problems. So you can manually kill everything an try again within this delay.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
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
errorslastrun.log
is empty.errorslastrun.log
is touched (modification date changed) regularly (see env BACKUP_INTERVAL
).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)