Help needed with to script Robocopy

llarava
llarava used Ask the Experts™
on
Hi,

I have two USB disk attached to a server. I have copied all the data from disk E: to disk F: I want now to setup Robocopy in order to run diferential copies from E: to F:

The goal would be to use a batch or vbs to run robocopy and the right switches in order to copy all the changes.  Once I have the script I will run a scheduled task.

I have found the following script but it does not work.  am getting following output on my console which is repeating continously:

Maximum setlocal recursion level reached.

Could someone help me out.

Thank you.

@ECHO OFF
SETLOCAL
 
SET _source=E:\
 
SET _dest=F:\
 
SET _what=/COPYALL /B /SEC /MIR
:: /COPYALL :: COPY ALL file info
:: /B :: copy files in Backup mode.
:: /SEC :: copy files with SECurity
:: /MIR :: MIRror a directory tree
 
SET _options=/R:0 /W:0 /LOG:MyLogfile.txt /NFL /NDL
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /NFL :: No file logging
:: /NDL :: No dir logging
 
ROBOCOPY %_source% %_dest% %_what% %_options%

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Have you named the script robocopy.bat, robocopy.cmd, or something else which matches the name of an existing command?  If so, rename it.
Try Syncback: has freeware version which is excellent: http://www.2brightsparks.com/freeware/freeware-hub.html

Author

Commented:
Shift-3:

No I haven't can please tell me why?
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Commented:
A search turned up a PAQ in which someone received the same error after naming their script robocopy.cmd.
Ben Personick (Previously QCubed)Lead SaaS Infrastructure Engineer

Commented:
What OS is running on the Server?  2K, 2K3, 2K8?  2K8 R2?

If it is Windows 2000 or Windows 2003, what version of the support tools did you install?  Windows 2000 or Windows 2003?
Ben Personick (Previously QCubed)Lead SaaS Infrastructure Engineer
Commented:
I believe Shift-3 is correct, you have the file named as "Robocopy" with an executable extention, such as bat, or cmd, or exe, or com, etc.

Solution: Save your batch file as C:\MYFILE.bat

then try running it.

Hmm, the more I look at this the more problem I see,  the text below has gotten quite a bit longer than initially expected.  Please see the attached script, it should help a lot.


If this is not the case, then I think it's because you are using the Unnecessary Verb "SETLOCAL" in your script.

SETLOCAL is generally unnecessary in a Windows NT Environment, because each command prompt is a visualized instance of the command shell and will not interact with others.  And Each is instantiated and destroyed at the time of the batch file's execution, via double-click or scheduled task.

The only time you might consider using SETLOCAL is when you call one batch from another batch and are using variable names which are the same in both.  However it should always be Paired with an ENDLOCAL command at the end of the batch file to release the local scope you've created.

It is a best bet to drop that command entirely, and if the batch file is being called by another batch file to ensure variables are named differently in each.

PS, you have some poor syntax here as you don't specify FQ Paths for the Logs, also you probably would be better served NOT using the /NFL and /NDL switches, and instead using the /NP and /TEE Switches, this way you will see the full patch and file name displayed, and you will not generate the percentage progress indicators

ALSO you are leaving a trailing \ on the source and destination drives, that will FUBAR RoBoCopy and cause strange behavior.

I have attached a batch file I feel to be a better version of this one, though does not contain the level I would normally put in as I think you may have abandoned your question.


::------------------------------------------------------------------------------------------------::
:: Script: Robocopy_Clone-Drives.Bat                                            				  ::
:: Version: 1.0                                                                                   ::
:: Copyright: Ben Personick                                                                       ::
:: Date: 2010-07-06                                                                               ::
::                                                                                                ::
::                                                                                                ::
:: Desc: Clones Directory Structure from one Hard Drive to Another								  ::
::                                                                                                ::
::------------------------------------------------------------------------------------------------::
:Begin
@ECHO OFF

:Start-Set-Variables
SET TDate=%date:~10,4%-%date:~4,2%-%date:~7,2%
SET TTime=%Time:~0,2%.%Time:~3,2%.%Time:~6,2%
SET LogDrive=C:
SET SrcDrive=E:
SET DstDrive=F:
SET LogDir=DriveClone\Logs
SET LogFile=DriveLone_%TDate%_%TTime%.Log

:: FYI I think you are being a little silly putting all of these options into a variable in your script because it's such a minor script but I'm leaving this here for your benefit
SET RoBoOptions=/COPYALL /ZB /SEC /MIR /R:1 /W:2 /LOG:%LogFile% /NP /TEE
:: /COPYALL :: COPY ALL file info (/SEC is Redundant!!)
:: /ZB :: Copy files in restartable mode, if they cannot be accessed copy them in Backup mode.
:: /MIR :: MIRror a directory tree
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /NP :: No Progress Logging
:: /TEE :: Output information to the screen as well as the log file, to keep track of progress
:End-Set-Variable

:Start-Robocopy
SET TDate=%date:~10,4%-%date:~4,2%-%date:~7,2%
SET TTime=%Time:~0,2%.%Time:~3,2%.%Time:~6,2%
Echo ON %TDate% AT %TTime% - Begining: Robocopy %SrcDrive% %DstDrive% %RoBoOptions%
Echo ON %TDate% AT %TTime% - Begining: Robocopy %SrcDrive% %DstDrive% %RoBoOptions% >> %LogFile%
ROBOCOPY %SrcDrive% %DstDrive% /COPYALL /ZB /SEC /MIR /R:1 /W:2 /LOG:%LogFile% /NP /TEE
SET TDate=%date:~10,4%-%date:~4,2%-%date:~7,2%
SET TTime=%Time:~0,2%.%Time:~3,2%.%Time:~6,2%
Echo ON %TDate% AT %TTime% - Completed: Robocopy %SrcDrive% %DstDrive% %RoBoOptions%
Echo ON %TDate% AT %TTime% - Completed: Robocopy %SrcDrive% %DstDrive% %RoBoOptions% >> %LogFile%
:End-RoboCopy

:End

Open in new window

Ben Personick (Previously QCubed)Lead SaaS Infrastructure Engineer

Commented:
Thanks for the points, glad I could be of assistance! =)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial