Merge Folders Together on Mac OS

My computer drive crashed recently.  To restore I downloaded the archives from Mozy, my offsite backup provider.  To make downloading easier, they break the restore into a series of 1.7 GB restore files (disk images).  On each disk image are a subset of my backed up files.

However, what I want is to reassemble my computer as it was prior to the crash.  This requires mounting each disk image, and copying the contents onto my hard disk.  What’s difficult is that by default, Mac OS does a replace not a merge copy.

To alleviate this problem, I use the command line tool ditto.  Ditto will do a merge copy.  It’s usage is easy:

ditto /Volumes/584205.3.dmg/ /RESTORED/

Any directory in /RESTORED/ that already exists and is also in /Volumes/584205.3.dmg will get the new files merged in!

I encountered a problem using ditto if the target directory already existed, but it’s ownership or permissions didn’t allow me access. You’ll see a message like this:

ditto: /RESTORED/Users/arahn/andy/drawings/.BC.5syGcu: Permission denied

Use ls to diagnose the problem:

Lab-Computer-152:Downloads labuser$ ls -la /RESTORED/Users/arahn/andy/drawings total 11088
dr-xr-xr-x@ 9 labuser staff 306 Sep 11 17:59 .

See the “dr-x”? The lack of a “w” as the third character in that cryptic word means “writing” is diabled. Fix this with chmod:

chmod +w /RESTORED/Users/arahn/andy/drawings

To fix all of them at once, I used find to recursively apply the fix:

find /RESTORED -type d -exec chmod +w {} ';'

(Aside: Mac OS has several ways to “lock” a file. chmod is one way. The file could also be “owned” by a different user: To fix this, use “chown” (you might have to be super user — in this case do “sudo chown”). The file might also be locked via a mac-only “hfs attribute”. Fix this with “chflags -nouchg”.) Most of these can also be changed via the Finder’s “get info” window on a directory under the “Sharing & Permissions” section.)

Leave a Reply