Last active
June 12, 2017 11:37
-
-
Save HashandSalt/90b55701827a2adf1bd086bdd22c4711 to your computer and use it in GitHub Desktop.
Bash script for deploying website with Rsync
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/bash | |
ERRORSTRING="Whoops! That didn't work. Please check the command you ran." | |
if [ $# -eq 0 ] | |
then | |
echo "$ERRORSTRING"; | |
elif [[ "$1" == "live" ]] | |
then | |
if [[ -z $2 ]] | |
then | |
echo "Running live dry-run" | |
rsync --dry-run -az --force --delete --progress --exclude-from=rsync_exclude.txt -e "ssh -p22" ./public/ user@domain.com:/var/www/vhosts/yoursitefolder | |
elif [[ "$2" == "go" ]] | |
then | |
echo "Running live actual deploy" | |
rsync -az --force --delete --progress --exclude-from=rsync_exclude.txt -e "ssh -p22" ./public/ user@domain.com:/var/www/vhosts/yoursitefolder | |
else | |
echo "$ERRORSTRING"; | |
fi | |
elif [[ "$1" == "staging" ]] | |
then | |
if [[ -z $2 ]] | |
then | |
echo "Running staging dry-run" | |
rsync --dry-run -az --force --delete --progress --exclude-from=rsync_exclude.txt -e "ssh -p22" ./public/ user@domain.com:/var/www/vhosts/yoursitefolder | |
elif [[ "$2" == "go" ]] | |
then | |
echo "Running staging actual deploy" | |
rsync -az --force --delete --progress --exclude-from=rsync_exclude.txt -e "ssh -p22" ./public/ user@domain.com:/var/www/vhosts/yoursitefolder | |
else | |
echo "$ERRORSTRING"; | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make the script executable:
chmod +x deploy.sh
Alter the paths and username to match your own.
If your using NPM scripts, you can add this to your package json for easy running:
./deploy.sh live
will do a simulated deploy. No files transferred, will just output what it would do in a real deploy./deploy.sh live go
this will do a real deploy