Skip to content

Instantly share code, notes, and snippets.

@HashandSalt
Last active June 12, 2017 11:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HashandSalt/90b55701827a2adf1bd086bdd22c4711 to your computer and use it in GitHub Desktop.
Save HashandSalt/90b55701827a2adf1bd086bdd22c4711 to your computer and use it in GitHub Desktop.
Bash script for deploying website with Rsync
#!/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
@HashandSalt
Copy link
Author

HashandSalt commented Jun 12, 2017

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:live:sim": "./deploy.sh live",
    "deploy:live": "./deploy.sh live go",
    "deploy:staging:sim": "./deploy.sh staging",
    "deploy:staging": "./deploy.sh staging go"

./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

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