-
-
Save evasilev/f3e060c6c07fd67247a4897cc48e665d to your computer and use it in GitHub Desktop.
Git pre-commit hook for MySQL database backup ( remote mysqldump + Git push )
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 -e | |
# -e means exit if any command fails | |
DBHOST=address.to.your.server | |
DBUSER=username | |
DBPASS=password # do this in a more secure fashion | |
DBNAME=DBNAME | |
GITREPO=/where/is/your/repo | |
DUMP=$GITREPO/where/you/store/dumps | |
NEW=$DUMP/schema.sql | |
OLD=$NEW.old | |
DIR=$(pwd) | |
cd $GITREPO | |
if [ -f "$NEW" ] | |
then | |
mv $NEW $OLD | |
mysqldump -h $DBHOST -u $DBUSER -p$DBPASS $DBNAME --skip-dump-date --single-transaction --no-data > $NEW | |
if cmp -s $OLD $NEW; then | |
echo Databases are the Same | |
else | |
echo changes detected in database schema | |
git add $NEW | |
echo "schema committed" | |
fi | |
else | |
mysqldump -h $DBHOST -u $DBUSER -p$DBPASS $DBNAME --skip-dump-date --single-transaction --no-data > $NEW | |
git add $NEW | |
echo "schema committed" | |
fi | |
cd $DIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment