Created
August 3, 2016 15:10
-
-
Save wyliethomas/26ebdd395230778506a625a34e2a268d to your computer and use it in GitHub Desktop.
MySQL Backup to S3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NOWDATE=`date +%Y-%m-%d` | |
BACKUPNAME="$NOWDATE.sql.gz" | |
echo "Creating backup of database finances to $BACKUPNAME" | |
mysqldump --user=[username] --password=[password] [database] | gzip -9 > $BACKUPNAME | |
echo "Succesfully created database backup" | |
echo "Uploading backup to Amazon S3 bucket…" | |
s3cmd put $BACKUPNAME s3://[path-to-bucket-and-folder]/$BACKUPNAME | |
echo "Successfully uploaded backup to S3" | |
echo "Deleting backup file…" | |
rm $BACKUPNAME | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Ubuntu I used this to install S3cmd:
sudo apt-get install s3cmd
Then in my /home/user directory I create a directory called DATABACKUP and put this shell script in there.
Then this goes in my cron:
0 3 * * * /bin/bash /home/[user]/DATABACKUP/backitup.sh >/dev/null 2>&1
After a while I go through my S3 bucket and delete old archives. I usually keep 30 to 60 days worth of backups depending on the size.