Git Product home page Git Product logo

docker-mysql-backup's Introduction

MySQL backup on Docker

This image allows backing up MySQL Docker containers (running on the same machine) as well as external MySQL servers. It is configured via ENV variables.

Generic ENV variables needed:

  • MYSQL_BACKUP_USER, MYSQL_BACKUP_PASSWORD: User and password for connecting to the MySQL database
  • MYSQL_BACKUP_DATABASE: Database to backup. Optional. Backup all databases otherwise
  • MYSQL_BACKUP_SSH_ADDRESS, MYSQL_BACKUP_SSH_PORT, MYSQL_BACKUP_SSH_KEY: SSH Credentials for the target server where backups will be stored. The key must be base64 encoded (see below).
  • MYSQL_BACKUP_ENCRYPTION_PASSPHRASE: Password for encrypting the backup

Backing up a mysql docker container

Replace MYSQL_CONTAINER_NAME with the name of the target MySQL container. Example:

MYSQL_CONTAINER_NAME=mysql-server
MYSQL_BACKUP_SSH_KEY=$(base64 -w0 id_rsa)

docker run --rm \
  --link ${MYSQL_CONTAINER_NAME}:mysql \
  -e MYSQL_BACKUP_USER=backup -e MYSQL_BACKUP_PASSWORD=password \
  -e MYSQL_BACKUP_SSH_ADDRESS=data@backup: -e MYSQL_BACKUP_SSH_PORT=22 -e MYSQL_BACKUP_SSH_KEY=$MYSQL_BACKUP_SSH_KEY \
  -e MYSQL_BACKUP_ENCRYPTION_PASSPHRASE=secret-passphrase \
  schoolscout/mysql-backup

Backing up an external MySQL server

You need to additionally set the following ENV variables:

  • MYSQL_HOST: hostname/IP of the external MySQL server

Example:

MYSQL_BACKUP_SSH_KEY=$(base64 -w0 id_rsa)

docker run --rm \
  -e MYSQL_HOST=external-mysql-server.example.com \
  -e MYSQL_BACKUP_USER=backup -e MYSQL_BACKUP_PASSWORD=password \
  -e MYSQL_BACKUP_SSH_ADDRESS=data@backup: -e MYSQL_BACKUP_SSH_PORT=22 -e MYSQL_BACKUP_SSH_KEY=$MYSQL_BACKUP_SSH_KEY \
  -e MYSQL_BACKUP_ENCRYPTION_PASSPHRASE=secret-passphrase \
  schoolscout/mysql-backup

Privileges needed on the MySQL server

GRANT SHOW DATABASES, SELECT, SHOW VIEW, LOCK TABLES, RELOAD, EVENT, REPLICATION CLIENT ON *.* TO backup@`172.17.%.%` IDENTIFIED BY '<PASSWORD>';

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.