When you start a SnapManager backup, database verification, restore, or clone operation, you have the option to automatically run a command (a user executable program or script) either before the operation starts or after the operation is complete. You can also choose how script errors are handled.
You can set up commands or scripts to run before SnapManager operations in the following ways:
From within the context of a SnapManager backup, verification, restore, or clone operation, you can use the Run Commands dialog box to do the following:
When you choose to run a script before an operation from a wizard or quick dialog box, you are prompted to specify the following information before the operation begins:
Because the command (your own program or script) is invoked from within the context of a SnapManager operation, you can pass the command information about the components of that operation. For example, if the pre- or post-command is a batch file that is launched, it will look like c:\bat\mytestCommand.bat $SqlSnapshot $Database. In this example, inside the batch file, the %1 batch parameter corresponds to the first parameter $SqlSnapshot passed to the batch script; the %2 string will corresponds to the second $Database parameter passed, and so on, because it is running in the context of the SMSQL operation.
To run a script from a wizard or a Quick dialog box, see one of the following procedures:
You can use the Run Commands dialog box to configure default values that you want used to prepopulate the Run Commands dialog box when it is opened from either the Backup, Verify, Clone, or Restore wizards and options.
To run a script from the Run Commands dialog box, complete the following steps.
Step | Action | |
---|---|---|
1 | From the Actions menu, click the Run Commands option. Result SnapManager displays the Run Commands dialog box with the current default settings. |
|
2 | Select the list box item value for the operation (for example, backup, verify, restore, or clone) where you want these default Run Commands settings to apply. |
|
3 | Make sure that the Pre-Operation Command tab is selected. |
|
4 | Choose whether to stop the pre-command operation if an error occurs. |
|
If... | Then .. | |
You want the SnapManager for SQL Server operation to stop when an error occurs in the custom user command | Select the check box labeled, "Treat pre command errors as fatal by stopping the remaining SnapManager operation..." |
|
You want to ignore errors that occurred during the user command or script, and want to continue to run the SnapManager for SQL Server operation regardless of those script errors | Do not select the check box labeled "Treat pre command errors as fatal by stopping the remaining SnapManager operation..." | |
5 | In the "Specify a computer where..." box, enter or browse to the name of the host on which your program or script resides. |
|
6 | In the "Specify the full path..." box, browse to your program or script. |
|
7 | Form the command input string in the Command Arguments box. You can do this using any combination of the following methods:
Note: Several
parameters like $SnapInfoPath and $LogBackupFile variables
are enclosed within double quotes by default, so that the actual
path name can contain spaces without affecting the script invocation
on the Windows command line. If you do not want the double quotes
to appear in your command line, remove them from the Command Arguments
field in the Run Commands dialog box.
|
|
8 | Repeat step 4 as needed until the Command Arguments box contains the arguments you want to pass to your program or script. |
|
9 | Click OK to apply your changes and close the Run Commands dialog box. Your changes are saved as the default. |
SnapManager provides the ability to run scripts after database backup, verify, restore, or clone operations. SnapManager also enables you to choose how operation errors are handled. You can choose to stop the SnapManager for SQL Server operation if an error occurs during the script launch.
You can set up commands or scripts to run after SnapManager operations in the following ways:
From within the context of a SnapManager backup, verification, restore, or clone operation, you can use the Run Commands dialog box to do the following:
To run a script from a wizard or a Quick dialog box, see one of the following procedures:
When you choose to run a script after an operation from a wizard or quick dialog box, you are prompted to specify the following information before the operation begins:
Because the command (your own program or script) is invoked from within the context of a specific backup or database verification, you can pass the command information about the components of that operation. For example, if you run the following batch file script after the operation, following c:\myPostCmd.bat $Database $SqlInstance, the first parameter passed, $Database, corresponds to the %1 batch parameter, and the second parameter, $SqlInstance, corresponds to the batch %2 parameter.
After you have completed specifying the command and parameters, you can start the operation.
You can use the Run Commands dialog box to configure default values that you want used to prepopulate the Run Commands dialog box when it is opened from either the Backup, Verify, Clone, or Restore wizards and options.
To specify the default command or script information to be run after a backup, verify, clone or restore wizard operation, complete the following steps:
Step | Action | |
---|---|---|
1 | From the Actions menu, click the Run Commands option. Result SnapManager displays the Run Commands dialog box with the current default settings. |
|
2 | Select the list box item value for the SnapManager or SQL Server operation where you want these default run command settings to apply. |
|
3 | Make sure that the Post Operation Command tab is selected. |
|
4 | Choose whether to stop the post-command operation if an error occurs. |
|
If... | Then... | |
You want the SnapManager for SQL Server operation (for example, backup, verify, restore, or clone) to stop when an error occurs in the custom user command | Select the check box labeled, "Treat pre command errors as fatal by stopping the remaining SnapManager operation..." |
|
You want to ignore errors that occurred during the user command or script, and want to continue to run the SnapManager for SQL Server operation regardless of those script errors | Do not select the check box labeled "Treat pre command errors as fatal by stopping the remaining SnapManager operation..." | |
5 | In the "Specify a computer where..." box, enter or browse to the name of the host on which your program or script resides. |
|
6 | In the "Specify the full path..." box, browse to your program or script. |
|
7 | Form the command input string in the Command Arguments box. You can do this using any combination of the following methods:
Note: Several
parameters like $SnapInfoPath and $LogBackupFile variables
are enclosed within double quotes by default, so that the actual
path name can contain spaces without affecting the script invocation
on the Windows command line. If you do not want the double quotes
to appear in your command line, remove them from the Command Arguments
field in the Run Command Operation dialog box.
|
|
8 | Repeat step 6 as needed until the Command Arguments box contains the arguments you want to pass to your program or script. |
|
9 | Click Save to save your changes as the default run commands settings for the operation selected, then close the Run Command dialog box. Repeat Steps 2 through 7 to set up the default for each operation type. Your changes are saved as the default. |
The following pre-command arguments apply to backup, verify, restore, and clone operations.
Variable | Description | |
---|---|---|
$Database |
Specifies the logical name of the database processes. Note: To
prevent PowerShell from interpreting the value of this parameter,
be sure to enclose the entire parameter value with single quotes.
For example:
-PreCmdArg '$Database $ServerInstance'
Example: DatabaseAccounting If you want to have more than one database expanded, repeat the parameter as many times as you want. Example: AccountingDB1 AcmeServer1/SqlInst1 FinanceDB2 AcmeServer1/SqlInst2 |
|
$ServerInstance |
Specifies the name of the SQL server instance that is actually processed. Example: ACMESERVER1\SQLINSTANCE1 |
The following post-command arguments apply to backup, verify, restore, and clone operations.
Variable | Description | |
---|---|---|
$InfoSnapshot |
Expands to the name of a SnapInfo directory Snapshot copy. Examples: sqlinfo__winsrvr2__01-31-2005_15.03.09 sqlinfo__winsrvr2__recent |
|
$LogBackupFile |
Expands to the full path name of the transaction log backup file. Example: I:\SMSQL_SnapInfo\SQL__WINSRVR2\DB__Northwind\LogBackup\ 11-01-2004_13.34.59__Northwind.TRB |
|
$OperationStatus |
Provides the status of the SMSQL operation. Example: 5234 |
|
$PreCommandStatus |
Provides the pre-command status to the post-command if the post-command is executed based on the status of the earlier pre-command. Example: 5234 |
|
$SnapInfoName |
Expands to the name of the SnapInfo directory. Examples: WINSRVR2__recent WINSRVR2_11-23-2004_16.21.07__Daily
Note: If you use this variable, you must also provide the correct
path to the directory.
|
|
$SnapInfoPath |
Expands to the name of the SnapInfo subdirectory. This argument is used in backup and verification operations. Example: I:\SMSQL_SnapInfo\SQL__WINSRVR2\DB__NorthwindFor restore and clone operations, this argument specifies the path to the Snapshot copy information metadata that is being used for the database restore. Example: U:\SMSQL_SnapInfo\VDISK__E\FG__\05-14-2010_15.33.41\SnapInfo__05-14-2010_15.33.41.sml |
|
$SqlSnapshot |
Expands to the name of an SQL Server database Snapshot copy. This argument is used for backup and verification operations. Examples: sqlsnap__winsrvr2__01-31-2005_15.03.09 sqlsnap__winsrvr2__recent Note: The number of database Snapshot copies in a SnapManager
backup set depends on the number of volumes used to store the databases
included in the backup.
For restore and clone operations, this argument specifies the name of the Snapshot copy to be restored. Example: sqlsnap__winsrvr2__01-31-2005_15.03.09 sqlsnap__winsrvr2__recent |
The following post-command arguments apply only to restore and clone operations.
Variable | Description | |
---|---|---|
$StandbyFile |
This is the full file system path of the SQL standby file used on a restore. This file path is calculated during the restore-clone operation as a temporary file when incomplete transactions are removed from the database and stored in the file for later use. The user requests to generate a standby (or undo) file in a certain directory, but the full file name path actually used is not known until the restore or clone operation is launched. This happens when several databases are restored at the same time to the same LUNs. By default, this is created in the snap-info directory. Example: U:\SMSQL_SnapInfo\VDISK__E\UNDO_SECLOCSYS_db5.dat |
|
$TargetDatabase |
Specifies the destination name of the database to restore. Example: DatabaseAccountingRestoredCopy |
|
$TargetServerInstance |
Specifies the destination SQL Server instance to be used. Example: ACMESERVER2\SQLINSTANCECOPY |
|
$TargetDatabaseFile |
Specifies the target file system database path to be used. Example: Z:\MNT\NETAPP1\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\DatabaseAccounting.mdf |
Each SnapManager operation that supports the Run Commands feature parses only the variables that apply to the operation as you have specified it.
The following table shows which of the command variables are available to the Run Commands feature, depending on which SnapManager operation is used to invoke the feature.
Variable | SnapManager operation that is used to invoke the Run Commands feature |
||||
---|---|---|---|---|---|
Full backup | Transaction log backup | Verification of full backup | Restore | Clone | |
$Database |
Parsed | Parsed | Parsed | Parsed | Parsed |
$InfoSnapshot |
Parsed | Parsed | — | — | — |
$LogBackupFile |
Parsed | Parsed | — | — | — |
$ServerInstance |
Parsed | Parsed | Parsed | Parsed | Parsed |
$OperationStatus |
Parsed | Parsed | Parsed | Parsed | Parsed |
$PreCommandStatus |
Parsed | Parsed | Parsed | Parsed | Parsed |
$SnapInfoName |
Parsed | Parsed | Parsed | — | — |
$SnapInfoPath |
Parsed | Parsed | Parsed | — | — |
$SqlSnapshot |
Parsed | — | Parsed | Parsed | Parsed |
$StandbyFile |
— | — | — | Parsed | Parsed |
$TargetDatabase |
— | — | — | Parsed | Parsed |
$TargetDatabaseFile |
— | — | — | Parsed | Parsed |
$TargetServerInstance |
— | — | — | Parsed | Parsed |