Bidirectional synchronisation of two folders on a Mac with Automator and Rsync

Keep two folders in sync

This is modification of my previous automator workflow for synchronising target folder with source folder (leaving source folder intact). This one, however, is bidirectional sync (mirror), the result of which is two folders with identical contents.

To achieve bidirectional sync, we'll be running rsync twice, once for each direction.
The rest of the workflow is pretty much the same as the one way sync.

First, we sync folder 1 with folder 2:

Notice that I've added option u (rsync -vau "$1/" "$2/") which leaves files that are newer in target folder. And I removed option --delete which would delete files/folders that are non-existent in target folder and that's not what we want.

After we've synced files and folders from folder 1 to folder 2 we'll run rsync again to sync folder 2 with folder 1:

And that's about it.

 

Comments

I've never really even attempted to take the time to learn Automator, but this tutorial made it simple to get a job done that Automator seemed the obvious choice for. Thanks for a clear tutorial!

Rich Platts 25. Apr 2011 at 5:33 PM

Thanks for the tutorial! This is definitely useful.

One question -- instead of re-getting the variables, can you add the second shell command after the first one? that is..

rsync -vau "$1/" "$2/"
rsync -vau "$2/" "$1/"

into one "Run Shell Script"?

Grace 4. May 2011 at 9:25 PM

Branko - thanks for the tutes, enormously helpful!

Grace - then you would not get the report after each stage of the sync. See how the TextEdit document is created after each stage to track changes? This will assist if you run the sync and then have a "where the f' has this gone??!" moment!

Franks. ;^)

Frankie 18. Oct 2011 at 12:06 PM Reply to: Grace

Thanks for this great info... I had not seen the ctrl+click option before.

I found through another site that they were recommending an update to Apple's rsync version because of bugs:
www bombich dot com/rsync.html
Do you think it is necessary for the backup? If you don't have that update, is it possible that a restore from backup would have issues with some files or applications?
thanks!

Dr Mintylow 14. Nov 2011 at 6:17 PM

This is indeed bidirectional synchronisation. How would you go about bidirectional mirroring ? For example, if you delete a file on the first folder, you'd expect it to be deleted on the second folder after a synchronisation. With your method, the deleted file will be created again on the first folder. Any ideas?

Daniel 21. Jan 2012 at 12:35 AM

Transmit by Panic software (panic.com) is an ftp program that can do mirror syncing.

Plilip 2. Feb 2012 at 7:19 PM Reply to: Daniel

Leave a comment

*
Leave your e-mail if you would like to get reply from me. Your e-mail will not be shown on my web page nor will I use it for anything other than replying to your question/comment.
**
Leave your website address if you want an extra link pointing to it ;)