OSX SSH rsync - Keep remote directory up to date

Solution 1:

Your best bet is probably to use Folder Actions and adapting the new item alert script to your needs, issuing a call to the command line utility of your choice.

Solution 2:

alias run_rsync='rsync -azP --exclude ".*/" --exclude ".*" --exclude "tmp/" /source_folder username@host:/destination_folder'
run_rsync; fswatch -o . | while read f; do run_rsync; done

Second line runs run_rsync once unconditionally and then - on each change in current directory (or specify exact path instead of .)

You will need fswatch - here is how to install via brew:

brew install fswatch

Rsync options:

  • -a - stands for "archive" and syncs recursively and preserves symbolic links, special and device files, modification times, group, owner, and permissions.
  • -z - compression
  • -P - combines the flags --progress and --partial. The first of these gives you a progress bar for the transfers and the second allows you to resume interrupted transfers
  • --exclude - excludes files by pattern

Solution 3:

You may use launchd instead of folder actions (to get some sample code just google for: launchd folder watcher).

You may then combine you launchd folder watcher item with a scp script similar to this one.

Or, use rsync over ssh like so:

rsync -urltv --delete -e ssh /path/to/dir othermachine:/path/to/dir

For a commercial cross-platform software solution see GoodSync.