Created
March 28, 2015 12:45
-
-
Save pstaender/18c4aaf25461554329b9 to your computer and use it in GitHub Desktop.
Import MySQL Dumps (batch)
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 | |
if [ $# -eq 0 ]; then | |
echo "No arguments supplied" | |
exit 1 | |
fi | |
SOURCEDIR="$1" | |
if [ ! -d "$SOURCEDIR" ]; then | |
echo "$SOURCEDIR does not exists / or is not a dir" | |
exit 1 | |
fi | |
# unzip gzipped sql files | |
ls $SOURCEDIR | while read FILE; do | |
NAME=$(echo $FILE | sed -e "s/-201.*$//") | |
echo "importing $FILE to database $NAME; drop and recreate database;" | |
echo "drop database if exists $NAME; create database $NAME;" | mysql | |
# unzip / extract sql dump and import to mysql | |
gunzip < $SOURCEDIR/$FILE | mysql --database $NAME | |
done | |
echo "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment