Last active
August 29, 2015 14:09
-
-
Save teledirigido/f86574cdf1e9e929f9af to your computer and use it in GitHub Desktop.
MySQL dump on pre-commit
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 | |
# Pre-commit hook to make a mysql dump right before committing and add it to the commit. | |
# | |
# Change the following values to suit your local setup. | |
# Add this file on your .git/hooks/ and name it as 'pre-commit' | |
# | |
# The name of a database user with read access to the database. | |
DBUSER=[dbuser] | |
# The password associated with the above user. Leave commented if none. | |
DBPASS=[dbpass] | |
# The database associated with this repository. | |
DBNAME=[dbname] | |
# The path relative to the repository root in which to store the sql dump. | |
DBPATH=sql | |
[[ -d $DBPATH ]] || mkdir $DBPATH | |
if [ -n $DBPASS ]; then | |
echo mysqldump -u $DBUSER -p$DBPASS $DBNAME > $DBPATH/$DBNAME.sql | |
mysqldump -u $DBUSER -p$DBPASS $DBNAME > $DBPATH/$DBNAME.sql | |
else | |
mysqldump -u $DBUSER $DBNAME > $DBPATH/$DBNAME.sql | |
fi | |
git add $DBPATH/$DBNAME.sql | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment