Skip to content

Instantly share code, notes, and snippets.

@simi
Last active December 17, 2015 22:58
Show Gist options
  • Select an option

  • Save simi/5685419 to your computer and use it in GitHub Desktop.

Select an option

Save simi/5685419 to your computer and use it in GitHub Desktop.
backup entire mysql to s3
#!/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