Last active
December 17, 2015 22:58
-
-
Save simi/5685419 to your computer and use it in GitHub Desktop.
backup entire mysql 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/bash | |
| # you'll need configured s3cmd and stored password for mysql in ~/.my.cnf | |
| DIR=`pwd` | |
| # cd $DIR | |
| info() { | |
| echo -e "\e[1;34m"$1"\e[0m" | |
| } | |
| info "Dumping MYSQL data" | |
| TIME=`date +"%Y-%m-%d.%H-%M-%S"` | |
| BACKUP_DIR=$DIR"/backup/"$TIME | |
| mkdir -p "$BACKUP_DIR" | |
| mysql -s -N -e 'show databases' | sed "1 d" | while read dbname; do mysqldump --complete-insert --add-drop-table "$dbname" | gzip > $BACKUP_DIR/"$dbname".sql.gz; done | |
| info "Sending to S3" | |
| s3cmd sync $BACKUP_DIR s3://backup/mysql/ > /tmp/backup-s3.log | |
| info "Removing files" | |
| rm -rf $BACKUP_DIR | |
| info "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment