Robocopy help on Server 2008 R2

I have a set of Robocopy scripts that I have been using on server 2003 for a couple of years quite successfully. Now I am trying to use these same scripts to do the same job from server 2008 R2 and they keep hanging up. Here is what they need to do:

I use the Task Scheduler to kick of a script each night that starts my process. The process is that Robocopy will collect files from a source PC and copy them to the destination storage on the server. Then it calls another script that uses a findstr and a txt to generate an output log file that is a summary of the log file created in the copy process. Then it starts a RoboEmail.vbs command that sends the summary log in an email to the designated email address. 

When I manually run the script everything works fine. When I run the script through the Task Scheduler the process goes through to sending the email then only sends the first four but will not send the rest. I see the summary logs created and in the Task Manager I see all the processes start and end but the emails do not go through.

The account that I run the script with has full Domain Admin rights and works fine when manually started but that is with my creds at that point. I am including the scripts below

    

This is what the Task Scheduler starts:

Title Lab Backup
@echo off
REM This script is to start the backup process. 
REM It need to have the path to the backup script the instrument name and the share name
rem Source     Inst   Share     Lab
Start C:\Source\Scripts\Instruments\INSBU.cmd PC395 CHEM32 Denver
Start C:\Source\Scripts\Instruments\INSBU.cmd PC342 HPCHEM Denver
Start C:\Source\Scripts\Instruments\INSBU.cmd PC306 CHEM32 Denver

Generally have 10 to 15 Starts here

This is INSBU.cmd that the above script starts:

Title Instrument Backup
@echo off
REM Written by Me to run instrument backups

REM Set Variables that are passed from the BU script that calls this script
set SDIR=c:\Source\Scripts
set INST=%1
set PTH=%2
set LAB=%3
SET SRC=\\%INST%\%PTH%
REM The destination drive may vary from server to server
SET DES=D:\Instrument_Data\Backups\%INST%\%PTH%
SET LOG=c:\Source\Scripts\Logs\%INST%.log
SET LOGOUT=c:\Source\Scripts\Logs\%INST%output.log

echo Instrument= %INST%
echo Path=%PTH%
echo Lab= %LAB%
echo Logout= %LOGOUT%
echo Source= %SRC%
echo Destination= %DES%
echo Log= %LOG%

Title %INST%

REM Run the backup script
cd c:\source\scripts\Instruments
Robocopy "%SRC%" "%DES%" /NP /FFT /Z /S /V /TEE /IPG:5 /R:5 /W:5 /XO /Log:"%LOG%"
REM This captures the errorlevel so that it can be reported in the email
set ERR=%errorlevel%
echo %LOGOUT%

REM Switch to the Logs folder and collect the summary results for the backup
cd c:\source\scripts\logs
call c:\source\scripts\logs\Results.cmd %INST%
echo %INST%

REM Send email to group indicated with the results of the backup and the error code that is generated
cd c:\source\scripts
START /MIN C:\Source\scripts\RoboEmail.vbs "%LAB%-InstBackupNotification@DOMAIN.com" "%LAB% %INST% backup log" "%LOGOUT%" %ERR% 
Exit

This is the Results.cmd call out to generate  the summary from above

@ECHO on
REM This script captures the summary information at the bottom of the log file 
REM and creates a new file to be attached to the email sent to the lab with results
REM The variables are sent from the backup script

REM Set Variables
set RSYS=%*
echo %RSYS%


findstr /G:finddata.txt %RSYS%.log > %RSYS%output.log
exit

This is the RoboMail.vbs to send the email to the intended destination

Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

Set objMessage = CreateObject("CDO.Message") 
objMessage.From = "Backup@testamericainc.com" 
objMessage.To = WScript.Arguments.Item(0)
objMessage.Subject = WScript.Arguments.Item(1) & " Error Code = " & WScript.Arguments.Item(3) 
objMessage.TextBody = "Facility backup log attached.  Error codes listed below" & vbCrLf & vbCrLf
objMessage.TextBody = objMessage.TextBody & "The attached log is a summary of the backup. The Detail log for this process may be too large to be emailed." & vbCrLf 
objMessage.TextBody = objMessage.TextBody & "You can Manually check the logs at \\SVR01\logs" & vbCrLf &vbCrLf
objMessage.TextBody = objMessage.TextBody & "Current Error Code = " & WScript.Arguments.Item(3) & vbCrLf & vbCrLf
objMessage.TextBody = objMessage.TextBody & "0 = No files changed" & vbCrLf
objMessage.TextBody = objMessage.TextBody & "1 = Successful copy" & vbCrLf
objMessage.TextBody = objMessage.TextBody & "2 = Extra files, check log for details" & vbCrLf
objMessage.TextBody = objMessage.TextBody & "3 = Everything Copied Correctly but Extra files were on the Destination" & vbCrLf
objMessage.TextBody = objMessage.TextBody & "4 = Mismatch files or directories, check log for errors" & vbCrLf
objMessage.TextBody = objMessage.TextBody & "8 = Some files or directories could not be copied" & vbCrLf
objMessage.TextBody = objMessage.TextBody & "16 = Serious Error - Action Required" & vbCrLf
objMessage.TextBody = objMessage.TextBody & "Most of the time error 16 means that the computer was not accessible." & vbCrLf
objMessage.TextBody = objMessage.TextBody & "This needs to be verified that the PC on. Reboot if needed." & vbCrLf
objMessage.TextBody = objMessage.TextBody & "If this does not correct the issue then open a helpdesk" & vbCrLf
objMessage.TextBody = objMessage.TextBody & "Category: IT Use Only Subcategory: ComVault Item: Backup" & vbCrLf
objMessage.TextBody = objMessage.TextBody & "and list in the ticket the information then it will be looked into further" & vbCrLf
objMessage.Addattachment WScript.Arguments.Item(2)

'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "10.1.###.###"


'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 2

'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "domain\username"

'Your password on the SMTP server
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

'Server port (typically 25)
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 

'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60


objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send
 

This has been a thing of beauty for the last couple of years and has been serving me very well until trying to get it to work on server 2008. Can anyone see anything I am missing?

Thank you 

Virgil :}{:


  • Edited by TA-ITAdmin Friday, December 05, 2014 5:36 PM
December 5th, 2014 5:33pm

Can anyone see anything I am missing?

No, I cannot see it either but I would add some self-documenting debugging code in order to find out where the problem lies. This would consist of two items:

  • Capture the screen output by invoking your script like so:
    cscript.exe c:\scripts\myscript.vbs 1>> c:\scripts\myscript.log 2>>&1
  • Create a logging subroutine of the following form:
    sub Log(sMsg)
       (code to write sMsg to a text file)
    end sub
    Invoke this subroutine from strategic places in your script so that you know where exactly it gets off the rails.
Free Windows Admin Tool Kit Click here and download it now
December 5th, 2014 5:56pm

I bet this is a case where the mail server sees too many messages coming to fast and blocks them as spam.  To test this place a sleep between each message send.  Sleep for abut a minute to let the spam detector reset.  If that works then have smtp server admin set the source IP as a trusted source and the spam kicker won't kick.

One other thing that can happen on a faster server is that the batch finishes before the scripts finish and when it exits the script process will get terminated before the mail is sent.

Look in event log for signs of aborted processes.

Fred's idea about tracing is also very good and will leave you with a built in debug facility for future use.

December 5th, 2014 8:02pm

Is the task set to run with administrative rights?

2008 + architecture has proven finicky with task scheduler and administrative privileges.

Free Windows Admin Tool Kit Click here and download it now
December 5th, 2014 8:11pm

Yes - here is your problem I am sure:

Start C:\Source\Scripts\Instruments\INSBU.cmd PC395 CHEM32 Denver
Start C:\Source\Scripts\Instruments\INSBU.cmd PC342 HPCHEM Denver
Start C:\Source\Scripts\Instruments\INSBU.cmd PC306 CHEM32 Denver

These all run async to the task.  When the task is terminated they will be terminates.  When the calling batch ends all children will be terminated.

When you run under a login you do not see the tasks that have been spawned quitting because the se3ssion is not killed when the batch finishes as it is under the scheduler.

Converting this to PowerShell will simplify this and allow you to run the child tasks as jobs then wait on the job completion. It can be done in about 12 or 15 lines I think.

The VBS becomes one line under PosH.  Spawning the tasks become a three or four line loop.

# spawn all jobs in loop
# Get-Job | Wait-Job
# exit.

The jobs can still be the batch file multiple times.

$joblist=@(
    PC395 CHEM32 Denver
    PC492 HPCHEM Denver
    PC306 CHEM32 Denver
}

$sb={
C:\Source\Scripts\Instruments\INSBU.cmd $args[0]
Send-MailMessage -Body <whatever> -To $args[1] -From $args[2] ... etc
} $joblist | %{Start-Job -ScriptBlock $sb -args @($_,'tomail','frommail',,,) } Get-Job | Wait-Job #done

That is actually pretty much it.  Of course I didn't do a total analysis or timing but it would definitely end up as a much more simple script and be much easier to manage.

December 5th, 2014 8:16pm

Actually I would dump all of the batch files.  All of that formatting and report building can be done very easily in PowerShell and will be much easier to use.

In any case good luck trying to fix this.  I hope it is an easy fix.

Free Windows Admin Tool Kit Click here and download it now
December 5th, 2014 8:20pm

So at long last I have solved this problem. It was with the first script:

Title Lab Backup
@echo off
REM This script is to start the backup process. 
REM It need to have the path to the backup script the instrument name and the share name
rem Source      Inst   Share     Lab

Start C:\Source\Scripts\Instruments\INSBU.cmd PC395 CHEM32 Denver
Start C:\Source\Scripts\Instruments\INSBU.cmd PC342 HPCHEM Denver
Start C:\Source\Scripts\Instruments\INSBU.cmd PC306 CHEM32 Denver

Generally have 10 to 15 Starts here

When working on an unrelated but related issue I added a /WAIT switch in the script and decided to do the same to this one so that is now reads

Start /WAIT .....

That makes each line run and wait until the process that is started completes before going on. What I figure was happening was the server saw too many email requests coming at once and therefore stopped allowing them out and as a result the process hung  and would go no further.

With the wait switch in place that no longer happens.

The PowerSheel solution is coming I am working on learning how to work with it and continue to improve my process. Thanks for all the replies.

April 29th, 2015 4:11pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics