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

Transmit will sync only through the net (ftp or elsewise) I don't know why it won't sync locally.

Paul 7. Jun 2012 at 3:12 AM Reply to: Daniel

Thanks for the tutorial.
I am manually testing the -vau options and it is ok for sync file changes between two dirs.
But when I delete a file from one, it is ignored in one direction and restored in the direction to the dir where it was firstly deleted.
Is there a way to (safely) two-way sync deletion of a file the same way are two-ways synched modifications?

Tommaso 10. Apr 2012 at 5:26 PM

Tommaso: have a look at man entry for rsync. Type in terminal.app: man rsync
You might as well find the solution that fits your needs.

Vale 19. Apr 2012 at 9:14 AM

Vale, precious answer, already scanned man up and down..
Maybe you were implying the --delete option which is not exactly what I'm searching for (I tested it in different scenarios and it doesn't fit). Maybe rsync is just not the appropriate command. For your info I'm testing unison command now, seems better for my purpuse. Checking unison man right now.......

Tommaso 20. Apr 2012 at 5:07 PM Reply to: Vale

I just wanted to thank you for taking the time to create and post these easy to follow instructions on using Mac Automator for syncing !
I am a photographer and I shoot hundreds to thousands of photos in a week and always had to manually check which drives had which folders copied to them. Now I can just sync the top level photo folders and be done with it.
I have made several scripts based on this for my different needs (delete or not, bi-directional or not etc.) and have a flexible, free and simple way for me to keep accurate backups of all my photo files on multiple external drives. Saves me time and money and keeps my photos safer too.

Gen 16. May 2012 at 10:47 AM

It's the strangest thing. The screenshot images on this page are all black and scribbles when viewed on an iPad.

Robert 14. Aug 2012 at 7:43 AM

Thanks for letting me know! For some reason images got corrupted, it should be ok now.

bananica 14. Aug 2012 at 9:48 AM Reply to: Robert

Many thanks for this. It's been very helpful. I'm a student, and like to keep all of my files synced between by macbook and iMac. One question for you - I use Skim as a PDF viewer because I like the style of note-taking capabilities. Unfortunately, when I modify one PDF, the changes don't get transferred when I sync. Do you know of a way instruct automator to check for changes in the document while syncing? Thanks again!

Ryan 8. Oct 2012 at 2:43 AM

Is it possible to have a progress bar?

Gona 28. Oct 2013 at 9:12 PM

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.