-
-
Save LL782/8654285 to your computer and use it in GitHub Desktop.
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 | |
# | |
# A hook script to export your database on every commit. | |
# | |
# The export is saved to a temp file. If the export | |
# fails, the file is trashed. Otherwise it overwrites the tracked file. | |
# | |
# Called by "git commit" with no arguments. The hook should | |
# exit with non-zero status after issuing an appropriate message if | |
# it wants to stop the commit. | |
# | |
# To enable this hook: | |
# $ cd /path/to/repo | |
# git clone https://gist.github.com/rpowis/5198224.git .git/hooks/pre-commit | |
# chmod +x .git/hooks/pre-commit | |
# Users Initials | |
USR="" | |
# Database Details | |
DB_DIR="db" | |
DB_NAME="" | |
DB_HOST="" | |
DB_USER="" | |
DB_PASS="" | |
# Create directory if it doesn't exist | |
if [ ! -d "$DB_DIR" ]; then | |
mkdir -p ${DB_DIR} | |
fi | |
# File names | |
TMP="${DB_DIR}/${DB_NAME}_TMP.sql" | |
if [ -z "$USR" ]; then | |
FILE="${DB_DIR}/${DB_NAME}.sql" | |
else | |
FILE="${DB_DIR}/${DB_NAME}_${USR}.sql" | |
fi | |
# Export Database | |
mysqldump --add-drop-table --skip-extended-insert --skip-comments -h ${DB_HOST} -u ${DB_USER} -p${DB_PASS} ${DB_NAME} > ${TMP} | |
if [[ "$?" -eq 0 ]]; then | |
mv $TMP $FILE | |
echo 'DATABASE EXPORT COMPLETE!' | |
else | |
rm $TMP | |
echo 'DATABASE EXPORT FAILED!' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment