SQL Agent executes RoboCopy via PowerShell

  • only it doesnt execute it.

    I have one specific server on which this doesnt run. a few on which an identical job-step works just fine.

    on the one that doesnt work:

    1) the script runs just fine if I open Powershell console and paste in the command

    2) also works if I run just the robocopy portion via cmd line

    3) it initiates a ROBOCOPY.EXE process, but nothing more. The process and job-step just hang, and do not move any files to the target directory.

    the job step shows Run AS: 'OS_Adminstrator'. The ones I see this working correctly under execute as OS_Proxy, which is NOT an available option on this server.

    This was setup by someone else, and Im by no means Powershell Knowledgable or savvy... any direction you can provide would be apprecaited!

  • I've run into some subtleties when using ROBOCOPY as a SQL Agent job step:

    1. Don't paste the ROBOCOPY code into a SQL Agent job step properties, general page, command window. Instead, in the SQL Agent job step properties, general page, command window, show the "JOB.bat" path and file that contains the ROBOCOPY commands, like this: "C:\BatchCommandScriptFiles\CopyBackedUpBakFiles.bat".

    2. Execute the job step as the SQL Server Agent service account. On our servers, this is the same account as is used for the SQL Server service.

    3. In the job step properties, "General" page, the "Type" is "Operating system (CmdExec)".

    4. In the ROBOCOPY.bat file, be sure to include a second line of script code ("EXIT 0") to make sure the job doesn't return a status of failed: "C:\Program Files (x86)\Windows Resource Kits\Tools\ROBOCOPY" "Z:\Database Full Backups" \\DC-NAS01\SharedSqlBackups *.bak /S /COPY:DAT /XO /R:0 /NS /NC /NFL /NDL /NP

    EXIT 0"

    Hope this information helps you,

    LC

  • thanks Lee.

    Im trying to figure out why these were configured under PowerShell initially, and not really getting anywhere 😉

  • Understood. I don't have very much experience with Powershell.

    Could you make them part of a SQL Agent job? When our database backup jobs execute, the jobs execute:

    > step 1 - database backups

    > step 2 - database backup file copy operations using a ROBOCOPY batch file as I've shown

    This has worked well for us.

    LC

  • fixed.

    changed the destination path to a local dir and it worked.

    changed back to UNC path, and added /R:0 and it 'succeeded' the job, but did not move files.

    pointed us to a security issue on the destination side which I was able to sort out.

    thanks for the tips, appreciate it! 🙂

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply