The Awesomeness That Is RoboCopy

I had the opportunity to enjoy a little R&R over the holiday season. (For the uninitiated, R&R does not mean "rats & rodents", though they might be delicious. Instead, it means "rest & relaxation" - or as Elmer Fudd would put it "west & wewaxation"). And one of my favorite things to do over those grey winter days is to clean up my office and hard disks, delete or round-file unnecessary files, archive oldies but goodies, and otherwise freshen up for the start of the new year.

I've had the opportunity to try lots of third-party archiving and backup tools and many of them are definitely worth the money. However, what if you're a dyed in the wool cheapskate like me?

There are several tools to investigate that are worth your time (to learn more, visit " Off-Box Backups and Luke-Warm Standby Servers" and " SQL Server Backup Comprison"). Today, I'll tell you about my one favorite - RoboCopy. (I'll also tell you about a few alternatives in a future blog post.)  RoboCopy enabled me to rather easily create a backup script that copied all of My Documents once and then, on fortnightly intervals, copy only those files which had changed since my last backup.

RoboCopy, which always reminds me of the 1987 movie called RoboCop, is in fact an acronym for "robust copy" and has nothing to do with robots, droids, biots, or cyborgs.  It's a real shame too.

COPY and XCOPY = Bad, RoboCopy = Good

RoboCopy is a part of the Windows Server 2003 Resource Kit, but also ships with Windows Vista and more recent desktop OSes. RoboCopy has a variety of stellar features that make it worth adding to your toolkit, even if you don't use it for frequent desktop backups like I'm now doing. Here's a sampling:

  • self-restarting copies after encountering a failure or network disconnect with a configurable number of retries
  • parameterized scripting
  • logging
  • coppying files above or below a certain age
  • moving files (i.e. deleting them from the source after they are copied)
  • copying any or all of a files attributes and permission settings (including NTFS attributes not copied by utilities like XCOPY)
  • file monitoring, such that when a source file has changed, it will be recopied to the destination
  • file excluding, such that when a target file exists, done bother to overwrite it unless the source file is newer

In Windows 7, you can set a switch to perform a multi-threaded copy, enabling multiple files to be copied simultaneously.

Wanna Learn More?

There's a decent little tutorial for RoboCopy.  You can find two nice command-line references for RoboCopy and here.

I like the nice example of a RoboCopy script to copy Analysis Services files written by Denny Lee on the SQLCat team.

GUI Is Kind'a Like Lazy Only With A Prettier Interface

If you're not one for command-lines (I chastize thee!) then you can download a GUI, written by a Microsoft engineer named Derk Benisch, to do the heavy lifting for you. If the GUI has any weakness, it is that it lacks good documentation.  You can find out what a single switch is about by hovering the cursor over it, but I really didn't feel comfortable with it until I read the regular RoboCopy help information which fully explained all of the switches.

Here's a tutorial for the RoboCopy GUI.

What'd He Do? What'd He Do?

 So what did my RoboCopy script look like? First, the requirements. I wanted a backup routine that'd make a copy of "My Documents"(the source) and copy it to an external hard disk called "Maxtor" (the target). I also wanted the copy process to restart in the event of failure and to copy all of the file attributes, while keeping the Last Date Modified unchanged. Finally, since I have many files that don't change much, I wanted the copy process to grab everything the very first time but then to only grab those files that'd changed since my last copy process thereafter. Make sense?

Here's the script:

ROBOCOPY mydocuments maxtor /E /COPYALL /Z /R:3 /W:10 /LOG:robolog.txt /QUIT /XO

Here's what each switch means:

  • mydocuments = source
  • maxtor = target
  • /E = copy all subdirectories even empty ones
  • /COPYALL = copies all attributes
  • /Z = copies in restartable mode
  • /R:3 = retry up to three times
  • /W:10 = wait10 seconds between retries
  • /LOG... = log all operations to the specified file
  • /QUIT = exits the command-line when done
  • /XO = excludes older files if they already exist on the destination, unless the source has the same file with a newer date

So that's a quick and easy archival copy process using ROBOCOPY.  Next time, I'll show you some alternative tools and utilities that you might prefer.

Toodles,

-Kev

 Twitter @kekline

 More content