So on top of the 8,000 other things I've been dealing with in the last week, I did some experimenting with rsync for work. I really liked it, and decided that once I got a chance, I wanted to switch to using rsync to upload my sources for my web sites. And so the weekend finally came, and after sleeping straight through Saturday afternoon/evening, I woke up and started playing with rsync, when Kevin messaged me:
Benjy (10:23 PM): Time to play with rsync.
Kevin (10:23 PM): I know it. I'm looking into it.
Benjy (10:24 PM): No, I mean, I'm actually playing with rsync right now.
Kevin (10:24 PM): Oh, did you read my just-finished post?
Benjy (10:24 PM): no...
Kevin (10:24 PM): That's pretty coincidental.
So before, I was using a Makefile + tar --after-date=($TODAY) ... + scp + ssh to copy updates to the web server. This worked okay, but it was pretty messy, and I had to manually specify the directories to include, and I had to manually exclude certain things from being copied every time, and so on. But here's what the new rsync based Makefile looks like:
all: clean put
put:
rsync -avuz --exclude-from=exclude \
--delete -e ssh gimli/ bsii@gimli:
get:
rsync -avuz --exclude-from=exclude \
-e ssh bsii@gimli: gimli/
clean:
@echo 'Removing those pesky backup files'
find gimli/ -name "*~" -exec rm {} \;
find gimli/ -name "*bak" -exec rm {} \;
find gimli/ -name "*#" -exec rm {} \;
find gimli/ -name "#*#" -exec rm {} \;
find gimli/ -name ".#*" -exec rm {} \;
The directory ~/gimli/ on my local machine contains everything that goes in my home directory on my web server. The file ~/exclude contains directories that should never be touched on either side -- notably, log files on the server side.
Because I use the `-e ssh` option to rsync, it uses ssh, so all of the communication is encrypted. And the best part is, you can do all of this on a default Mac OS X install, because it comes with rsync and ssh and make and everything you need! Yummy.
And then, as I make changes, I can just periodically type `make`, and it uploads just the bits that are different. And the advantage of this over my old system is that, if I make changes on the server side while I'm away from my own computer, I can type `make get` later and it'll update my local copy with what was changed on server. If you want more details about my setup, please ask.
disclaimer! It would be very easy to blow away your files by just running those commands that are in this post! Before you start playing with rsync, make sure you have a backup of all of your files on both ends! Also, be sure to use the -n option to rsync for a dry run -- it'll tell you exactly what it plans to do. Finally, be really careful with rsync's --delete. And if something does happen to your files, it's not my fault!