Using Task Scheduller to run Robocopy Scripts

YellowbusTeam
YellowbusTeam used Ask the Experts™
on
Hi Guys,

We have a Server 2008 Standard edition server running service pack 2 (this is not R2).

We use Robocopy to backup data from the server to a NAS box over night, this is setup to run via a Windows Schedulled task. When it runs over night we get the following error (0x41306), this result is returned for all out Schedulled tasks that we have on the server.

If we try to run the Schedulled tasks by clicking run, it all apears to work... but it doesnt as there is no mapped drive appearing in windows explorer for the NAS box.

If we run the Robocopy script on its own and not through the Schedulled taks it runs fine and we dont get anyy errors (if a little slow).

Any help on this would be greatly appreciated?

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
There are two likely culprits for this message.  One that I have seen that is very common especially in windows 2003 is that the command prompt that is open cannot locate the robocopy.exe file to execute the program.  The other is that the network drive you are mapping to cannot be located.  A possible fix is to add a line to your bat file like:

net use X: \\NAS_Box\Backup

This will ensure that your network drive is mapped and that the drive letter matches the one used by robocopy.  In addtion you can also robocopy directly to a shared path.

robocopy.exe "C:\User\%Username%" "\\Backup_Server\MyDocs_Backup" /e /DATS /R:3 /W:1 /LOG:C:\RC_Logs\mydocs.txt

You may also notice that the /LOG parameter is called.  This is always a good idea so you can see if your command is ever actually running or if your error happens before robocopy is even executed.
Top Expert 2012
Commented:
First I would create a batch file that then calls up the script you shouldn't have the script put in directly into Schedule Tasks make sure you have a batch file calling up the script in schedule tasks.

Author

Commented:
The Robocopy script runs whitout any issues when you run it manually on the server. It maps the network drive on the NAS box and then backups all data to that drive letter.

It is a specific issue within task schedullar when it comes to execute robocopy... as it returns (0x41306) when it has supposedly finished its job.
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

Author

Commented:
Sorry yes i should of stated Robocoy batch file not Robocopy script.

for example we have daily.bat, week1.bat and so on for the batch files and the schedulled taks follow on occordingly.
Top Expert 2012

Commented:
Create another batch file that calls up the daily.bat and week.bat see if this fixes the problem.

Author

Commented:
i have created a batch file to call the original batch file and ammended the schedulled task. i have run the batch file to check all is working and it is. I have run the schedulled task and it is showing a status of running but how do i know it is definetly working??
Top Expert 2012

Commented:
Check to see if files are getting copied.

Author

Commented:
Ah Yes it appears to be copying files... Although it seems to be at snales pace...
Top Expert 2012

Commented:
That has nothing to do with the actual schedule task not running.

Author

Commented:
Yes i know.
I will see what the end result is tomorrow as there is a large volume of filess to be copied accross.
Please use /LOG and post the log that is created.  It will tell you what was transfered or not and also how long, avg speed etc, thanks
Top Expert 2012

Commented:
Ok but the Schedule task problem is fixed, right? And the batch file calling up the other batch file fixed the problem

Author

Commented:
ok...
I have checked the schedulled task this morning and we a seeing a last run result of (0x8004131F), anybody know what this means??

I have checked the files and it appears to have copied data accross but it is still running at this moment at time.
Top Expert 2012

Commented:
Means schedule task is already running

SCHED_E_ALREADY_RUNNING
0x8004131F

http://msdn.microsoft.com/en-us/library/aa383604(v=vs.85).aspx

Where are you trying to copy the data, because to me it sound like you are trying to copy it over a very slow link and it is giving you fits.

Author

Commented:
We are trying to copy data from our DC server to a Netgear NAS box over the LAN.

How come you no longer get the command line screen like you used to do when you run a schedulled task on a 2003 server?

Ta
If you schedule a .bat to run your robocopy script you can add the /TEE switch in order to log the copy and also to have a command prompt where you can monitor the status while the transfer is taking place.  You will notice after a couple copies that most files are skipped and that the transfer does not take nearly as long.

Author

Commented:
is the /TEE switch at the end of the line where you would place /w:2 ans so on??
Correct

example:

robocopy.exe <source> <destination> /e /DATS /r:3 /w:1 /TEE /LOG:<logfile_name>

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