Last active
June 14, 2017 12:06
-
-
Save ijin82/480e630a5a576d9ec788a6e0ad4bf76f to your computer and use it in GitHub Desktop.
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 | |
# Optional variables for a backup script | |
MYSQL_USER="root" | |
MYSQL_PASS="secret" | |
BACKUP_DIR=./$(date +%Y-%m-%d_%H%M%S); | |
test -d "$BACKUP_DIR" || mkdir -p "$BACKUP_DIR" | |
# Get the database list | |
for db in $(mysql -B -s -u $MYSQL_USER --password=$MYSQL_PASS -e 'show databases') | |
do | |
case "$db" in | |
performance_schema|mysql|information_schema) | |
# ignore some databases | |
echo "-> IGNORED DB: $db" | |
continue | |
;; | |
*) | |
# dump each database in a separate file | |
echo "processing: $db ..." | |
mysqldump -u $MYSQL_USER --password=$MYSQL_PASS "$db" | gzip > "$BACKUP_DIR/$db.sql.gz" | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment