Skip to content

Instantly share code, notes, and snippets.


danieleorler/Backup MySQL to S3 Secret

Last active Jan 27, 2016
What would you like to do?
#get the day of week as a number (i.e. 1 = Monday, 7 = Sunday)
DAY_OF_WEEK=$(date +%u)
#backup the datababase passed as argument($1) to the folder /var/local/backups/mysql/
#$DAY_OF_WEEK is appendend o the file name in order to keep a weekly history of nthe backups
mysqldump -u user -ppassword $1 > /var/local/backups/mysql/$1/dump_$DAY_OF_WEEK.sql
#use aws (Amazon's tool) to sync your backups to Amazon S3
#/usr/local/bin/aws - the tool
#s3 - the service we want to use
#sync - the command to run
#/var/local/backups/mysql/ - local folder
#s3://my-backups/mysql/ - Amazon s3 folder
/usr/local/bin/aws s3 sync /var/local/backups/mysql/$1/ s3://my-backups/mysql/$1/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment