Last active
May 14, 2017 00:31
-
-
Save ToX82/ca4502c2e0cabdab8f77 to your computer and use it in GitHub Desktop.
pre-push GIT Hook - upload project to remote server through SSH, update Database
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/sh | |
############## | |
## CONFIGURATION | |
############## | |
# remote access | |
sshUser="" | |
sshPass="" | |
remoteServer="192.168.1.1" | |
remotePath="/var/www/production" | |
# local database | |
localDbName="myapp" | |
# remote database | |
remoteDdbUser="root" | |
remoteDbPass="" | |
remoteDbName="myapp" | |
############## | |
## WORKFLOW | |
############## | |
# create a database backup and add it to the last commit (amend) | |
mysqldump -uroot --skip-extended-insert $localDbName > database.sql | |
git add database.sql | |
git commit --amend --no-edit | |
# since you can't force the password for SSH, echo it here as a hint (don't do this for critical projects! :)) | |
echo When prompted, please insert this password: $sshPass | |
# update all the files through rsync | |
echo | |
echo Updating files... | |
rsync -rzhe ssh --delete --filter=':- .gitignore' ./ $sshUser@$remoteServer:$remotePath | |
# update the database | |
echo | |
echo Updating database... | |
cat database.sql | ssh $sshUser@$remoteServer "mysql -u$remoteDdbUser -p$remoteDbPass $remoteDbName" | |
# and you're done! | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment