I’m currently building a new site using a minimal flat file markdown-embracing CMS called Pico. Once nice thing about flat file systems, of course, is easy deployment. Just grab all your files, push them to any host and you’re good to go.
I’m using Git only for keeping track of the codebase and don’t want to add content files to the repository.
However, it would be tedious to manually keep track of the files added, changed and removed, so I decided to let rsync take care of that.
I found this nice shell script on Codewall
#!/bin/bash $ERRORSTRING = "Error. Please make sure you've indicated correct parameters" if [ $# -eq 0 ] then echo $ERRORSTRING; elif [ $1 == "live" ] then if [[ -z $2 ]] then echo "Running dry-run" rsync --dry-run -az --force --delete --progress --exclude-from=rsync_exclude.txt -e "ssh -p22" ./ username@server:/var/www/website-name elif [ $2 == "go" ] then echo "Running actual deploy" rsync -az --force --delete --progress --exclude-from=rsync_exclude.txt -e "ssh -p22" ./ username@server:/var/www/website-name else echo $ERRORSTRING; fi fi
All you have to do is put that into your project’s root, make it executable and change the username, server and path to suite your environment. You can optionally provide a list of files and directories in a file called
rsync_exclude.txt. Here’s how my exclude list looks like currently:
.git/ .DS_Store Thumbs.db config.php *.sass-cache/ .htaccess .htpasswd
When I used this script to deploy from my local development (Mac) to the stage (Linux) environment I was a bit disappointed. All newly transferred files lacked proper permissions, resulting in
403 Permission Denied errors when trying to access them on the web. After trying various different rsync modes I gave up and added the desired chmod command as a parameter to the rsync command:
I found this on StackOverflow.