More rsync’ing action

I’ve been doing some (light) development lately at night.  Depending on my mood, sometimes it will be from my desktop Mac, other times from my MacBook Pro.  I wanted to keep everything in my ~/Development directory in sync, so I figured I would whip up something hacky with rsync.

One of my main criteria was that I didn’t want the syncing process to keep around old files from one machine and copy them to the other.  To get around this, whenever I rsync from one machine to the other, I pass the –delete flag to the operation.  This can be dangerous…so I’m very careful that whenever I do a one-way sync (either “push” or “pull” in my parlance), I’m confident I’m not clobbering needed files on the target system.

I have 2 scripts that accomplish this:

The first one is my “pull” script.  This will pull all changes from the remote machine to my local machine.


# "Pull" changes from remote machine directory to target directory on
# local machine.
# This will destroy any changes in target directory on local machine not
# present on remote machine.
# Sync via ssh and compress the files over the wire
rsync -avz -e ssh --delete eric@lenny.local:~/Development/ /Users/eric/Development

The second script is my “push” script.  Basically the same as above, but in reverse.

# Sync the local directory to the remote server, this will "PUSH" the
# changes from local,
# destroying any changes in target directory on remote machine.
# Sync via ssh and compress the files over the wire
rsync -avz -e ssh --delete  /Users/eric/Development/ eric@lenny.local:~/Development

So there you have it.  Pretty basic pushing/pulling (remote mirroring) of files with rsync.

1 Comment so far »

  1. Patrick Forhan said,

    Wrote on June 22, 2009 @ 9:52 am

    If it’s mostly source files you are moving around, sounds like a good case for version control. There are also some projects out there like Unison which do a decent job of Sync’ing.

Comment RSS · TrackBack URI

Leave a Comment

Name: (Required)

E-mail: (Required)