Please enable JavaScript to view this site.

SQL Backup Master Help

Navigation: Backups > Backup Job Editor > Backup Job settings

Batch scripts

Scroll Prev Top Next More

SQL Backup Master offers the ability to execute a custom batch (.bat) or PowerShell (.ps1) script before and/or after the associated backup job is executed.

 

Error and informational messages that occur during custom batch script execution are written to the SQL Backup Master log. Such errors will not halt the progress of the backup job.

 

Script Variables

 

SQL Backup Master makes backup job state information available to your batch script at run time by setting environmental variables for the script process.

 

The following environmental variables are defined:

 

SQL_BACKUP_MASTER_TYPE -  "Full", "Diff" or "Log"

SQL_BACKUP_MASTER_STAGE - "BeforeBackup" or "AfterBackup"

SQL_BACKUP_MASTER_STATUS - "Finished", "FinishedWithErrors", "Cancelled" or "Failed"

 

Custom Script Example

 

Here's a  simple custom batch (.bat) script example:

 

@ECHO OFF

ECHO %SQL_BACKUP_MASTER_TYPE%

ECHO %SQL_BACKUP_MASTER_STAGE%

ECHO %SQL_BACKUP_MASTER_STATUS%

 

Or the equivalent PowerShell (.ps1) script:

 

echo $Env:SQL_BACKUP_MASTER_TYPE

echo $Env:SQL_BACKUP_MASTER_STAGE

echo $Env:SQL_BACKUP_MASTER_STATUS

 

Note that the SQL_BACKUP_MASTER_STATUS environmental variable will only be available if the SQL_BACKUP_MASTER_STAGE variable is "AfterBackup".

 

Error Handling

 

If your custom batch script produces an error or returns an exit code other than zero (0), an error will be logged by SQL Backup Master and will be reflected in the final backup job state. Such errors will not halt the overall backup job.

 

If your batch script needs to return an error state, it should use the EXIT statement with a code other than zero (0).

 

If your batch script outputs messages, they will be logged as informational messages in the SQL Backup Master log.