Giter VIP home page Giter VIP logo

backup-all-mysql's Introduction

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

Setup

You have to:

  • run the container `dsteinkopf/backup-all-mysql``
  • create a link called mysql to you db to be backed up.
  • Create a volume called /var/dbdumps.

Environment

  • Interval may be set via environment BACKUP_INTERVAL (in seconds).
  • Use 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 (default = ""): More options to be added to mysqldump.
  • MYSQL_CONNECTION_PARAMS (default = ""): More mysql option to add to any mysql command (incl. mysqldump)
  • MYSQL_HOST (default = "mysql"): Hostname (or IP) of mysql database.
  • MYSQL_USER (default = "root"): Username to connect to mysql database.
  • MYSQL_PASSWORD ( use MYSQL_ENV_MYSQL_ROOT_PASSWORD if available ): The password to connect to mysql .

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

  • check that errorslastrun.log is empty.
  • chat that errorslastrun.log is touched (modification date changed) regularly (see env BACKUP_INTERVAL).

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)

backup-all-mysql's People

Contributors

dsteinkopf avatar skydiscover avatar thib3113 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.