Skip to content

Instantly share code, notes, and snippets.

@clarete
Created November 26, 2013 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clarete/7666026 to your computer and use it in GitHub Desktop.
Save clarete/7666026 to your computer and use it in GitHub Desktop.
Backup each database inside of mysql in a separate .sql.gz file
#!/bin/bash
#
# I usually start the server with the following command
# before running this script:
#
# $ mysqld_safe --skip-grant-tables
#
# Than just run the following script and all the databases
# are gonna be saved in separate files in the current
# directory. Ps.: It does not check for existing files,
# it overwrites everything. You've been warned.
DBS="$(mysql -uroot -Bse 'show databases' | grep -v _schema)"
for db in $DBS; do
FILE="$db.sql.gz"
mysqldump --add-drop-table --allow-keywords -q -c -uroot $db | gzip -9 > $FILE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment