In a recent post, we spoke of correcting a scheduled process that was failing on the robocopy step.
We fixed it by setting the Scheduled task to run with the “Run with highest privileges” option turned on.
Here is the original code
robocopy \\DBPROD\f$\SQLBackups\csLogins F:\Microsoft\SQLServer\Restore *.bak /ZB /ETA
ERROR: You do not have the Backup and Restore Files user rights. ***** You need these to perform Backup copies (/B or /ZB).
Here is the revised code
robocopy \\DBPROD\f$\SQLBackups\csLogins F:\Microsoft\SQLServer\Restore *.bak /Z
And, here is another version that we tweaked a bit
set "_app=robocopy" set "_srcFolder=\\DBPROD\f$\SQLBackups\csTrafficSchool" set "_srcFile=*.bak" set "_destFolder=F:\Microsoft\SQLServer\SQLRestore" @rem Initiate copy %_app% %_srcFolder% %_destFolder% %_srcFile% ^ /r:1 /w:1 ^ /NP ^ /LOG+:%_LOG_FILE%
We originally chose the /zb option as it offers the “restartable” option.
Unfortunately, /zb connotes restartable and backup.
In this case, it was an overkill.
Choosing /z is sufficient.
To squeeze out some performance:
- We added /r and /w to restrict number of retries and duration between retries
- Also, added /LOG to log to a file rather than to the console
Though, unfortunately not quite useful, here is what we captured via SysInternal’s Process Monitor.
When successful, robocopy follows the “Create File Mapping” operation with querying the remote server and getting the files that match our file signature. And, upon doing that the destination is queried to determine whether same files exist.
I think replacing the /zb option with /z is a more granular and direct approach.
Here are the quick reasons:
- The earlier option runs the entire scheduled task with this (Run with highest privileges) option on.
- This means that we are not setting at an intermediate step level, but for the entire task