Skip to content

Instantly share code, notes, and snippets.

@ianlintner-wf
Last active August 29, 2015 13:58
Show Gist options
  • Select an option

  • Save ianlintner-wf/9961187 to your computer and use it in GitHub Desktop.

Select an option

Save ianlintner-wf/9961187 to your computer and use it in GitHub Desktop.
Read all mysql dumps in a directory and restore them to database that matches filename.
#!/bin/bash
#Load all mysql backups in directory
FILES=/you/restore/db/*.mysql
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 -u root $(basename $f .mysql) < $f"
#mysql -u root -e 'CREATE DATABASE IF NOT EXISTS $(basename $f .mysql);'
mysql -u root $(basename $f .mysql) < $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