Last active
February 28, 2016 19:33
-
-
Save uneak/e35076a262088c5c4abc to your computer and use it in GitHub Desktop.
Git hooks mysql dump automatisation
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 | |
# db info | |
host="DBHOST" | |
user="DBUSER" | |
pass="DBPASS" | |
name="DBNAME" | |
# path info | |
project="/var/www/uneak" | |
dumppath="db_backup/dump" | |
dumpfile="oncommit-dump.sql" | |
# cmd | |
mysqldump="/usr/bin/mysqldump" | |
mysql="/usr/bin/mysql" | |
dumpoptions="--skip-extended-insert" |
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 | |
# | |
# Uneak 28/02/2016 | |
# Auto restore dump db on pull, merge, ou checkout | |
# | |
eval ". $(dirname "$0")/config" && | |
echo "updating $name database" | |
if [ -z $pass ] | |
then | |
eval "$mysql -h $host -u $user $name < $project/$dumppath/$dumpfile" | |
else | |
eval "$mysql -h $host -u $user -p$pass $name < $project/$dumppath/$dumpfile" | |
fi && | |
echo "$name database updated" | |
#exit 0 |
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 | |
# | |
# Uneak 28/02/2016 | |
# Auto dump db on commit | |
# | |
eval ". $(dirname "$0")/config" && | |
echo "dumping $name database ..." && | |
## | |
## | |
mkdir -p "$project/$dumppath" && | |
if [ -z $pass ] | |
then | |
eval "$mysqldump -h $host -u $user $dumpoptions $name > $project/$dumppath/$dumpfile" | |
else | |
eval "$mysqldump -h $host -u $user -p$pass $dumpoptions $name > $project/$dumppath/$dumpfile" | |
fi && | |
cd "$project" && | |
git add "$dumppath/$dumpfile" && | |
echo "$name database dumped" | |
#exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Change file permission :
sudo chmod +x .git/hooks/config
sudo chmod +x .git/hooks/pre-commit
sudo chmod +x .git/hooks/post-checkout
sudo chmod +x .git/hooks/post-merge