1

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?

NOTE 1:

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.

1
  • 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, 2009 at 23:02

7 Answers 7

5

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.

2
  • does you still use robocopy script ? now, any alternative better than robocopy ?
    – Kiquenet
    Dec 29, 2016 at 13:33
  • Yes, I'm still using it. It's easy to use and is already there. No additional install.
    – Marcus
    Dec 30, 2016 at 19:47
2

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

robocopy /? | more
1
  • 3
    Don't forget "robocopy /??? | more " to get the full documentation for all the switches.
    – mrdenny
    Jul 28, 2009 at 0:03
0

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.

2
  • 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, 2009 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, 2009 at 21:57
0

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.

3
  • Thanks Charles. Do you use the /mir option for your solution?
    – Geo
    Jul 27, 2009 at 22:04
  • yes depending on the job. We have several that do not due to legacy data however.
    – Charles
    Jul 27, 2009 at 22:06
  • any samples (options, parameters ) RoboCopy scripts ? anyways, can you create a scheduled task programmatically ?
    – Kiquenet
    Dec 29, 2016 at 13:14
0

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

0

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.

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .