Created
October 23, 2015 07:00
-
-
Save kasparsj/2ccd0cad81306d5a74de to your computer and use it in GitHub Desktop.
Backup all MySQL databases, copy latest backup to S3
This file contains 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/sh | |
DB_USER="root" | |
DB_PW="root" | |
DATE=`date +%d%m%y%H%M` | |
S3_BUCKET="s3://my-bucket" | |
# export database | |
mysqldump -u $DB_USER -p${DB_PW} --all-databases | gzip > /opt/backups/db_${DATE}.bak.gz | |
cp /opt/backups/db_${DATE}.bak.gz /opt/backups/db-latest.bak.gz | |
# delete backups older than 5 days | |
find /opt/backups/db* -mtime +5 -exec rm {} \; | |
# sync to amazon | |
aws s3 cp /opt/backups/db-latest.bak.gz ${DB_PW} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment