Created
November 26, 2013 20:52
-
-
Save clarete/7666026 to your computer and use it in GitHub Desktop.
Backup each database inside of mysql in a separate .sql.gz file
This file contains 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 | |
# | |
# 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