Keeping Things in Sync with Syncer

In almost every company I’ve ever worked as a developer I’ve had both a personal work computer as well as a development machine. The development computer may be a virtual machine sitting in a datacenter somewhere or it may be a Dell desktop tucked under my desk next to the file cabinet.

In all cases, I’ve preferred to work on my code locally and sync it with my development machine for testing. This allows me to write code in an off-line mode, and allows me to take advantage of many of the bells and whistles of my IDE.

The process of keeping files in sync between my local and remote computers has always been different, and never ideal… until now.

One of my co-workers recently clued me in to Mac OS X’s File System Events API. This is a low-level OS API that emits events corresponding to very common actions on files, like saving, opening, and closing.

I did some hunting and found this great Ruby script which takes advantage of the API. When the script is running it listens for save events in the current working directory tree and syncs the entire directory tree to a remote location using rsync.

I made some improvements to the script so that it can take command-line options like username, hostname, and a remote directory location. The updated script is available in its own repository from GitHub. Feel free to grab Syncer and play with it.

As it stands right now Syncer makes two assumptions about your operating environment:

  1. You have an ssh-agent running which allows you to connect to your remote server without having to type a password every time. If you don’t already have this, read this great tutorial on ssh-agent. It will tell you everything you need to know.
  2. The script takes advantage of growlnotify, a command-line interface for Growl. growlnotify is an extra in the Growl distribution. So, you need to install it separately.

If you find this script useful let me know.

One response to “Keeping Things in Sync with Syncer

  1. Dude…love your script! Thanks for writing/updating it…Sateesh and Nazim told me about it a month or so ago and I’ve used it ever since. Half the services team is using it, too!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s