Skip to content

Instantly share code, notes, and snippets.

@ianlintner-wf
Last active October 21, 2015 21:55
Show Gist options
  • Save ianlintner-wf/d61023e58a445c974966 to your computer and use it in GitHub Desktop.
Save ianlintner-wf/d61023e58a445c974966 to your computer and use it in GitHub Desktop.
#!/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