Skip to content

Instantly share code, notes, and snippets.

@tonybolzan
Created March 26, 2014 21:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tonybolzan/9793414 to your computer and use it in GitHub Desktop.
Save tonybolzan/9793414 to your computer and use it in GitHub Desktop.
Backup (mysqldump) all your MySQL databases in separate files
#!/bin/bash
# MySQL Dump All
#
# Backup (mysqldump) all your MySQL databases in separate files
#
# Author Tonin R. Bolzan <tonin@bolzan.io>
# License http://www.opensource.org/licenses/mit-license.php MIT License
# https://gist.github.com/tonybolzan
BACKUPFOLDER="/backup"
DATABASES=$(mysql --defaults-file=/etc/mysql/debian.cnf -Bse 'SHOW DATABASES WHERE `database` NOT IN ("information_schema", "performance_schema", "mysql", "test");')
DATE=$(date +"%y-%m-%d")
mkdir -p $BACKUPFOLDER
for DB in $DATABASES; do
mysqldump --defaults-file=/etc/mysql/debian.cnf -CER --triggers --add-drop-database --hex-blob --databases $DB | gzip > $BACKUPFOLDER/$DATE-$DB.sql.gz
# You can use Google Drive Uploader to send backups to your Google Account
# https://gist.github.com/tonybolzan/9792813
# google_drive_upload.sh $BACKUPFOLDER/$DATE-$DB.sql.gz
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment