Skip to content

Instantly share code, notes, and snippets.

@mattattui
Created January 5, 2013 09:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattattui/4460787 to your computer and use it in GitHub Desktop.
Save mattattui/4460787 to your computer and use it in GitHub Desktop.
Simple default-safe rsync deployment script
#!/bin/bash
# Will add --dry-run unless the --go option is set. All other arguments passed to rsync (e.g. --delete)
SOURCE=.
DEST=example.com:/var/www/mysite
DRYRUN="--dry-run"
args=()
for var in "$@"
do
if [ $var == "--go" ]
then
DRYRUN=""
else
args=( "${args[@]}" "$var" )
fi
done
/usr/bin/env rsync -azCcO --force --progress --exclude-from=rsync_exclude.txt $DRYRUN "${args[@]}" "$SOURCE" "$DEST"
@mattattui
Copy link
Author

This apes Symfony 1.4's deployment task, which is just a wrapper around rsync. Its most important feature is that it defaults to a dry-run, so you can run it to see the changes that will be made. The rsync options are configured to ignore file patterns listed in an rsync_exclude.txt file, and to perform a checksum match rather than a date & time match, in case you're deploying from a different working directory.

Before using it, modify the DEST variable to match your project. To actually perform the sync, add --go to the command (./deploy.sh --go). All other arguments are passed to rsync.

@mattattui
Copy link
Author

Obviously this is for relatively simple deployments. At the other end of the scale, Capifony is a powerful Ruby-based configurable solution for managing Symfony & Symfony2 deployments to multiple servers and can do stuff like provide atomic, reversible deployments, and run scripts (like database migrations, Composer update, or your test suite). If that's too complicated and this script is too simple, Anchour may suit you better.

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