Skip to content

Instantly share code, notes, and snippets.

@kasparsj
Created October 23, 2015 07:00
Show Gist options
  • Save kasparsj/2ccd0cad81306d5a74de to your computer and use it in GitHub Desktop.
Save kasparsj/2ccd0cad81306d5a74de to your computer and use it in GitHub Desktop.
Backup all MySQL databases, copy latest backup to S3
#!/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