Last active
August 29, 2015 13:58
-
-
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.
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/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