Last active
May 24, 2018 16:12
-
-
Save landbryo/8ca46de961b39c177a9492d0b6a9568b to your computer and use it in GitHub Desktop.
Script for dumping a database to /tmp/dbbackup/
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/sh | |
rm -rf /tmp/dbbackup/ | |
MYSQL_USER="root" | |
MYSQL_PASS="password" | |
NOW=$(date +"%Y-%m-%dT%H_%M_%S") | |
BACKUP_DIR=/tmp/dbbackup/$NOW | |
test -d "$BACKUP_DIR" || mkdir -p "$BACKUP_DIR" | |
# Get the database list, exclude information_schema | |
for db in $(mysql -B -s -u $MYSQL_USER --password=$MYSQL_PASS -e 'show databases' | grep -v information_schema | grep -v performance_schema) | |
do | |
# dump each database in a separate file | |
mysqldump --default-character-set=utf8 -u $MYSQL_USER --password=$MYSQL_PASS "$db" | gzip > "$BACKUP_DIR/$db.sql.gz" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment