Skip to content

Instantly share code, notes, and snippets.



Created Nov 4, 2011
What would you like to do?
full mysql backups with push to s3
# 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)
mysqldump -hhostname -uuser --password='password' --quote-names --create-options --force $DB > /backup-directory/$DB.sql
# 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/))
rm /backup-directory/$FILE

This comment has been minimized.

Copy link
Owner Author

@miend miend commented Nov 4, 2011

Sorry-- this one isn't exactly clear with its directory names.

Edit: Sorry again for not clarifying use of s3cmd (thanks joshuakraemer).


This comment has been minimized.

Copy link

@joshkraemer joshkraemer commented Nov 8, 2011

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.