Forwarding Address: OS X

Tuesday, March 04, 2003

This posting, mostly about rsync, is aimed at people like me -- web developers who migrated to OS X with little experience in actually running web servers. I did it almost two years ago and am still learning.

I quickly came to enjoy, and rely on, having a local Apache/MySQL/PHP environment for development, but found that once a site went live I became more tied to the production server than I wanted. It was slowing me down, too, because of the workarounds needed to 1) keep work in progress isolated from live code and 2) integrate that work when testing was complete.

To remedy that situation I've been using rsync, with great success. I set up offline mirrors of live sites I'm working on, complete with their own MySQL databases and local-only virtual domains (e.g. ""). I tweak code with abandon and then, when it's all working perfectly (ahem), I upload the changes to the production server in one step -- using a shell script containing a couple long-ass rsync commandlines.

For those new to rsync, basically my rsync commands say: "here's the development mirror A; here's the live server B; take every file in the following directories on A that's newer than its counterpart on B and upload it, saving the old one as a backup."

Sometimes even a "simple" change involves interdependent changes to half a dozen files in different directories. I don't have to keep track. rsync finds them all. I also have a "dry run" version that has the same commands with the addition of the "-n" option that does everything except actually transfer the files -- for a last-minute sanity check.

(Note 1: In theory you could accomplish the same thing by just uploading everything, but in practice this doesn't work except with very small sites. And if you get around this by selecting which directories or files to upload, well, then you are manually doing the work that rsync can do faster and more accurately.)

(Note 2: This is clearly best suited to smaller operations. With many developers working at once, you want something like CVS. Though rsync can of course sync in either direction, so I can update my mirrors when other developers or HTML coders make changes to the live server.)

rsync has a jillion options, so if this sounds at all appealing I encourage you to curl up with the manpage.

I have used lots of other methods for making code changes to live sites; for efficiency, ease, and safety this beats them all hands down.

Any related tricks or methods to share? Discuss