pre-push GIT Hook - upload project to remote server through SSH, update Database
#!/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