geek stuff - synchronize two folders on a mac with automator and rsync - branko jevtić's piece...

16
9/12/14 12:23 AM Geek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web Page 1 of 16 http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/ Home Home About Me & Contact About Me & Contact Geek Stuff Geek Stuff Everything Else Everything Else Web Web Photo Photo Graphic Graphic Search I really miss some good Automator tutorials online. It's such a great and I guess underrated and underused tool. Here I'll show you how to combine it with rsync to easily synchronise two folders. Share: Downloads Finished workflow, ready to use (for OS X Mountain Lion) zip | 308 kb Make a backup before you try it out on your files! I suggest you make some dummy folders and fill them with some random files to test it out first. You'll start by opening automator.app, you can find it in your Application folder it has a nice icon which reminds me of eve from Wall-E. Once you start it, it will ask you what kind of workflow you're going to make, we'll choose Workflow: Geek Stuff Blog Automator Mac Terminal Unix Synchronize two folders on a Mac with Automator and Rsync Power of Automator and Unix combined You can find the finished workflow (for Mountain Lion) from the tutoria on the right so you can use it right away and see how it's done for yourself. And here it is for the patient ones, step by step... Jump to comments 65 14 December 2009

Upload: azmi-plg

Post on 18-Jan-2016

416 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Geek Stuff - Synchronize Two Folders on a Mac With Automator and Rsync - Branko Jevtić's Piece of Web

9/12/14 12:23 AMGeek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web

Page 1 of 16http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/

bananica.com | Branko Jevtić's piece ofweb

HomeHome

About Me & ContactAbout Me & Contact

Geek StuffGeek Stuff

Everything ElseEverything Else

WebWeb

PhotoPhoto

GraphicGraphic Search

I really miss some good Automator tutorials online. It's such agreat and I guess underrated and underused tool. Here I'll showyou how to combine it with rsync to easily synchronise twofolders.

Share:

Downloads Finished workflow, ready to use (for OS XMountain Lion)zip | 308 kb

Make a backup before you try it out on your files!I suggest you make some dummy folders and fill them with some randomfiles to test it out first.

You'll start by opening automator.app, you can find it in your Application folder it hasa nice icon which reminds me of eve from Wall-E. Once you start it, it will ask youwhat kind of workflow you're going to make, we'll choose Workflow:

Geek Stuff Blog Automator Mac Terminal Unix

Synchronize two folders on a Mac with Automator andRsyncPower of Automator and Unix combined

You can find the finished workflow (for Mountain Lion) from the tutoria on the right soyou can use it right away and see how it's done for yourself.

And here it is for the patient ones, step by step...

Jump to comments 65

14December2009

Page 2: Geek Stuff - Synchronize Two Folders on a Mac With Automator and Rsync - Branko Jevtić's Piece of Web

9/12/14 12:23 AMGeek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web

Page 2 of 16http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/

First action we're going to add is "Ask for Finder Items" (it's inside Files & Folderscategory, but best way to find actions is to use search), that action simply opensfinder window where you can choose file(s) or folder(s).

And here we can write some custom text in "Prompt" field, you can specify whichfolder will it open as a starting point (Start at), and we'll specify that we want onlyfolders and we do not want multiple selection option.

Next we'll add "Set Value of Variable" action which will get the folder that you choseand write it's name into a variable that we'll use later with Rsync.

Next, we'll repeat it, we need another pair of Ask for Finder Items and Set Value ofVariable actions. First we add Ask for Finder Items:

The important thing here, is to ctrl + click (right click) on the Ask for Finder Items textand choose "Ignore Input" option, if you do not do this the whole thing will not work.

Page 3: Geek Stuff - Synchronize Two Folders on a Mac With Automator and Rsync - Branko Jevtić's Piece of Web

9/12/14 12:23 AMGeek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web

Page 3 of 16http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/

Then we'll add Set Value of Variable

And we'll click on Variable drop down and choose New variable and name it forexample "target_folder".

Next step is optional, we'll add confirmation window (Ask for Confirmation action)that will ask us if we chose the right folders and print out the names of the folderswe're going to sync:

Here you start writing something like "You'll be syncing from" than you drag thevariable "source_folder" from variable list below, continue by writing " to " and thandrag "target_folder" variable from the list, and finish your confirmation text, forexample " is that right?".Here you're also have to say to automator that you want to ignore input from previousaction.

