robocopy script

I want to get a simple .bat file script to run once a week to copy files from one share to another. Can someone tell me the line I should put in it using robocopy? It has to point to where the robocopy command is on the system it runs on, and then copy a directory from one server to another. I also need to it to copy even if somebody has the file open, and it needs to copy permissions over.

Im going to setup a scheduled task to run it. Im not sure how the command should read. Thanks
Thomas NSystems Analyst - Windows System AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott CSenior EngineerCommented:
Here's the TechNet on Robocopy

 and here's some (11) examples for you with descriptions.

Robocopy comes with the versions listed the article I posted:

 Applies To: Windows 7, Windows 8, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012
NVITEnd-user supportCommented:
> I also need to it to copy even if somebody has the file open
Robocopy will fail to copy files that are locked by other users or applications... The Windows Volume Shadow Copy service is the only Windows subsystem that can copy open files.
Thomas NSystems Analyst - Windows System AdministratorAuthor Commented:
Thanks the examples are assuming we are at a command prompt at the location of the robocopy executable. How would I put that in the script so it knows where to run it from? Do I put "c:\robocopy "commands" " somewhere in it?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Scott CSenior EngineerCommented:
Try syncback if you want a nice program that can.

I don't know of any copy program that can copy open files.  You'll need a real backup solution for that.
Scott CSenior EngineerCommented:
Yes.  That should do it.  Or just make sure RoboCopy is in the path of that machine.
NVITEnd-user supportCommented:
To cover open file, you could do it with programs that use the shadowcopy service. Then combine that with robocopy.
Please keep in mind that the robocopy versions that come with the OS can have problems with copying NTFS permissions. This is a bug.
To overcome this you could use the older XP010 version which is included in the Windows 2003 resource kit (or the XP026 version).

For the XP010 version.
Download the Windows Server 2003 Resource Kit Tools
I would not install the software but just unpacking the files.
Unpack rktools.exe with e.g. 7-Zip
Unpack rktools.msi and copy "robocopy.exe" to the directory where you want to run the script.

For the copy script.
If you use UNC paths for Source and for Destination then make sure you have full control on the share permissions.
Also make sure that you have full control on the NTFS permissions.

For perfomance reasons it's always best to run the job on the destination server.

As an example:
Source is: \\server1\e$\Data\Groups
Destination is: \\server2\e$\Data\Groups

Be careful when choosing your source and destination.
Making a mistake can be very costly.

The bat or cmd file e.g. named SyncDirectory.cmd can contain:
@echo off
%~dp0robocopy.exe "\\server1\e$\Data\Groups" "\\server2\e$\Data\Groups" /MIR /NP /R:0 /W:1 /COPY:DATSO /LOG+:"%~dp0SyncDirectory.log"

Open in new window

/MIR  The mirror option will make sure that the destination will be exactly the same as the source.
      It also make sure that files that are deleted on the source are also deleted on destination.
/NP   Turns off the copy progress indicator
/R:0  By default robococpy will do 1000000 times a retry when a copy fails (e.g. due to an open file or a permission problem) and it waits 30 seconds between the retries. By setting the retry option to 0 the logon script will then still finish quickly instead of taking a lot of time (days).
/COPY:DATSO  For copying NTFS security (S in DATSO) and File Ownership information (O in DATSO)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Will SzymkowskiSenior Solution ArchitectCommented:
The below robocopy command is am example of the one that i use.

robocopy source destination /E /ZB /DCOPY:T /COPYALL /R:1 /W:1 /V /TEE /LOG:Robocopy.log

Open in new window

NVITEnd-user supportCommented:
@ Thomas,

I thought you needed to "...copy even if somebody has the file open"
Did my posts ID: 40916108 and ID: 40916119 not assist with your question?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.