All Projects → fradelg → docker-mysql-cron-backup

fradelg / docker-mysql-cron-backup

Licence: Apache-2.0 License
Docker image to backup all your databases periodically

Programming Languages

shell
77523 projects
Dockerfile
14818 projects
Makefile
30231 projects

Projects that are alternatives of or similar to docker-mysql-cron-backup

Docker Backuppc
Docker container with BackupPC version 4.x/3.x based on Alpine distribution.
Stars: ✭ 53 (-63.19%)
Mutual labels:  backups, alpine
docker-flask
Alpine + Docker + Flask + Gunicorn + Supervisor
Stars: ✭ 16 (-88.89%)
Mutual labels:  alpine
docker-geoserver
A basic docker geoserver image with JAI and marlin renderer running on tomcat
Stars: ✭ 17 (-88.19%)
Mutual labels:  alpine
alpine-grav
Grav running on Alpine Linux [Docker]
Stars: ✭ 14 (-90.28%)
Mutual labels:  alpine
alpine-php-wordpress
Wordpress running on Alpine Linux [Docker]
Stars: ✭ 30 (-79.17%)
Mutual labels:  alpine
docker-aws-s3-sync
Docker container to sync a folder to Amazon S3
Stars: ✭ 21 (-85.42%)
Mutual labels:  alpine
docker-alpine-bash
Docker image with Bash and complete utils (busybox replacements) (10MB)
Stars: ✭ 25 (-82.64%)
Mutual labels:  alpine
spring-boot-docker
Lightweight Spring Boot Docker image based on Alpine + Docker Compose file
Stars: ✭ 25 (-82.64%)
Mutual labels:  alpine
docker-base
Just enough to get process supervision and startup mechanisms
Stars: ✭ 25 (-82.64%)
Mutual labels:  alpine
docker-alpine-gcc
The smallest Docker image with C compiler (GCC) (130MB)
Stars: ✭ 48 (-66.67%)
Mutual labels:  alpine
alpine-buildpack-deps
An attempt at a "buildpack-deps"-like Docker image with Alpine Linux
Stars: ✭ 30 (-79.17%)
Mutual labels:  alpine
alpinist
Automatic Alpine Linux Package (apk) Repository Generation using AWS Lambda, S3 & SSM Parameter Store
Stars: ✭ 45 (-68.75%)
Mutual labels:  alpine
borg-import
importer for rsync+hardlink based backups / rsnapshot
Stars: ✭ 33 (-77.08%)
Mutual labels:  backups
runrestic
A wrapper script for Restic backup software that inits, creates, prunes and checks backups
Stars: ✭ 81 (-43.75%)
Mutual labels:  backups
docker-jitsi-meet
Docker Jitsi Meet WebRTC conferencing system w/Prosody XMPP and s6 overlay
Stars: ✭ 66 (-54.17%)
Mutual labels:  alpine
dcos-k8s-rust-skaffold-demo
A demo of pipelining Rust application development to Kubernetes on DC/OS with Skaffold.
Stars: ✭ 40 (-72.22%)
Mutual labels:  alpine
dockerfiles-nginx-auth-ldap
Nginx on Alpine with LDAP authentication module from kvspb/nginx-auth-ldap
Stars: ✭ 25 (-82.64%)
Mutual labels:  alpine
docker-nagios
Docker image for Nagios Core in Alpine Linux with basic plugins, available for x86, x64 , ARM v6, ARM v7 and ARM64.
Stars: ✭ 33 (-77.08%)
Mutual labels:  alpine
ptrack
Block-level incremental backup engine for PostgreSQL
Stars: ✭ 21 (-85.42%)
Mutual labels:  backups
SyntaxNet-Tensorflow
Minimal Tensorflow Docker image with SyntaxNet/DRAGNN based on Alpine linux
Stars: ✭ 35 (-75.69%)
Mutual labels:  alpine

mysql-cron-backup

Run mysqldump to backup your databases periodically using the cron task manager in the container. Your backups are saved in /backup. You can mount any directory of your host or a docker volumes in /backup. Othwerwise, a docker volume is created in the default location.

Usage:

docker container run -d \
       --env MYSQL_USER=root \
       --env MYSQL_PASS=my_password \
       --link mysql
       --volume /path/to/my/backup/folder:/backup
       fradelg/mysql-cron-backup

