Skip to content

Instantly share code, notes, and snippets.

@dnicolson
Created July 3, 2014 07:09
Show Gist options
  • Save dnicolson/82ed8afd3c10f4c3ea9b to your computer and use it in GitHub Desktop.
Save dnicolson/82ed8afd3c10f4c3ea9b to your computer and use it in GitHub Desktop.
Git pre-push hook to dump and push a MySQL database
#!/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