The power of the command line

I’ve got a rather interesting task to accomplish. We have a staging web server where multiple web editors are making changes to static files. There is also a web publisher that has to sort through all of the changes and then commit the proper changes to cvs so that they can be pushed to the live site. The problem is that the web publisher’s skill level is not quite up to managing command line cvs with large scale diffs and tagging. So, the proposed answer was to pull the htdocs dir from the server down to his laptop to so that he can use the graphical cvs tools from eclipse to manage tagging and committing changes.

At first glance it’s pretty simple to set up a project in eclipse and just use rsync to pull the dir down to local and then manage with cvs. The first pass at the command to accomplish this was:

rsync -zva –delete -e ssh server:/htdocs /localDir

This worked great at first until I noticed that after the initial checkin the CVS dirs were getting deleted. A quick check of the man page showed a very helpful param -C that tells rsync to ignore anything that cvs would ignore. So now the command was:

rsync -zvaC –delete -e ssh server:/htdocs /localDir

This worked better as all of the cvs dirs were left untouched. A new problem became apparent though in that all of the timestamps, users, and permissions were getting changed because of the -a param. This isn’t the behavior that we wanted so the next try was:

rsync -zvCrl –delete -e ssh server:/htdocs /localDir

This didn’t completely solve the timestamp issues since rsync was still updating the timestamps locally even though the files hadn’t changed. There is a way to get around this. With eclipse’s cvs tool to Synchronize there is an option to Clean Timestamps which will set things right again, but it requires a complete compare of the cvs repository which can take awhile on a slow connection. So another version of the rsync command is:

rsync -zvCrl –size-only –delete -e ssh server:/htdocs /localDir

This only updates files if their sizes are different which will work for most html edits. We’re going to have to test if this is sufficient to catch the changes or if we have to go back to the previous option and Clean Timestamps.

What’s really amazing though is how specific you can get with this incredibly efficient method of syncing files with only a few command line parameters. I’m not aware of any other utilities that could handle the sync this easily, just a reading of the manpage and a little trial and error to get it right.