Recently the technical support team has received questions about how BackupAssist handles manually entered scripts. In one such case, a user’s Robocopy script was causing a warning to appear in the backup report, even though the script was completing successfully. To explain why this warning appeared, and to answer other scripting-related questions, we’d like to outline how scripting works in BackupAssist, as well as show you how you can resolve the issue with Robocopy and other similar scripting commands.
Each script entered in the ‘Scripts’ tab of a BackupAssist job runs as a separate batch file. The “Run before each backup” script runs as one batch file, the “Run after each successful backup” runs as another batch file, and so on.
BackupAssist determines the success of each script individually, in the same way that Windows (DOS) does: the exit code of each batch file executed is the exit code of the last command in the script that modifies the exit code. While some commands, like echo, do not modify the exit code, the majority use ‘zero’ for success and a non-zero value for failure.
If BackupAssist detects a non-zero exit code from a script, the reporting option selected for the script will determine whether a warning or error appears in the backup report. In the job below, the script is set to add a minor warning to the report if the script fails:
If the above script returns an exit code of -1 (or anything except ‘zero’) when executed, a minor warning will appear in the report, similar to the following:
This is the default behavior for any script entered, but can be modified by changing the reporting option from “Minor warning” to one of the other available settings:
Now that we’ve explained how scripting works in BackupAssist and how the success or failure of a script is determined, we can discuss the Robocopy case mentioned. In this scenario, a user noted that a warning appeared in their backup report for a Robocopy script even though the script completed successfully.
The reason for this is that Robocopy does not use a ‘zero’ value to indicate success. Robocopy instead uses ‘zero’ to indicate two things: 1) that there were no errors AND 2) that nothing was copied. Non-zero return values from Robocopy can have many different meanings, including that the script completed successfully. For example, an exit code of ‘1’ indicates that files were copied successfully. You can visit http://support.microsoft.com/kb/954404 (Microsoft website) or http://ss64.com/nt/robocopy-exit.html (3rd party website) to learn more about Robocopy return values.
To handle Robocopy commands in BackupAssist you need to first decide whether the Robocopy operation is a critical part of the backup. If it is, you should change the reporting option to report an “Error” instead of a “Minor warning” if BackupAssist detects that the script failed (i.e. the exit code was a non-zero value). You can then modify your script to have BackupAssist report the Robocopy exit code so that you can identify real errors by checking for an exit code of 8 or higher.
You can then make sure that when the script runs successfully (i.e. the exit code returned is less than 8 ) BackupAssist receives an exit code of zero. This will mean that no script warning or error will appear in the report unless the error code returned is 8 or higher. An example script to achieve this is as follows:
echo robocopy %errorlevel%
if errorlevel 8 exit
We hope this information helps clarify how scripting works in BackupAssist, as well as how you can modify your job to handle different scripting programs. If you have any questions please email us at firstname.lastname@example.org