Next we'll add two Get Value of Variable actions that will pick up the values of sourceand target variables:Again, ignore the input from the Ask for Confirmation action.

Because of the "--delete" option rsync will delete any files it finds in thetarget folder that are not found in the source folder! Omit this option ifyou want just to add missing (and newer) files from the source folder.

After that, add Run Shell Script action which will tell rsync what to do:

You have to change "Pass input" to "as arguments" and thanwrite rsync -va --delete "$1/" "$2/" $1 represents first variable that you'resending in, and $2 second one (first one being source_folder and second onetarget_folder). You can play with rsync options here and maybe exclude some filesfrom syncing. You can omit --delete option if you don't want rsync to delete filesfrom the target folder that don't exist in the source folder.

And here is another optional action, we'll add New TextEdit Document at the end.

Page 4: Geek Stuff - Synchronize Two Folders on a Mac With Automator and Rsync - Branko Jevtić's Piece of Web

9/12/14 12:23 AMGeek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web

Page 4 of 16http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/

That will open new TextEdit window with output from Rsync, so you can see whatRsync actually did.

Share:

Comments

What a nice Workflow. Same people with brainsgotten figure this out, well done.reply

Madmurdog17. Mar 2010 at 10:17 AM

Marvelous !I was searching such tutorial a long time ago,thanks so much :-)

reply

Crocodil22. Apr 2010 at 8:28 PM

This works great! I was wondering if there is a wayto set it up so that once you choose to run the scriptfrom the menu bar, it does not ask you to choosefolders at all.

reply

Janis1. Oct 2010 at 5:40 AM

Sure, if you want to have it with predefined foldersyou delete everything from automator workflowexcept "Run Shell Script" and "New TextEditDocument" (if you want to see the output). And in"Run Shell Script" enter something like this: rsync -va --delete "/path/to/folder1/""/path/to/folder2/"

bananica13. Oct 2010 at 12:11 AM

Reply to: Janis

Leave a comment

Your name:(required)

Your e-mail:*

Your web site:**

Your comment:(required)

Post it

* Leave your e-mail if you would like to getreply from me. Your e-mail will not beshown on my web page nor will I use it foranything other than replying to yourquestion/comment.

** Leave your website address if you wantan extra link pointing to it ;)

And that's it! Now we're going to save it, the best way I think is to save the workflowinto your Scripts folder (you go to your home folder and there you'll find Scriptsfolder). I named mine workflow "RsyncTutorial". Then if you have Script Menu turnedon in menu bar (If you don't you can enable it by running AppleScript Utility, locatedat /Applications/AppleScript/, and checking the "Show Script Menu in menu bar"checkbox) you'll see something like this when you click on the Script Menu:

And if you click on it your workflow will start by asking you for folder to sync from.

Back to: Geek Stuff Previous post Next post

Enter this number:

(required)

Page 5: Geek Stuff - Synchronize Two Folders on a Mac With Automator and Rsync - Branko Jevtić's Piece of Web

9/12/14 12:23 AMGeek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web

Page 5 of 16http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/

Great tutorial, thanks!

reply

David3. Oct 2010 at 3:05 PM

I too have been looking for some time for an easysolution for this. So thank you! However, I keepgenerating a shell script error. I started with exactlywhat was cited, leaving the values "$1/" and $2/"then tried replacing the text within the quotes to"Source_Folder" and "Target_Folder" respectively.Still an error. What am i doing wrong? Thank you!

reply

Eric22. Oct 2010 at 7:35 PM

Hi Eric. I'm not sure I understand it right. Youshould leave "$1/" and "$2/" in the run shell scriptwindow. It basically should look just as it is on thescreenshot above. Folder names (paths) are passedas arguments to shell script ($1 is first argument wepass to it and $2 is second one) so these names weuse in automator itself are irrelevant to bash script.

bananica22. Oct 2010 at 7:48 PM

Reply to: Eric

Hvala puno puno puno i pozdrav iz Pule!

reply

Igor Diminić7. Nov 2010 at 10:07 PM

Really nice tutorial, thank you very much

reply

Dalen19. Mar 2011 at 11:56 AM

Hi, like Eric I keep getting a shell script error. Thefolder copies, but the contents do not. Help needed!reply

Nivesh Galaiya19. Mar 2011 at 2:30 PM

Hi, Nivesh, could you send me your automatorworkflow? If you send me your e-mail over thecontact form I have onhttp://www.bananica.com/Contact/ I'll reply withmine, so you can send me the files and I'll take alook.

bananica20. Mar 2011 at 12:47 AMReply to: Nivesh Galaiya

Hi there,your idea of using automator is great!Do you know if is possible to do a bydirectionalsyncronization? meaning a mirror sync where themost recent file version (no metter where is stored ifin target or destination) is copyed to the otherfolder.....That's what I'm looking for....

thanks

Luca

reply

luca22. Mar 2011 at 6:33 PM

Page 6: Geek Stuff - Synchronize Two Folders on a Mac With Automator and Rsync - Branko Jevtić's Piece of Web

9/12/14 12:23 AMGeek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web

Page 6 of 16http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/

Hi Luca. Yes it's possible. You can read more aboutit here

bananica28. Mar 2011 at 11:24 AM

Reply to: luca

Really awesome. Thanks for posting. Just a quickquestion though. With this script, the original"Source" will not be altered so only the "Target" willbe altered?

reply

Iqbal27. Mar 2011 at 4:23 AM

Yes, that's right. Source folder is left intact.bananica

28. Mar 2011 at 10:23 AMReply to: Iqbal

Also my thanks, this will help me a lot.

reply

LastofAdozen23. May 2011 at 2:17 PM

Actually, my second "ask for finder items" alwaysget TWO items. the first one again, and the secondone. Even if I drag your first three commands into anew window, this happens, whereas it does NOThappen in your script. some hidden details?

reply

lastofAdozen24. May 2011 at 5:07 PM

oops read read directions ... the bit about ignoreinput ...reply

lastofadozen24. May 2011 at 5:11 PM

last comment. It might improve the tutorial if yousay what the "ignore input" does even graphically.E.g. breaking the link between the above panel andthe panel one is editing. Thanks again.

reply

lastofthree24. May 2011 at 5:30 PM

Awesome tutorial. Love the layout for your blog :Dwas super easy to follow and make sense ofautomator!

reply

Aaron25. Jun 2011 at 8:12 PM

Thank you Aaron! Glad you liked it, and the layoutas well, some find it weird with right/leftalignments :)

bananica27. Jun 2011 at 12:07 PM

Reply to: Aaron

Very clear tutorial. Thanks.Is it possible to use this or something similar to do abidirectional sync between two Macs over annetwork?

reply

Karl8. Aug 2011 at 7:35 PM

Thanks! Now I don't have to buy special software toNiklas

Page 7: Geek Stuff - Synchronize Two Folders on a Mac With Automator and Rsync - Branko Jevtić's Piece of Web

9/12/14 12:23 AMGeek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web

Page 7 of 16http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/

do my backups. :-)

Is there an easy way to schedule running of theworkflow in OS X Lion?

reply

20. Sep 2011 at 10:58 AM

All my files and folders from source_code got lost. Ican't find them anywhere, they didn't copy todestination_folder and they were deleted. Is thereany way to recover that? Please help, im desperate.

reply

Conrad14. Oct 2011 at 4:19 PM

Thanks - just what i needed. copies my scannedphotos to an external disk once run.This may be a bit confusing though on step no 8. Ithink should be on step number 7. 'Again, ignore theinput from the Ask for Confirmation action.'

reply

ade15. Oct 2011 at 5:34 PM

You were right! I changed it. Thanks!bananica

9. Nov 2011 at 8:39 AMReply to: ade

Great tutorial, thanks! I am looking for a way to dothis over a network between my laptop and myMacPro. I saw your tut on bidirectionalsynchronization on one machine, but is this possiblebetween two machines? I've got about 8GB of filesthat I need to keep synced.

Thank you!

reply

Jason A.1. Nov 2011 at 4:02 PM

Jason A.

it is possible but this workflow won't support itwithout some editing. Quite frankly I haven'tfigured it out yet but for that I just manually do it interminal or iTerm with the I.P. addy of the 2computers.

Grant9. Nov 2011 at 7:45 AM

Reply to: Jason A.

Hi Jason!I am myself syncing some folders on my laptop anddesktop macs. I'm using rsync over ssh to do it. I'mgonna try to write a tutorial how to do it. Theremight be some other ways to do it, but this oneworks for me.

bananica9. Nov 2011 at 8:06 AM

Reply to: Jason A.

This tutorial is great, I h ave been looking forsomething like this.

However I have a question. Once the folder sync isset up, will it automatically then sync everythingbetween the folders in the future. Without having tomanually run it every time?

reply

CJ25. Dec 2011 at 4:29 PM

Page 8: Geek Stuff - Synchronize Two Folders on a Mac With Automator and Rsync - Branko Jevtić's Piece of Web

9/12/14 12:23 AMGeek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web

Page 8 of 16http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/

Thanks!

Hi there, this is an amazing idea, and was actuallythe first time I have ever used Automator; so go youfor educating me there.

I was wondering if there was a way of making thisscript run permanently, so it updates the targetfrom the source automatically?

i.e. I drop a file into 'documents' on my systemdrive, and it automatically backs up on my backupdrive.

reply

Ken5. Jan 2012 at 3:36 PM

Thank you so much for this tutorial.

I tried the modified version of your instructionsfound on practically efficient dot com.

I have not used the terminal nor the Automatorbefore, so I apologize in advance for my total lack ofknowledge.

When I type this command in Terminal:

rsync -aE --delete ~/Desktop/testerfolder/"/Volumes/My Passport/"

I am getting the error:

rsync: opendir “/Volumes/My Passport/.Trashes”failed: Permission denied (13)rsync error: some files could not be transferred(code 23) at /SourceCache/rsync/rsync-42/rsync/main.c(992) [sender=2.6.9]

The files actually did copy though.

When I type this command in Terminal:

rsync -va --delete "~/Desktop/testfolder/""Volumes/My Passport"

I get these error messages:

building file list ... rsync: link_stat"/Users/Jan/~/Desktop/testfolder/." failed: Nosuch file or directory (2)donersync: push_dir#3 "/Users/Jan/Volumes" failed:No such file or directory (2)rsync error: errors selecting input/output files, dirs(code 3) at /SourceCache/rsync/rsync-42/rsync/main.c(580) [receiver=2.6.9]rsync: connection unexpectedly closed (8 bytesreceived so far) [sender]rsync error: error in rsync protocol data stream(code 12) at /SourceCache/rsync/rsync-

reply

Jan11. Jan 2012 at 6:08 AM

Page 9: Geek Stuff - Synchronize Two Folders on a Mac With Automator and Rsync - Branko Jevtić's Piece of Web

9/12/14 12:23 AMGeek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web

Page 9 of 16http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/

42/rsync/io.c(452) [sender=2.6.9]

And no files are copied.

When I wrote and saved this in a RunShellScript inAutomator:

rsync -va --delete "~/Desktop/testfolder/""Volumes/My Passport/"

it didn’t work. I tried with both -va and -aE andwith and without quotes around the source folder.

I got this message:

The action “Run Shell Script” encountered an error.Check the action’s properties and try running theworkflow again.

Thanks again, so much.

I hope it isn't a bother to help me sort this out.

Hi Jan!

The problem with this one:rsync -aE --delete ~/Desktop/testerfolder/"/Volumes/My Passport/"

Is that you're syncing to root of your attached disk,and there are always some hidden folders in roots ofhard disks (one is .Trashes for deleted files) andthese are usually locked. And rsync is trying todelete .Trashes because there's no such folder inyour testerfolder/ folder.So I would suggest that you make a folder on youMy Passport disk and then run it, for example:rsync -aE --delete ~/Desktop/testerfolder/"/Volumes/My Passport/test_target/"

Here:rsync -va --delete "~/Desktop/testfolder/""Volumes/My Passport"

you're missing "/" before Volumes, when you put itlike this without "/" you're telling it to search for afolder Volumes in the folder you're currently in, so ifyou're in your home folder ("/Users/Jan/") it willlook for /Users/Jan/Volumes/My Passport/ andthere's probably no such folder.And there's another problem. "~" is a shortcut forhome folder, so instead of writing /Users/Jan/ youput just ~, but, if you use that shortcut than youcan't put the whole path under quotes.

So the simple solution would be to create somefolder on your My Passport disk and than sync it tothat. Like I wrote above:rsync -aE --delete ~/Desktop/testerfolder/"/Volumes/My Passport/test_target/"

Btw. you need quotes around My Passport path

bananica11. Jan 2012 at 8:51 AM

Reply to: Jan

Page 10: Geek Stuff - Synchronize Two Folders on a Mac With Automator and Rsync - Branko Jevtić's Piece of Web

9/12/14 12:23 AMGeek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web

Page 10 of 16http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/

because you have space in the volume name (MyPassport), you could do without quotes, but thanyou have to escape space character like this:/Volumes/My\ Passport/test_target/

Does not work here (Mac OS 10.6.5, MacBook Pro):Shell script seems to run in an endless loop. Running the corresponding rsync script from theshell works flawlessly though. May I send you my automator workflow forexamination?

reply

tomasio16. Jan 2012 at 2:03 PM

Does this also subfolders? if i have a subfolder withfiles in the source_folder, does it sync that to thetarget_folder?

reply

Polo25. Jan 2012 at 6:52 PM

Great workflow. I have been using this for sometime now and find it really useful. I would like toknow if it is possible to add a if/then/else commandto the apple script? I want to be prompted if i wouldlike to run a dry run first. Something like:

set question to display dialog "Would you like to runa Dry Run?" buttons {"Yes", "No"} default button 1set answer to button returned of question

if answer is equal to "Yes" thenrsync -vaun --exclude=".*" --exclude=".*/" "$1/""$2/"end if

if answer is equal to "No" thenrsync -vau --exclude=".*" --exclude=".*/" "$1/""$2/"end if

I know i could just create a separate workflow fordry run mode... but that would be too easy!

Thanks

reply

Adrian Cartlidge21. Feb 2012 at 6:34 PM

Thanks for the clear tutorial! I've never usedautomator before and followed perfectly ( I think).Two questions, though:I'm trying to sync about 1 tb of data from oneexternal drive to another. When I do this, my MacHD begins to fill up with data. Does all of the datatemporarily visit my HD, or did I do somethingwrong?Second question is, do you know of an action todisplay a progress bar to estimate the time to runthis script?Thank you so much for your help!

reply

Matthew Richie2. Mar 2012 at 1:16 AM

Page 11: Geek Stuff - Synchronize Two Folders on a Mac With Automator and Rsync - Branko Jevtić's Piece of Web

9/12/14 12:23 AMGeek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web

Page 11 of 16http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/

Thanks. Great info and tutorial.

reply

Marcelo29. Mar 2012 at 6:58 PM

If I change $1 and $2 to valid paths, can I add it tothe Source folder as a Folder Action so it runswhenever a new file is added or existing filechanged?Do I save the workflow as an app or a script orwhat?Thanks.

reply

Simon30. Apr 2012 at 12:42 AM

great tutorial!thanks guy now i've a questionthis task run once the syncing. is it possible to createa script that constantly monitors a folder and real-time replication to target folder?

thanks anywaY!regards

Simon

reply

Simon B13. May 2012 at 11:19 AM

This is really wonderful stuff, automator isunderrated indeed. Almost love how well this oneworks – i am missing a progress/status whileupdating/rsyncing two folders though… any chancefor that?

reply

Steffen15. May 2012 at 11:46 PM

Combined with the bidirectional approach from theother post and something like 'lsyncd'… hm : )reply

Steffen16. May 2012 at 3:22 PM

What I needed seemed so simple -- a way tosynchronize a folder on my office MAC with a folderon a portable device so I could share them with myhome MAC. I did NOT want to have to re-copy theentire folder everyday (it is 4 gigs!) and I did notwant to have to keep track of which files I modifiedeveryday. Information on the internet pointed to3rd party software - some free and others with afee. REALLY? Those were my options? A potentialfor malware/spyware or monthly charges? After afew hours, I came upon this tutorial. I took the timeto follow the instructions, which, at first, seemedvery complicated and intimidating. But each stepwas explained. I had to take a leap of faith when itcame to interpreting "Here you're also have to sayto automator that you want to ignore input fromprevious action." I wasn't sure if I'd missed a step,but it turned out to be the same step as 4. It tookabout 20 minutes to build it in Automator - aprogram I've never used before. I ran it. ITWORKED! It deleted what I deleted. It created what

reply

David Vaccaro19. Jun 2012 at 7:21 PM

Page 12: Geek Stuff - Synchronize Two Folders on a Mac With Automator and Rsync - Branko Jevtić's Piece of Web

9/12/14 12:23 AMGeek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web

Page 12 of 16http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/

I created. The folders where in sync. I recommendthis procedure to anyone trying to synchronize twofolders on a Macintosh. Thank you bananica!

I think it's important to note that this is a one waysync. At least that's how it works for me. Still handythough and with another workflow to sync in theother direction it's very useful.

reply

Brian Gerry10. Sep 2012 at 8:14 AM

Thnaks for this great tutorial

I do have 2 questions :

Q1Is there a way to select a sub folder coming from anapp (Open Package Contents) ; it would be usefull tobackup a huge MMO folder under Wine forexample).

I tried the shell method but i got an error : rsync -va--delete "/Applications/Games (video)/UruLive.app/Contents/Resources/drive_c/Uru Live/""/Volumes/d2 Quadra/MMO Backup/Uru Live/

Q2I used to use arRsync, but since I upgrade to Lion itcrash whenever i tried to backup those huge folderplenty of files.Your Automator Script either.It work well on some medium size folder sync.

Are ther some usage limit with Rsync ?

Thanks

reply

Varum16. Oct 2012 at 6:36 PM

Q1 : R1Work well with the command line method ; You justneed to be very, very careful when typing the path.Especially behavior differ if you use a / at the end ofthe source and destination path .../ mean "the content"Without / mean the folder and its content.If you omit / for dest, it seems that Rsync try tocreate a subfolder and crash if it exist...Sorry for posting in hurry

Q2 : I don't find any answer. It crash ALL the macwith LOTRO folder (20G0 / 10 000 files). All otherMMO are Ok ....

reply

Varum16. Oct 2012 at 7:46 PM

Well, I really really wish I hadn't done this. I haveno idea what happened but the script didn't work,and it ended up deleting everything.

I set it to copy out of my main work folder and thewhole thing has disappeared, it's not in my trash

reply

Kim20. Nov 2012 at 11:35 PM

Page 13: Geek Stuff - Synchronize Two Folders on a Mac With Automator and Rsync - Branko Jevtić's Piece of Web

9/12/14 12:23 AMGeek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web

Page 13 of 16http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/

either. Seeing as I was trying to make this commandwork in order to back up in in the first place I don'thave any back ups except an old one from severalweeks back. I've just lost a whole load of work andI'm slightly in shock right now.

Do you know how I might be able to reverse thiscommand. Also I can't see any of the files in myrecycle bin.

I'm actually quite upset. I followed all the stepsperfectly and then downloaded your script to test.

To anyone else, please please back up before you trythis.

Apologies for my slightly dramatic post yesterday. Ihave re-analysed the Automator workflow I madeand can only assume that I got the two foldersmixed up. As the rsync command effectively makes amirror of the source folder in the destination folder,selecting an empty folder as the source will leaveyou with an empty destination folder, regardless ofwhat was in it.

