Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.