Variables

  • MYSQL_HOST: The host/ip of your mysql database.
  • MYSQL_PORT: The port number of your mysql database.
  • MYSQL_USER: The username of your mysql database.
  • MYSQL_PASS: The password of your mysql database.
  • MYSQL_PASS_FILE: The file in container where to find the password of your mysql database (cf. docker secrets). You should use either MYSQL_PASS_FILE or MYSQL_PASS (see examples below).
  • MYSQL_DATABASE: The database name to dump. Default: --all-databases.
  • MYSQLDUMP_OPTS: Command line arguments to pass to mysqldump (see mysqldump documentation).
  • CRON_TIME: The interval of cron job to run mysqldump. 0 3 * * sun by default, which is every Sunday at 03:00. It uses UTC timezone.
  • MAX_BACKUPS: The number of backups to keep. When reaching the limit, the old backup will be discarded. No limit by default.
  • INIT_BACKUP: If set, create a backup when the container starts.
  • INIT_RESTORE_LATEST: If set, restores latest backup.
  • TIMEOUT: Wait a given number of seconds for the database to be ready and make the first backup, 10s by default. After that time, the initial attempt for backup gives up and only the Cron job will try to make a backup.
  • GZIP_LEVEL: Specify the level of gzip compression from 1 (quickest, least compressed) to 9 (slowest, most compressed), default is 6.
  • USE_PLAIN_SQL: If set, back up and restore plain SQL files without gzip.
  • TZ: Specify TIMEZONE in Container. E.g. "Europe/Berlin". Default is UTC.

If you want to make this image the perfect companion of your MySQL container, use docker-compose. You can add more services that will be able to connect to the MySQL image using the name my_mariadb, note that you only expose the port 3306 internally to the servers and not to the host:

Docker-compose with MYSQL_PASS env var:

version: "2"
services:
  mariadb:
    image: mariadb
    container_name: my_mariadb
    expose:
      - 3306
    volumes:
      - data:/var/lib/mysql
      # If there is not scheme, restore the last created backup (if exists)
      - ${VOLUME_PATH}/backup/latest.${DATABASE_NAME}.sql.gz:/docker-entrypoint-initdb.d/database.sql.gz
    environment:
      - MYSQL_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD}
      - MYSQL_DATABASE=${DATABASE_NAME}
    restart: unless-stopped

  mysql-cron-backup:
    image: fradelg/mysql-cron-backup
    depends_on:
      - mariadb
    volumes:
      - ${VOLUME_PATH}/backup:/backup
    environment:
      - MYSQL_HOST=my_mariadb
      - MYSQL_USER=root
      - MYSQL_PASS=${MARIADB_ROOT_PASSWORD}
      - MAX_BACKUPS=15
      - INIT_BACKUP=0
      # Every day at 03:00
      - CRON_TIME=0 3 * * *
      # Make it small
      - GZIP_LEVEL=9
    restart: unless-stopped

volumes:
  data:

Docker-compose using docker secrets:

The database root password passed to docker container by using docker secrets.

In example below, docker is in classic 'docker engine mode' (iow. not swarm mode) and secret source is a local file on host filesystem.

Alternatively, secret can be stored in docker secrets engine (iow. not in host filesystem).

version: "3.7"

secrets:
  mysql_root_password:
    # Place your secret file somewhere on your host filesystem, with your password inside
    file: ./secrets/mysql_root_password

services:
  mariadb:
    image: mariadb:10
    container_name: my_mariadb
    expose:
      - 3306
    volumes:
      - data:/var/lib/mysql
      - ${VOLUME_PATH}/backup:/backup
    environment:
      - MYSQL_DATABASE=${DATABASE_NAME}
      - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql_root_password
    secrets:
      - mysql_root_password
    restart: unless-stopped

  backup:
    build: .
    image: fradelg/mysql-cron-backup
    depends_on:
      - mariadb
    volumes:
      - ${VOLUME_PATH}/backup:/backup
    environment:
      - MYSQL_HOST=my_mariadb
      - MYSQL_USER=root
      - MYSQL_PASS_FILE=/run/secrets/mysql_root_password
      - MAX_BACKUPS=10
      - INIT_BACKUP=1
      - CRON_TIME=0 0 * * *
    secrets:
      - mysql_root_password
    restart: unless-stopped

volumes:
  data:

Restore from a backup

List all available backups :

See the list of backups in your running docker container, just write in your favorite terminal:

docker container exec <your_mysql_backup_container_name> ls /backup

Restore using a compose file

To restore a database from a certain backup you may have to specify the database name in the variable MYSQL_DATABASE:

mysql-cron-backup:
    image: fradelg/mysql-cron-backup
    command: "/restore.sh /backup/201708060500.${DATABASE_NAME}.sql.gz"
    depends_on:
      - mariadb
    volumes:
      - ${VOLUME_PATH}/backup:/backup
    environment:
      - MYSQL_HOST=my_mariadb
      - MYSQL_USER=root
      - MYSQL_PASS=${MARIADB_ROOT_PASSWORD}
      - MYSQL_DATABASE=${DATABASE_NAME}

Restore using a docker command

docker container exec <your_mysql_backup_container_name> /restore.sh /backup/<your_sql_backup_gz_file>

if no database name is specified, restore.sh will try to find the database name from the backup file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].