Created
August 26, 2011 01:44
-
-
Save jlbfalcao/1172506 to your computer and use it in GitHub Desktop.
MySQL Backup/Restore between git-branches
This file contains hidden or 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
#!/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