Thursday, May 27, 2010

Poor man's remote backup via LogMein Hamachi, Robocopy, and Task Scheduler

Mainly so I can remember what I am doing for remote backup, I wanted to share what I have lashed together from a wonderful free private VPN service, LogMeIn Hamachi, and the Windows Robocopy and Task Scheduler.  I guess for what I specify below to work, you don't really need to use LogMeIn Hamachi, you could use over a secure  home network or VPN, as long as the two computers are accessible to each other via specification of a UNC.

Don't proceed unless you already know something about accessing resources over a network (i.e. you know what a UNC address looks like), you are familiar with Task Scheduler, and more generally, you know what you are doing.  And unless you know something about sharing folders in Windows and setting permissions, don't go any further, you're really endangering yourself.  This guide is intended with someone already familiar with the elements I refer to, and is intended more than anything else as a hint about to put them together for a poor man's remote backup.  I absolutely can't provide any help to anyone, and you really shouldn't try any of this unless you have a pretty good idea of what the elements are.

Basically I wanted to automatically backup the contents of my Users folder on home machine to an external drive on my office machine, and the contents of my Users folder on my office machine to my home machine.  I am not too worried about backing up a drive image because I use only a limited number of apps, and anyway, if something happens to my machine that requires a restoration, I would rather just reinstall the operating system and the apps rather than restore from an image.  So all I care about is backing up content.

The solution that I finally settled on was to take advantage of the existing VPN I had created with Hamachi LogMeIn that connected my home and office computers and my laptops, and then set up a Robocopy task to run regularly with Windows Task Scheduler.

What is Robocopy?  It is a Windows utility that is like the old XCopy on steroids.  It has a rich, maybe overwhelming array of options for mass copying of files, including lots of flags that allow restricting copying to files that are newer on the source than on the destination, and so forth.  I had experimented with a bunch of different approaches to automated copying, most notably SyncToy, but in my experience they didn't work.  SyncToy is very nice but it seemed to choke on large folders with lots of subdirectories and small files, for example, music collection, and photo collection.  Other tools I experimented with always seemed to have some problem, for example, they didn't play well with network locations, and so forth.  Robocopy, however, seems to be really robust, and I haven't had any trouble whatsoever with it.

I shared the user directories on my home and office machines with appropriate permissions so the folders would be accessible only to my own password protected user accounts on other machines on the network.  If you don't know or understand what permissions are for shared folders, don't read any further, this is not for you and trying this could be really dangerous.

Say that the Hamachi-assigned IP address of my home machine was 5.1.1.1 and the IP address of my office machine was 5.1.1.2..., and I had shared C:\Users\John Smith on my home machine as "John Smith Home"

And on my office machine I had an external HD (F:) with a folder to be used for home backup called "Home Backup"

I specified a task on my office machine to run every day that looked like the following...

Robocopy "\\5.1.1.1\John Smith Home" "F:\Home Backup" /XA:HS /S /XO /XD AppData Searches Desktop Downloads Favorites Links /MIR /R:0 /W:0 /LOG:"C:\Users\John Smith\Documents\Home Backup .log"

All those flags are basically there to the specify the files that are being copied.  Key ones are /S, for copying subdirectories, /XD for excluding directories, in this case AppData Searches and so forth, all stuff I didn't want backed up, /XA for excluding files with particular attributes set, in this case /XA:HD excludes hidden files,  /MIR specifies mirror so that files that are no longer on the source are deleted from the destination, /XO excludes older files (i.e. only copy files that are newer on the source than on the destination), /R:0 soecifies number of retries on failed copies, in this case I set to zero so it would give up on a failure and move to the next file, /W:0 is wait time between retries, set to 0 here but meaningless since the /R:0 should prevent any retries, finally /LOG specifies a log file.

I set up additional tasks for my photo collection since it was too large to reside on my C: drive, and is on an  external drive.

I did the same on my home machine to backup my office.

This has been running smoothly now for several years, and works for me.  It seems to work a lot better for backing up really large folder trees with thousands and thousands of files like my music and photo collections than SyncToy and some of the other applications I experimented with.  As I mentioned, SyncToy seemed to choke when thousands of files were involved.

One problem I did encounter: using Robocopy to back up directory trees associated with the latest versions of Thunderbird seemed to be impossible.  At least the most recent version of Thunderbird I had seemed to create thousands and thousands of folders with strange names and backup always seemed to blow up.  Since I had given up on Thunderbird anyway, and only wanted my old email for archival purposes, I just zipped the whole directory so it would copy as one big file.

0 comments: