Created
July 9, 2012 08:37
-
-
Save jacquesbh/3075130 to your computer and use it in GitHub Desktop.
Restore a local database with .sql.gz file
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
# Restore a database | |
function restore() | |
{ | |
if [[ $# < 2 ]]; then | |
echo "Usage: restore <database> <file.sql[.tar].gz> [-gz]" | |
echo "Use -gz option if you want to restore an only gziped file" | |
return 65 | |
fi | |
if [[ -f $2 ]]; then | |
mysqladmin -f drop $1 | |
mysqladmin create $1 | |
if [[ "$3" == '-gz' ]]; then | |
gunzip -c $2 | mysql $1 | |
else | |
tar -Oxzf $2 | mysql $1 | |
fi | |
else | |
echo "File not found." | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment