Skip to content

Instantly share code, notes, and snippets.

@payneio
Last active August 29, 2015 14:10
Show Gist options
  • Save payneio/699a3bb3f80bb8b94186 to your computer and use it in GitHub Desktop.
Save payneio/699a3bb3f80bb8b94186 to your computer and use it in GitHub Desktop.
rsync bash file for simple deployment of static files via ssh
#!/bin/bash
# This deploy script uses rsync with the following configuration:
#
# - Connection variables are read from .deploy.env. That file should set host, username and www_path environment variables.
# - Ignore local files (don't copy them) specified in .deployignore
# - All remote files not existing locally are deleted, except for the remote /share directory.
#
# set host, username and www_path in this non-source-controlled file (use ssh keys to avoid passwords)
source .deploy.env
ERRORSTRING="You must use with a parameter: plan or apply"
if [ $# -eq 0 ]
then
echo $ERRORSTRING;
elif [ $1 == "plan" ]; then
echo "Running dry-run"
rsync --dry-run -az --force --delete --progress --exclude-from=.deployignore --filter="P /share" -e "ssh -p22" ./ $username@$host:$www_path
elif [ $1 == "apply" ]; then
echo "Running actual deploy"
rsync -az --force --delete --progress --exclude-from=.deployignore --filter="P /share" -e "ssh -p22" ./ $username@$host:$www_path
else
echo $ERRORSTRING;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment