Skip to content

fernandoneto/docker-mysql-backup-s3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

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_TOKEN - Your slack token.
  • $SLACK_CHANNEL - Slack channel to send message.

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_TOKEN=abd5682jdj \
  --env SLACK_CHANNEL=slack-group \  
  fernandoneto/docker-mysql-backup-s3

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

Building image

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

About

Backup and restore mysql db using aws s3 storage

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages