Saturday, February 12, 2011

Dropbox and Junctions

If you haven't tried Dropbox, it's quite the nice little utility. It's 2GB of free online storage for whatever. Just sign up, download the app, and drop files in your Dropbox folder and they get synced so that you can access them from anywhere. There's even mobile apps so you can get at your files on your iPhone or Andriod device. Nice.

The main trouble people seem to have with it is that they don't want to store their files in their dropbox folder, so they have to copy their files from the original place and try to keep them synced.  Here's a little trick I've been using and it works great.  Windows Vista and above has a built-in feature called junctions.  Junctions, for those initiated in the Unix world, are essentially hard links.  Basically the concept is you have a folder for a few photos here: "C:\Users\MattMc3\My Photos\Vacation Pix 2011".  You'd like those to by synced via dropbox, which is located here: "C:\Users\MattMc3\Dropbox".  You can create a junction from your Dropbox folder into your Vacation Pix folder and when you delete from one, you'll delete from both.  When you change one, you'll change both.  When you add to one, you'll add to both.  The folders are the same... you don't have a copy, you have a mirror.

The magic is in a little DOS command called mklink.  On your Windows 7 or Vista computer with dropbox already installed, do the following:

  1. Start Menu -> type "cmd" to get to a command line
  2. Change your directory to your dropbox folder by typing cd "C:\Users\MattMc3\Dropbox"
  3. Type: mklink /J Vacation Pix "C:\Users\MattMc3\My Photos\Vacation Pix 2011"
  4. Watch in awe as Dropbox picks up your files and syncs them.  It doesn't matter which folder you drop a file, it'll sync both ways because this isn't a copy - it's a mirror. 
 Now, 2GB really isn't enough to store a lot of photos, but I have been running VisualSVN as my source code repository for awhile and I wanted to get it synced to Dropbox.  This is source code all the way back to Pascal code from High School, C++ from college, and personal projects from 10+ years of .NET.  I don't really need a 2-way mirror backup, I just wanted to keep C:\SVN as my repository location and still get backups.  Thanks to junctions, I can.