Skip to content

Instantly share code, notes, and snippets.

@bkenny
Created July 1, 2013 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bkenny/5900861 to your computer and use it in GitHub Desktop.
Save bkenny/5900861 to your computer and use it in GitHub Desktop.
Simple bash script to zip all mysql dbs and back them up to S3
#!/bin/bash
BACKUP="/tmp/s3/db"
DATE=`date +"%Y-%m-%d"`
DIR="${BACKUP}/${DATE}/"
if [ ! -d $DIR ];
then
mkdir -p $DIR
fi
for DATABASE in `echo "SHOW DATABASES" | mysql -pSECRET -u da_admin | grep -v ^Database`
do
echo -n Backing up $DATABASE .....
mysqldump -pSECRET -u da_admin $DATABASE | gzip -c > ${DIR}/${DATABASE}.sql.gz 2>/dev/null
echo Done
done
echo -n Uploading to Amazon S3
s3cmd put ${DIR} s3://S3-BUCKET-NAME/db/${DATE}/ --recursive
echo -n Removing local directory ...
rm -rf ${DIR}
echo Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment