Created
November 1, 2018 10:49
-
-
Save linosteenkamp/ab868758211a678bfde8aae21ecb2fcb 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
backup_path="~/sql_restore/" | |
dbs=$(find $backup_path -type f -name "*.gz" | sort) | |
echo "========================== Restore Database ====================================" | |
for db in $dbs; | |
do | |
dbname=`echo $db | basename $db | awk '{print substr($0, 1, index($0, ".") -1 )}'` | |
echo "Starting restore of $dbname database" | |
echo "Drop Database" | |
mysql --login-path=local -e "DROP DATABASE IF EXISTS $dbname" | |
echo "Create Database" | |
mysql --login-path=local -e "CREATE DATABASE IF NOT EXISTS $dbname" | |
echo "Restore Database" | |
gunzip < $db | mysql --login-path=local $dbname | |
done | |
echo "========================== Restore Complete ====================================" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment