/docker-mysql-backup-s3

Backups mysql database and sends the dump to AWS S3, also sends notification to Slack

Primary LanguageShell

Docker-mysql-backup-s3

container to backup and restore your mysql database's to using awscli.

Container startup explained

  • This container user cron to make backups

  • Mysql will dump the database to this container and compress it using gzip

  • Using s3cli the file will be uploaded to S3 Storage

  • To restore a db just enter the container and run the 'restore' script with the file name to restore:

    ./restore example.sql.gz
  • To run a manual backup just enter the container and run:

    ./backup

Environment variables

  • $MYSQL_PASSWORD - The password to connect with Mysql.

  • $MYSQL_USER - The username to connect with Mysql.

  • $DB_NAME - Database name.

  • $AWS_ACCESS_KEY_ID - Aws acess key.

  • $AWS_SECRET_ACCESS_KEY -Aws secret key.

  • $BUCKET - Aws bucket name .

  • $REGION - Aws region where your bucket is.

  • $MYSQL_PORT - Port to connect with Mysql. default 3306.

  • $MYSQL_HOST - Host where mysql is running.

  • $FILENAME - Name to file in Azure Storage. Default name default-date +"%Y-%m-%d_%H-%M" output example default-2015-08-03_17-58

  • $BACKUP_WINDOW - What time should backup run. you should use crontab format, so see [documentation](http://www.freebsd.org/cgi/man.cgi?crontab(5). default value every day at 6 am.

  • $SLACK_WEBHOOK - Put the Webhook URL here

  • _ NOT WORKING! $SLACK_TOKEN_ - Your slack token. NOT WORKING!

  • _ NOT WORKING! $SLACK_CHANNEL_ - Slack channel to send message. NOT WORKING!

Example of running

docker run --rm --name mysql-backup \
  --env AWS_ACCESS_KEY_ID=AKIAIDHJDJCCC2KM4SSA \
  --env AWS_SECRET_ACCESS_KEY=HT1PWzBN5sjVPFHCuTX+VQs+8nQ00KteoI44iBfz \
  --env BUCKET=backups.example.com \
  --env REGION=eu-west-1  \
  --env FILENAME=backup \
  --env MYSQL_HOST=test.mysql.net \
  --env MYSQL_USER=root \
  --env MYSQL_PASSWORD=password \
  --env DB_NAME=mysql-db \
  --env BACKUP_WINDOW='0 6 * * *' \
  --env SLACK_WEBHOOK=https://hooks.slack.com/services/XXXXXXXXXXX \ 
  bsdigital/docker-mysql-backup-s3

This will upload to Aws S3 a file named backup-2015-08-04_09-47.sql.gz.

Building image

docker build -t bsdigital/docker-mysql-backup-s3 .