Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We are installing the Windows Resource Kit, and that installs RoboCopy. We want to have access to a few windows scripts that uses RoboCopy so we can start from those to build something else. Any ideas on where I can find a few samples?


A bit of information. Every time we try to copy D drive to E drive (new drive) we get an error that says:

ERROR 32 (0x000000020) Copying File d:\pagefile.sys The process cannot access the file because it is being used by another process. Waiting 30 seconds.

Just to help figure it out.

share|improve this question
Are you looking for the /XF parameter to exclude pagefile.sys, or are you trying to copy the page file. I think the page file will always be in use while the system is running. I don't think you would need to copy it though. – railmeat Jul 27 '09 at 23:02

I used Robocopy to synchronize website content across 9 web servers. Here's a sample of the batch file that ran robocopy.exe. This batch file was scheduled to run every 5 or 10 minutes or could be run manually to push changes immediately.

robocopy.exe d:\inetpub\wwwroot\ \\webserver1\d$\inetpub\wwwroot\ *.* /E /PURGE /SEC /NP /NJH /NJS /XF keepalive_*.* /XD trigger /XD "D:\inetpub\wwwroot\Long Path Name" /R:5 /COPYALL /LOG:copy_to_webserver1.log

The previous command will copy the content of d:\inetpub\wwwroot and push it to the remote server's d:\inetpub\wwwroot.

/E = copies all subdirectories including empty ones
/PURGE = deletes destination files/folders that no longer exist in the source
/SEC = copies the security permissions (ACL) of the files to the destination location
/NP = turns off the copy progress bar; DEFINITELY do this if you are logging the results
/NJH = don't log the job header
/NJS = don't log the job summary
/XF = exclude copying specific files (e.g. keepalive_*.*)
/XD = exclude copying specific folders (e.g. trigger)
/R = specifies number of times to retry if the copy fails (e.g. 5)
/COPYALL = copies everything: data, attributes, timestamps, security, ownership and auditing information; overkill really since I specified /SEC
/LOG = log results to the specified log file (e.g. copy_to_webserver1.log)

I hope that gets you started on Robocopy. I found it to be a highly reliable and very robust solution for keeping our content in sync.

share|improve this answer

I don't have any scripts, but the built-in documentation is really easy to understand and very useful.

robocopy /? | more
share|improve this answer
Don't forget "robocopy /??? | more " to get the full documentation for all the switches. – mrdenny Jul 28 '09 at 0:03

Its really so simple that most just do their own from scratch. I have never seen any "code samples", as its basically just a matter of from where, to where with some parameters thrown in... but have a look at the different robocopy GUIs out there (just google it), most of them will show you the generated command.

share|improve this answer
Thanks, the basic use of robocopy itself is simple, I agree. I was hoping to see something for exception handling and other fault tolerance on the scripts itself. Basically i am looking to have a schedule job copy one drive to another drive. – Geo Jul 27 '09 at 21:43
This sort of stuff is pretty much handled internally in Robocopy, for example it will auto-retry files by default ad infinitum if they are locked. The parameters to Robocopy are how you control this behaviour, rather than by building any scripting voodoo. – tomfanning Jul 27 '09 at 21:57

So , looking at your comment to Trondh, I have several RoboCopy scripts that are scheduled, however the way this is accomplished (by me anyway) is via scheduled task. So as an example, I have a RoboCopy Script that copies files from drive X: to Drive Y: using whatever parameters I specify. I then create a scheduled task to run this script at a specified interval, and if I am worried about monitoring this script, I can create a second step to the task that emails myself the output log if I want to review it regularly.

share|improve this answer
Thanks Charles. Do you use the /mir option for your solution? – Geo Jul 27 '09 at 22:04
yes depending on the job. We have several that do not due to legacy data however. – Charles Jul 27 '09 at 22:06

Start small, just copying a single folder from point a to point b. Be sure to include the /L switch and the /LOG switch. The /L switch just lists the files it would have copied and the /Log will create a log so you can verify what you want copied. From there you just increase the complexity. For an example script:

robocopy "C:\test_source" "\server01\C$\test_destination" /L /V /E /LOG:"c:\test_robocopy.log" /R:10 /W:30

share|improve this answer

To solve the second problem, (the locked file error and subsequent wait), use the switches /r, /w and /reg, for example:

robocopy D:\ E:\ /r:1 /w:1 /reg

This means retry one time only after waiting one second and make these settings default in the registry.

share|improve this answer

The linked script is a template that can used to copy open files. You can just change the copy command in the script to robocopy and you will be able to robocopy open files.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.