Last active
October 21, 2015 21:55
-
-
Save ianlintner-wf/d61023e58a445c974966 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 | |
#Load all mysql backups in directory $1 is directory | |
FILES=$1/*.sql | |
if [ ${#FILES[@]} -gt 0 ]; then | |
#Loop through files | |
for f in $FILES | |
do | |
#Alert the user | |
echo "Processing $f file..." | |
# mysql connection based to specific db based | |
# on the filename minus path and ext | |
# also create the db if it does not exist | |
echo "mysql $(basename $f .sql) < $f" | |
mysql -e "drop database $(basename $f .sql)" | |
mysql -e "CREATE DATABASE IF NOT EXISTS $(basename $f .sql);" | |
mysql $(basename $f .sql) < $f | |
# delete the file | |
echo "cleaning up the $f file..." | |
rm -f -r $f | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment