Skip to content

Instantly share code, notes, and snippets.

@danieleorler
Last active November 24, 2015 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieleorler/6ae751b0c8e62afcb7e7 to your computer and use it in GitHub Desktop.
Save danieleorler/6ae751b0c8e62afcb7e7 to your computer and use it in GitHub Desktop.
#!/bin/bash
#get the day of week as a number (i.e. 1 = Monday, 7 = Sunday)
DAY_OF_WEEK=$(date +%u)
#backup 'my_database' to the folder /var/local/backups/mysql/
#$DAY_OF_WEEK is appendend to the file's name in order to keep a weekly history of the backups
mysqldump -u user -ppassword my_database > /var/local/backups/mysql/my_database_$DAY_OF_WEEK.sql
#use aws (Amazon's tool) to sync your backups to Amazon S3
#/usr/local/bin/aws - absolute path to Amazon's CLI 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/ s3://my-backups/mysql/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment