Last active
September 25, 2015 21:24
-
-
Save Voronenko/8fcd28fc79154153faa9 to your computer and use it in GitHub Desktop.
Batch import databases from subfolders by rule: folder name is database name, the most recent sql file in folder - one to import
This file contains hidden or 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 | |
HOMEDIR=${PWD} | |
if [ -f .nodbs ] ; then | |
echo ".nodbs flag present, db import skipped"; | |
exit 0 | |
fi | |
for d in */ ; do | |
DBNAME="$(echo $d | cut -d '=' -f 2 | sed 's/\/$//')" | |
echo "IMPORTING DB: $DBNAME" | |
cd "$HOMEDIR/$DBNAME" | |
mysql -u{{mysql_root_user}} -p{{mysql_root_password}} -e "drop database if exists $DBNAME" | |
mysql -u{{mysql_root_user}} -p{{mysql_root_password}} -e "create database if not exists $DBNAME CHARACTER SET utf8 COLLATE utf8_general_ci" | |
last_dump=$(find ./*.sql -type f -exec stat -c "%n" {} + | sort -r | head -n1) | |
mysql -u{{mysql_root_user}} -p{{mysql_root_password}} $DBNAME< $last_dump | |
done | |
touch "$HOMEDIR/.nodbs" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment