August 24, 2005 at 5:01 am
Hi I have a robocopy script that I wish to run after the nightly backups to copy the contents of the backups to another server.
I tried creating a DTS package with an execute process task that calls robocopy as the win32 process with the parameters of what I want to copy and where as the parameters. When I execute this and there is work for robocopy to do; the robocopy runs fine but the DTS reports an error code of 2. How do other usually run robocopy ?
August 24, 2005 at 4:50 pm
Robocopy has an annoying "feature" in having non-zero return codes that indicate success. What I used to do was execute ROBOCOPY in a VBScript. Capture the return code and exit with the appropriate code. From memory, I think any exit code less than 4 is ok.
A few months back I switched from having a seperate VBScript to running ROBOCOPY from within a stored procedure using xp_cmdshell. Here a snippet of the whole procedure. It takes a backup file and archive path as parameters.
SET @Cmd = '%systemroot%\ROBOCOPY ' + @BkpPath + ' ' SET @Cmd = @Cmd + @ArcPath + ' *.*' SET @Cmd = @Cmd + ' /MOV /XX /NP /LOG:' + @vcrLog EXEC @Err = master.dbo.xp_cmdshell @Cmd -- error codes returned from ROBOCOPY that are less than -- four just indicate that files where found and copied -- so they should be ignored IF @Err < 4 BEGIN SET @Err = 0 SET @TxtErr = '' -- write message to activity log SET @Msg = 'Backup file ('+ @BkpFile + ') moved to (' + @ArcPath + ') ' EXEC DBA.dbo.usp_InsMessageLog @ProcName, @Msg, @TxtErr END ELSE BEGIN -- Move to archive failed SET @Err = 60000 + @Err SET @TxtErr = CAST(@Err as varchar(50)) -- write message to activity log SET @Msg = 'ERROR: Could not move file (' + @BkpFile + ') ' SET @Msg = @Msg + 'to archive directory (' + @ArcPath + ')' EXEC DBA.dbo.usp_InsMessageLog @ProcName, @Msg, @TxtErr RAISERROR(@Msg, 10, 1) WITH LOG END
--------------------
Colt 45 - the original point and click interface
August 27, 2005 at 5:24 pm
Thanks Phil, that's perfect
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply