• subscribe
January 12, 2010 12:00 AM

Tool Tip - The Awesomeness of RoboCopy

SQL Server Pro
InstantDoc ID #103430

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.  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 (found here: http://go.microsoft.com/fwlink/?LinkId=4544), 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 here.  You can find a couple nice command-line reference for RoboCopy here and here.

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

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 here.  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.

There are a couple tutorials for the RoboCopy GUI, such as this one and this one.

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 at http://KevinEKline.com/

 



ARTICLE TOOLS

Comments
  • Leenheer
    2 years ago
    Mar 15, 2010

    Instead of Robocopy, use RoboCopyPlus (www.robocopyplus.com).
    It is a wrapper around your instalaltion of Robocopy, that adds email notification depending on the job result (success, warning, error) and optionally attaches logfiles that it can strip down to showing the warnings and errors only.

    Becasue it's only a wrapper, it works with all versions of Robocopy and you can use yoru existing scripts pretty much; just need to add the swicthes that define the email message to be sent out.

    We use it for our customers and is hugely enhances the ease of managing som any daily jobs.

    Cool little tool :)!

  • KEVIN
    2 years ago
    Jan 18, 2010

    Cool, Josh. Do you have any recommendations for script libaries for ROBOCOPY? It'd be neat to discover that there are some out there somewhere. Also, I encourage you to join the conversation at the SQLMag Tool Time forum (http://sqlforums.windowsitpro.com/web/forum/messageview.aspx?catid=169&threadid=93919&enterthread=y). Thanks,

    -Kevin

  • Josh
    2 years ago
    Jan 13, 2010

    I use robocopy almost daily and have use it in tons of automation scripts. Nice article.

You must log on before posting a comment.

Are you a new visitor? Register Here