August 2, 2014

Keep Multiple Macs in Sync with Dropbox

I love my 27″ iMac, but it’s a little tough to take it on the road. So I like to keep my Documents folder in sync between it and my MacBook pro. I’ve recently switched to a new method that uses cloud storage service, Dropbox, and am thrilled with the result. Read on for my document synchronization formula!

You might also want to read How Google and Dropbox Revolutionized My Laptop Migration

The Challenge of Synchronization

Keeping multiple machines “in sync” has always been a challenge. Ever since struggling with LapLink way back in the 1990′s, I’ve been looking for a better way.

Once I moved to Mac OS X, with its UNIX underpinnings, I began using rsync to move data back and forth. But rsync needs to be pointed in the right direction: It’s great for making sure the latest version of “this” is “over there” but not much help when trying to determine which is newer.

Early last year, I switched to the excellent open-source application, Unison. Like rsync, Unison optimizes the movement of data between multiple machines. But it detects which data is newer on a file-by-file basis and prompts before acting.

But Unison only runs on demand and requires interaction and attention. I also didn’t feel comfortable exposing it to the Internet, so both computers had to be on the same LAN.

Introducing Dropbox

I never expected Dropbox to be part of my dream synchronization solution, but that’s what it’s become. Dropbox mirrors local data to the cloud, allowing files to be made available through a web browser or mobile app. It can share a folder between multiple computers, and even multiple users.

By default, Dropbox syncs a cache folder with the cloud, rather than data in other locations

But data in Dropbox “lives” in Dropbox. Drag a file into your Dropbox folder and it now “lives” in the Dropbox cache and cloud. If the cache exists on the same drive as the original location, the file will be moved; it it is on another disk, a copy will be made. Either way, the original location is no longer relevant: Only the copy in the Dropbox folder will be synchronized.

Symlink to Sync

But I didn’t want to live out of the cache folder. I wanted my data to remain in my Documents folder. It’s not obvious how to do this with Dropbox, but a few FAQs and tools exist to make it happen.

Put a symbolic link in the Dropbox cache folder and it will sync files from any location!

The Dropbox application will follow symbolic links in the cache to discover data to synchronize, and this is the secret. Simply create a symbolic link (“symlink” for short) to another folder and you can leave your data wherever you want to!

There are two essential tricks to make this happen:

  1. The folder symlinks in the Dropbox cache folder must have the same name
  2. Dropbox must be turned off on all but one computer when initially setting all this up

A great little app called MacDropAny even exists to facilitate this process, and it’s not too difficult if you follow these rules.

Step By Step Instructions

Make sure you follow these instructions to the letter. Failure to turn off Dropbox, for example, can result in data loss! Good thing Dropbox keeps old copies available for recovery!

These instructions assume you have two Apple Macintosh computers, named “Computer 1″ and “Computer 2″, and that the Dropbox client and MacDropAny application are installed on both. A similar method will presumably work with Windows computers, but that’s left as an exercise for the reader!

Note: You must start with exactly-identical folders on both computers. The easiest way to ensure this is illustrated below, but there are other methods (rsync, for example).

  1. In Finder on Computer 1, drag a folder from any location and drop it on the MacDropAny application in the Applications folder. For example, I dropped the folder, “~/Documents/Example”.
  2. MacDropAny will ask where to create the link. Select a location in your Dropbox cache. For example, I created a folder called “~/Dropbox/Documents” and selected that.
  3. MacDropAny will ask what to name this symlink. It is critical that this name be the same on both sides, and I suggest using the default name, that of the source folder. In my example, I called my symlink “Example” so the full path is “~/Dropbox/Documents/Example”.
  4. Dropbox will discover, index, and synchronize this folder on both computers. You must wait until this process is finished before proceeding to the next step!
  5. Did you wait until it’s finished? Really? Did you check both computers? Click the Dropbox icon on both, just to be sure it’s not still synchronizing.
  6. Quit Dropbox on Computer 2. This is very important. You can leave it running on Computer 1, but it must not be running when you perform the next step!
  7. On Computer 2, open the Dropbox cache folder. Note that the symlink will show up as a real folder full of files here. Drag-and-drop this folder to the desired location. In my example, I dragged the folder “Example” from “~/Dropbox/Documents” to “~/Documents”.
  8. Still on Computer 2, drag this new folder and drop it on MacDropAny.
  9. Select the same folder in the Dropbox cache and give it the same name. This is absolutely critical. In my example, the symlink went back in “~/Dropbox/Documents” and was called “~/Dropbox/Documents/Example”.
  10. Check to make sure both computers have identically-named symlinks in the exact same location in both Dropbox cache folders.
  11. If you’re really sure, start the Dropbox application on Computer 2 and let it discover, re-index, and sync the folder. The synchronization should be very quick since no data has to be moved.

That’s it! Now when you edit a file in “~/Documents/Example” on one computer, it will automatically and nearly-instantly show up on the other computer, as long as both are connected to the Internet. And if you do it offline, these changes will queue until you reconnect. You’ll also have access to these files online and through the mobile Dropbox app. Nice!

Caution!

This really isn’t difficult, but make sure you don’t take any shortcuts. Dropbox will automatically delete the whole folder if you forget to turn it off while creating the symlink on the second computer, and it will delete any missing files if you try to use an incomplete copy. Monitor the “Events” tab in your Dropbox web page to make sure you didn’t lose any data, and restore any accidentally-deleted files from there as well.

This makes it well-suited for keeping multiple “Documents” folders in sync, but isn’t always desirable. Some applications (notably iPhoto) don’t want to sync individual files, they want an entire bundle of files to be consistent. So this isn’t a perfect Mac-syncing solution. It does work for individual files usually found in the Documents folder, but be cautious. Don’t open the same file on two machines simultaneously, for one thing.

  • http://twitter.com/pistapoci Umberto Gatti

    As a (former) Dropbox user I’d like to recommend SugarSync as an alternative way to backup and sync your data in the cloud. Free accounts provide 5GB of disk space and you can choose which folders to sync in your hard drive, not only one single dropbox.
    If anyone wants to register for an account, feel free to use my referral link that will add 500 MB further bonus to both mine and your account :)
    https://www.sugarsync.com/referral?rf=do5qm2rpjareh
    Thanks!

  • http://blog.fosketts.net sfoskett

    Some of my friends use SugarSync and tell me it’s great. I’ll have to give it a try!

  • Moneillmichelle2

    Thanks for the instructions but I’m stuck. I’ve got everything up to step 7.
    But on computer 2 (my laptop) I can’t find the  cache file. Any suggestions?
    I’ve used finder to locate the file and nothing is found?
    is the cache file called “dropbox.db”?
    Any help would be appreciated.
    Regards.
    MO

  • http://twitter.com/stevesunderland stevesunderland

    if I set up symlinks on “Computer 1″ only and then clone it,  will the clone sync automatically?

  • Soopmail

    Excellent. Just what I needed. Thanks for the tip.

  • Michael

    I am really confused by step 7. you say to “On Computer 2, open the Dropbox cache folder” but then say nothing else about that folder, why do you need to open this folder?

  • http://www.styleshoots.com/ Matt Brasier

    help! I am missing some files now and I want to switch off the syncing so I can get back in order.. Please help!!

  • Pingback: How I sync, backup and use the Cloud between my computers (and mobile devices) « Luis Gustavo Martins’s Blog

  • http://twitter.com/Tehninjah_ Tehninjah

    So as to modify the symlink without Dropbox synchronizing it back, or something like that.

  • SteveCodes

    This tutorial is a bit difficult to follow. It’s not hard to do. 1) computer1: drag a folder to macdropany, accept the default name. 2) let it sync. 3) go to computer2, drag the synced folder somewhere on your hd. 4) shut down dropbox. 5) delete the folder in the dropbox folder location on computer2. 6) drag the folder you copied in step 3 on to macdropany. 7) accept the default names (should be identical to what you did in step 1 except you are on computer2. 8) start dropbox and let it sync. 9) test by accessing the folder outside of the dropbox instance of it, that is, wherever you dragged the folder to in step 3. Check it on computer1 in the folder outside the dropbox location. If this helped show your gratitude: http://db.tt/AVFmY23

  • http://www.facebook.com/TheoryX Mitja Predikaka

    Is it possible to do something like this to synchronize Mac and PC?

    So that i would sync my “Documents” folder on Mac with the same folder placed somewhere on PC (just not in dropbox folder)