Skip to content

Instantly share code, notes, and snippets.

@jacquesbh
Created July 9, 2012 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacquesbh/3075130 to your computer and use it in GitHub Desktop.
Save jacquesbh/3075130 to your computer and use it in GitHub Desktop.
Restore a local database with .sql.gz file
# 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