Created
November 4, 2011 20:41
-
-
Save miend/1340421 to your computer and use it in GitHub Desktop.
full mysql backups with push 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/sh | |
# Dumps all MySQL databases, each to its own file, rotates out old backups. | |
# set correct dates | |
NOWDATE=`date +%Y-%m-%d` | |
LASTDATE=$(date +%Y-%m-%d --date='1 week ago') | |
# dump each database to its own sql file | |
for DB in $(echo 'show databases' | mysql -hhostname -uuser -password=password --batch -N) | |
do | |
mysqldump -hhostname -uuser --password='password' --quote-names --create-options --force $DB > /backup-directory/$DB.sql | |
done | |
# tar all the databases into $NOWDATE-backups.tar.gz | |
tar -czf /destination-directory/$NOWDATE-backup.tar.gz /backup-directory/ | |
# upload all databases | |
/usr/bin/s3cmd put /backup-directory/$NOWDATE-backup.tar.gz s3://my_bucket/$NOWDATE/ | |
# rotate out old backups | |
/usr/bin/s3cmd del --recursive s3://my_bucket/$LASTDATE/ | |
# remove all local dumps | |
rm /destination-directory/$NOWDATE-backup.tar.gz | |
for FILE in $(echo $(ls /backup-directory/)) | |
do | |
rm /backup-directory/$FILE | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry-- this one isn't exactly clear with its directory names.
Edit: Sorry again for not clarifying use of s3cmd (thanks joshuakraemer).