Skip to content

Instantly share code, notes, and snippets.

@jlbfalcao
Created August 26, 2011 01:44
Show Gist options
  • Save jlbfalcao/1172506 to your computer and use it in GitHub Desktop.
Save jlbfalcao/1172506 to your computer and use it in GitHub Desktop.
MySQL Backup/Restore between git-branches
#!/bin/sh
BRANCH=`git status --short -b | head -n 1 | awk '{print $2}'`
# echo $BRANCH
echo ""
mkdir -p backups
FILE="backups/$BRANCH.sql.gz"
if [ "$1" == "restore" ]; then
if [ -e "$FILE" ]; then
echo "restoring ${FILE}"
gunzip -c $FILE | mysql -u root itsm_development
rake db:schema:dump # restore db/schema.rb
else
echo "${FILE} doesn't exist...!"
fi
else
if [ -e "$FILE" ]; then
echo "${FILE} exist...giving up!"
exit -1
fi
echo "saving ${FILE}"
mysqldump --add-drop-database --databases itsm_development -u root | gzip -c > $FILE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment