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.

Geo
  • 3,061
  • 11
  • 41
  • 52
  • 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

7 Answers7

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.

Marcus
  • 536
  • 1
  • 3
  • 9
2

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

robocopy /? | more
tomfanning
  • 3,308
  • 6
  • 33
  • 34
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.

Trondh
  • 4,191
  • 23
  • 27
  • 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
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.

Charles
  • 879
  • 5
  • 9
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

Fishwalker
  • 409
  • 4
  • 11
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.

nray
  • 1,540
  • 17
  • 23
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.

Walter
  • 1,047
  • 7
  • 14