Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


September 2005

Add Robocopy to Your Toolbelt

The Ginzu knife of file copy, backup, and transfer
RSS
Subscribe to Windows IT Pro | See More Resource Kit Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

One of the Microsoft Windows Server 2003 Resource Kit's most versatile utilities is Robocopy (aka the Robust Copy Utility). Yes, Robocopy copies files, but before you get bored and turn the page, give this interesting utility a chance. Robocopy can handle copy operations involving huge chunks of data, and it lets you make certain specifications that other copy utilities—such as Copy and Xcopy—don't understand. For example, you can use Robocopy to copy a certain directory tree but only three levels down, and you can specify that Robocopy not use more than a third of the network bandwidth during a given copy operation.

If Robocopy has a weakness, it's syntax. The resource kit's robocopy.doc file doesn't really do anything except explain Robocopy's syntax—and it's 32 pages long. So let's dive in and check out some Robocopy basics.

Robocopy Basics
In its simplest form, Robocopy has a slight resemblance to other command-line copy tools:

robocopy <source directory> <destination directory>
   <filenames> <options>

Say I want to copy everything from the C:\stuff directory to the C:\stuffbak directory. I'd type

robocopy C:\stuff C:\stuffbak

So far, so good. That looks just like a Copy or Xcopy operation. But what if I want to copy only the text files whose names start with "s"? In Xcopy, I'd type something such as

xcopy C:\stuff\s*.txt C:\stuffbak

However, that syntax won't work with Robocopy. Instead of cramming together the source and destination directories with the file specifications and filters, Robocopy has a separate place for the latter items. To copy just the aforementioned text files, for example, you'd type

robocopy C:\stuff C:\stuffbak s*.txt

Network Considerations
So far, I've used source and destination examples that are merely local file folders, but Robocopy can also handle Universal Naming Convention (UNC) names, such as

robocopy \\marksws\myfiles \\centralserver\marksfiles

That command would copy everything in the myfiles share on the marksws machine over the network to a share named marksfiles on a machine named centralserver. Such functionality might be useful, but now that we've added networks to the mix, we'll need to worry about network reliability.

Any network copy operation can be interrupted by any of dozens of potential network problems. In many cases, network problems clear themselves up after a little while, so you need only try the operation again after a short wait. But who wants to babysit a big network file transfer? Fortunately, you can tell Robocopy to retry a copy operation after a specified number of seconds in the event of failure (with the /w:xx option), and you can specify the number of times it retries (with the /r:yy option). So, to tell Robocopy that you'd like your network file-copy job to retry as many as 13 times and to wait 30 seconds between retries, you'd type

robocopy \\marksws\myfiles \\centralserver\marksfiles
   /w:30 /r:13

If you don't specify a waiting period or a number of retries, Robocopy uses a default of 1 million retries for /r and 30 seconds for /w. In theory, then, a simple Robocopy command over an unresponsive network could take just under a year to complete (not that I've actually tested that).

Sometimes, a network copy job fails for a simple but annoying reason. For example, you might not have permission to read all the files you're trying to copy. (Such can be the case when you're trying to back up a user's profile or home directory.) If you need to back up some files but you don't have the NTFS Read permission, check to see whether you have Backup rights to the files—remember, they're not the same thing! If you do, you can use Robocopy with its /b or /zb options to back up the files. The /b option tells Robocopy to use the Backup permission, and the /zb option tells the tool to first try a standard copy operation, then try the Backup-based copy should that fail.

Just a Start
My intention here was to scratch the surface of Robocopy and tempt you to take a gander at the tool's online documentation. Next time, I'll share some more Robocopy functionality.

End of Article



Reader Comments
How about another art on Robo Copy

A little deeper maybe how to script a full copy of a directory with several words in it,s name like "My Documents" do you use quotes? Or do you truncate the name My~ ??

doc_rice21 January 24, 2006 (Article Rating: )


Good start; but there is so much to this little utility. We use it regularly to move user data around a 10K user network (migrations, SAN re-allocation etc.) in blocks typically of 50Gb+.
There are also caveats! - one that comes to mind is the disaster you can cause using the Mirror option... as a colleage discovered.
So maybe a pitfalls article :)

robtheailean January 25, 2006 (Article Rating: )


Your site is the MOST complicated site I have ever seen. Why don't you make a simple site to navigate and read???????

vishantpatel August 10, 2006 (Article Rating: )


I'm having difficulty using this tool when I simply want to copy multiple data folders (up to 2 levels down) and it's NTFS permissions but not copy the files. Can you please indicate what the command line switches I should using?

Etepi November 22, 2006 (Article Rating: )


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...

WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...


Related Events Deep Dive into Windows Server 2008 R2 presented by John Savill

7 Ways To Get More From Your SharePoint Deployment Now

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement