Where can I find ready to use windows scripts that used robocopy?
Solution 1
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.
Solution 2
I don't have any scripts, but the built-in documentation is really easy to understand and very useful.
robocopy /? | more
Related videos on Youtube
bassen
I have been exchanging knowledge for over 11 years, StackExchange just makes it easier. Come and find out which other SE sites I collaborate. Follow me on Twitter.
Updated on September 17, 2022Comments
-
bassen over 1 year
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.
-
akai almost 15 yearsAre 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.
-
-
bassen almost 15 yearsThanks, 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.
-
Olof Åkesson almost 15 yearsThis 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.
-
bassen almost 15 yearsThanks Charles. Do you use the /mir option for your solution?
-
Charles almost 15 yearsyes depending on the job. We have several that do not due to legacy data however.
-
Ryan Ferretti almost 15 yearsDon't forget "robocopy /??? | more " to get the full documentation for all the switches.
-
Kiquenet over 7 yearsany samples (options, parameters ) RoboCopy scripts ? anyways, can you create a scheduled task programmatically ?
-
Kiquenet over 7 yearsdoes you still use robocopy script ? now, any alternative better than robocopy ?