Skip to content

How to run Robocopy as a SQL Server 2012 Job In Maintenance Plan

by on May 15, 2014



  1. Create the Robocopy job in Jobs
  2. Add a step that calls the Robocopy command with some error handling of additional robocopy errors (see robocopy documentation for more info)
  3. Create a maintenance plan with a “Execute SQL Server Agent Job Task” step or just schedule the Job outright
  4. Run your Job or Plan – you should only get errors if it actually fails to run now

Example Command

c:\robocopy\robocopy w:\backup \\RemoteServer\sql_backup\sql12 /s /mov /log:"C:\robocopy\rlogs.txt" SET /A errlev="%ERRORLEVEL & 24%" EXIT /B %errlev%

UPDATE: Failure!

I recently had this randomly stop working properly – not sure why, but I had to remove the error handling and live with it "failing" (it actually completes properly, but robocopy has some additional "error" results other than 1 and 0). My .trn cleanup task now runs on complete, not success, and I get a warning if the drive space gets close to full, so I think I am covered.

Very annoying that it just changed for some reason!


  1. remove “SET /A errlev="%ERRORLEVEL & 24%" EXIT /B %errlev%”
  2. Plan for this step to error out and fail
Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: