Skip to content

Instantly share code, notes, and snippets.

@linosteenkamp
Created November 1, 2018 10:49
Show Gist options
  • Save linosteenkamp/ab868758211a678bfde8aae21ecb2fcb to your computer and use it in GitHub Desktop.
Save linosteenkamp/ab868758211a678bfde8aae21ecb2fcb to your computer and use it in GitHub Desktop.
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