Search This Blog

Wednesday, June 06, 2012

How to run Robocopy from SQL without a batch file

There is a problem running Robocopy from a command step in SQL server jobs. Robocopy returns a non zero code for success, I won;t go into why that is here. It is to do with flags and ANDing if you want to look it up.

So if you call Robocopy directly the SQL step will always fail (even though it is successful).

My way round that it is to use START. Now this solution will always return success so if Robocopy does actually fail you will never know. For my purpose this was acceptable. You can get around this by placing your Robocopy command in a batch file, call the batch file from SQL Server job step.

So to use START

START "<window title>" /WAIT ROBOCOPY /COPY:DAT /MOV /NP ^"<source>^" ^"<destination>^"

This works for me.