Skip to content

Instantly share code, notes, and snippets.

@uneak
Last active February 28, 2016 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uneak/e35076a262088c5c4abc to your computer and use it in GitHub Desktop.
Save uneak/e35076a262088c5c4abc to your computer and use it in GitHub Desktop.
Git hooks mysql dump automatisation
#!/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"
#!/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
#!/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
@uneak
Copy link
Author

uneak commented Feb 28, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment