Created
July 3, 2014 07:09
-
-
Save dnicolson/82ed8afd3c10f4c3ea9b to your computer and use it in GitHub Desktop.
Git pre-push hook to dump and push a MySQL database
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
#!/bin/bash | |
exit_if_pushing_database() { | |
if [ -f .git_push_lock ]; then | |
exit 0 | |
fi | |
} | |
dump_and_push_database() { | |
mysqldump --skip-comments --skip-dump-date -h localhost -u root db_name > db.sql | |
git add db.sql | |
if [ -n "$(git status --porcelain | grep '^M.*db.sql')" ]; then | |
touch .git_push_lock | |
git commit -m 'Remote database update' && git push origin master | |
rm .git_push_lock | |
fi | |
} | |
exit_if_pushing_database | |
dump_and_push_database & | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment