rsync when working on both sides...

Aaron Morris aaronwmorris at gmail.com
Mon Oct 31 18:41:34 GMT 2005


On 10/30/05, Christian Schneider <christian.schneider at uni-kassel.de> wrote:
> Hi rsync devs and users,
>
> I want to use rsync to synchronize home directories on two PCs. It works
> fine if I start rsync after working on a host each time I leave. But
> instead of operating modes "host1 -> host2" and "host2 -> host1" I would
> like to have a mode "host1 <-> host2" to allow synchronizing at any time
> -> Scenario:
> - on host1 files A,B have been created, C has been deleted
> - on host2 file D has been modified, E deleted
> Desired result after invoking rsync:
> - host1 and host2 have files C,E removed and A,B,D updated
> Is there an rsync switch supporting this?
>
> As I have not found such a switch I'm using the script at the end of
> this mail - which seems to work fine (provided that the created file
> 'syncedfiles.local' is available).
> Any obvious problems?
>
> Best regards,
> Christian Schneider
>
> -- skript following --
>
> #!/bin/bash
> NAME=username
> DIR=/home
> REMOTE=username at host::home
>
> echo "*** delete files at remote side that were deleted locally (since
> last find) ***"
> #ATTENTION: this deletes even modified files on the remote side!
> rsync -rtzogpu --progress --exclude="syncedfiles.*"
> --include-from=syncedfiles.local --filter "- **" --delete
> --modify-window=1 --existing $DIR/$NAME $REMOTE
>
> echo
> echo "*** delete files at local side that were deleted remotely (since
> last find) ***"
> #ATTENTION: this deletes even modified files on the local side!
> rsync -rtzogpu --progress --exclude="syncedfiles.*"
> --include-from=syncedfiles.local --filter "- **" --delete
> --modify-window=1 --existing $REMOTE $DIR
>
> echo
> echo "*** copy new file to remote side ***"
> rsync -rtzogpu --progress --exclude="syncedfiles.*" --filter "+ **"
> --modify-window=1 $DIR/$NAME $REMOTE
>
> echo
> echo "*** copy new file from remote side ***"
> rsync -rtzogpu --progress --exclude="syncedfiles.*" --filter "+ **"
> --modify-window=1 $REMOTE $DIR
>
> cd $DIR
> find ./$NAME | sed -e 's/^.//' | grep -v syncedfiles > syncedfiles.local

I would add "--temp-dir=/tmp" to each of the rsync commands so that
you don't transfer partial files from another sync process.

Otherwise, I'd take a look at unison, which does real bidirectional syncs.

--
Aaron W Morris (decep) <aaronwmorris at gmail.com>


More information about the rsync mailing list