I've tried it again with some assitance from Brankoand it's working great, so don't be put off using thisscript, just be careful because it's potentially quitedangerous if used incorrectly, as I found out thehard way :(

Kim21. Nov 2012 at 10:40 PM

Reply to: Kim

Great tutorial, thanks for sharing!

reply

Rene26. Nov 2012 at 10:30 AM

Ran into it – adopted logic and bingo: works great !

Thanks for sharing. This is a lifetime saver!reply

Mick11. Dec 2012 at 1:54 PM

This is a great tutorial!

I have some questions:

1. Is it possible to set default value for "Set Value ofVariable" action in the workflow without showing adialog when running it as an application?

2. Is it possible to show the progress of rsync outputwhile it is running without waiting until it finishesand output to the textedit?

3. When there are files with Chinese names involvedin the sync, the output in textedit shows, forexample, \#346\#262... for Chinese characters. Doyou have any idea to fix it?

Thanks a lot.

reply

Jason26. Feb 2013 at 5:30 PM

Page 14: Geek Stuff - Synchronize Two Folders on a Mac With Automator and Rsync - Branko Jevtić's Piece of Web

9/12/14 12:23 AMGeek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web

Page 14 of 16http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/

Here i find a usefull comment about extendedattributes from extra88:

Yes, the version of rsync that comes with all versionsof OS X is rather outdated. However, if you're goingto use that version, you really should add anotherswitch, -E. This tells rsync to include "extendedattributes," various file properties, not just resourceforks, that can be found on OS X files that aren'tgenerally found on other Unix-based operatingsystems.

Note single-dash parameters do not have to bewritten separately 'rsync -a -v -E' and 'rsync -avE'do the exact same thing.

The easiest way to get a newer version of rsync onyour Mac is to install Carbon Copy Cloner. Burieddeep within the application is/Applications/Carbon\ Copy\Cloner.app/Contents/MacOS/ccc_helper.app/Contents/MacOS/rsync

Within the current version of Carbon Copy Cloner(3.5.1) is rsync version 3.0.6. With this (and I thinkall versions of rsync that don't come from Apple),the -X parameter is what tells it to include extendedattributes, so '/Applications/Carbon\ Copy\Cloner.app/Contents/MacOS/ccc_helper.app/Contents/MacOS/rsync-avX --delete /path/to/source//path/to/destination/'. You might also add the -Aswitch to preserve ACLs (non-Unix file permissions)but if you just making a folder to folder backupwithin an account on your computer, preservingACLs probably isn't important.

reply

hopeless27. Feb 2013 at 10:16 AM

Great tutorial! Thank you! It worked perfectly forme!reply

Brett13. Jul 2013 at 1:27 AM

Amazing.

Is there a way for doing this but on two differentcomputers?

If i edit my personal directory on my MacBook Pro,i want those changes to be there when i turn myiMac at home.

Is this possible?

reply

David7. Sep 2013 at 10:20 PM

Hi- This tutorial is amazing... except I used anothertrick and a symlink to put my Dropbox onto one ofmy external drives. Now, when I run this script,trying to sync a folder in that Dropbox with a folderon another external drive, it hangs up on the'syncing' bit and nothing seems to happen... any

reply

Jason11. Sep 2013 at 12:37 AM

Page 15: Geek Stuff - Synchronize Two Folders on a Mac With Automator and Rsync - Branko Jevtić's Piece of Web

9/12/14 12:23 AMGeek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web

Page 15 of 16http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/

thoughts??

help!

I made a test folder with only 3 items in it andfollowed your steps carefully including the --deletecommand. Then I ran the workflow but it starteddeleting everything from my external drive thatcontained the target folder instead of only the folderitself. I managed to get it back from my other drivesbut what happened here? Any ideas?

reply

Graham11. Nov 2013 at 6:07 PM

This is great. Having a progress bar would make itexcellent ;)reply

jay29. Nov 2013 at 3:36 PM

This still does not work. Even if I copy/paste yourshell script mine is in an endless loop :(

Do the quotes in the shell script really have to betyped with quotation marks like "$1/" or should it be$1 instead?

reply

tomasio19. Dec 2013 at 3:42 AM

Hey there! So, this works great out of the box forwhat it does, but I'm curious (and have seen acouple of other commenters ask this as well) aboutsetting this up to automatically sync?

I have a networked drive and I'd love toautomatically sync to that drive ala Dropboxwhenever I add/remove files from my source folder.So, if I add a new movie to my folder, the syncingprocess will automatically run and send my new fileto the external drive. The same would be true fordeleting files.

Any thoughts?

reply

Corey14. Feb 2014 at 2:00 AM

So this is working great, except for it'scopying(creating?) a .ovf file for everything it syncsto the other folder... not completely sure what an.ovf file is or how to make it stop making them! anyinsight into this matter would be greatlyappreciated :)

reply

Robotech4. Apr 2014 at 2:00 AM

Is there a way to show progress?

reply

David11. May 2014 at 2:02 AM

Why did it enlarge both folders? The folder I wantedto mirror was 49GB and the other folder was 45 GB.reply

MoJoe11. May 2014 at 6:39 PM

Page 16: Geek Stuff - Synchronize Two Folders on a Mac With Automator and Rsync - Branko Jevtić's Piece of Web

9/12/14 12:23 AMGeek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevtić's Piece Of Web

Page 16 of 16http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/

Now both folders are 54 GB.

Great workflow!I was wondering if there is a way to not copy theicon of the source folder and delete the icon of thetarget folder. Can anyone answer?

reply

Matteo2. Jul 2014 at 11:04 AM

What you want to do is exclude "Icon" file which isthe folder icon. You can do that by adding excludeoption: " --exclude='Icon'"

Branko4. Jul 2014 at 3:19 PM

Reply to: Matteo

@Brank0 | I've written this script rsync -vaE "$1/""$2/" and adding the exclude option it still copiesthe icon. Instead, if i don't put the -E it deletes theicon of the target folder and create an empty filenamed "Icon".

reply

Matteo4. Jul 2014 at 7:24 PM

powered by: supporting: