Skip to main content
SnapCenter Plug-in for VMware vSphere 6.0

Prescripts and postscripts

Contributors netapp-madhulik

You can use custom prescripts and postscripts as part of your data protection operations. These scripts enable automation either before your data protection job or after. For example, you might include a script that automatically notifies you of data protection job failures or warnings. Before you set up your prescripts and postscripts, you should understand some of the requirements for creating these scripts.

Supported script types

Perl and shell scripts are supported.
Shell scripts must start with !/bin/bash. (!/bin/sh is not supported.)

Script path location

Prescripts and postscripts are run by the SnapCenter Plug-in for VMware vSphere. Therefore, the scripts must be located in the SnapCenter Plug-in for VMware vSphere OVA, with executable permissions.

For example:
* A PERL script path might be /support/support/script.pl
* A shell script path might be /support/support/script.sh

The script path is validated at the time the script is executed.

Where to specify scripts

Scripts are specified in backup policies. When a backup job is started, the policy automatically associates the script with the resources being backed up.

To specify multiple scripts, press Enter after each script path to list each script on a separate line. Semicolons (;) are not allowed. You can specify multiple prescripts and multiple postscripts. A single script can be coded as both a prescript and a postscript and can call other scripts.

When scripts are executed

Scripts are executed according to the value set for BACKUP_PHASE.

  • BACKUP_PHASE=PRE_BACKUP

    Prescripts are executed in the PRE_BACKUP phase of the operation.

Note If a prescript fails, the backup completes successfully, and a warning message is sent.
  • BACKUP_PHASE=POST_BACKUP or BACKUP_PHASE=FAILED_BACKUP

    Postscripts are executed in the POST_BACKUP phase of the operation after the backup completes successfully or in the FAILED_BACKUP phase if the backup does not complete successfully.

Note If a postscript fails, the backup completes successfully, and a warning message is sent.

Check the following to verify that the script values are populated:
* For PERL scripts: /support/support/log_env.log
* For shell scripts: /support/support/log_file.log

Environment variables passed to scripts

You can use the environment variables shown in the following table in scripts.

Environment variable Description

BACKUP_NAME

Name of the backup.
Variable passed in postscripts only.

BACKUP_DATE

Date of the backup, in the format yyyymmdd
Variable passed in postscripts only.

BACKUP_TIME

Time of the backup, in the format hhmmss
Variable passed in postscripts only.

BACKUP_PHASE

The phase of the backup in which you want the script to run.
Valid values are: PRE_BACKUP, POST_BACKUP, and FAILED_BACKUP.
Variable passed in prescripts and postscripts.

STORAGE_SNAPSHOTS

The number of storage snapshots in the backup.
Variable passed in postscripts only.

STORAGE_SNAPSHOT.#

One of the defined storage snapshots, in the following format:
<filer>:/vol/<volume>:<ONTAP-snapshot-name>
Variable passed in postscripts only.

VIRTUAL_MACHINES

The number of VMs in the backup.
Variable passed in prescripts and postscripts.

VIRTUAL_MACHINE.#

One of the defined virtual machines, in the following format:
<VM name>[vertical bar]<VM UUID>[vertical bar]<power-state>[vertical bar]<VM snapshot>[vertical bar]<ip-addresses>
<power-state> has the values POWERED_ON, POWERED_OFF, or
SUSPENDED

<VM snapshot> has the values true or false
Variable passed in prescripts and postscripts.

Script timeouts

The timeout for backup scripts is 15 minutes and cannot be modified.

Example PERL script #1

The following example PERL script prints the environmental variables when a backup is run.

#!/usr/bin/perl
use warnings;
use strict;
my $argnum;
my $logfile = '/support/support/log_env.log';
open (FH, '>>', $logfile) or die $!;
foreach (sort keys %ENV) {
print FH "$_ = $ENV{$_}\n";
}
print FH "=========\n";
close (FH);

Example PERL script #2

The following example prints information about the backup.

#!/usr/bin/perl
use warnings;
use strict;

my $argnum;
my $logfile = '/support/support/log_env.log';
open (FH, '>>', $logfile) or die $!;

print FH "BACKUP_PHASE is $ENV{'BACKUP_PHASE'}\n";
print FH "Backup name $ENV{'BACKUP_NAME'}\n";
print FH "Virtual Machine $ENV{'VIRTUAL_MACHINES'}\n";
print FH "VIRTUAL_MACHINE # is $ENV{'VIRTUAL_MACHINE.1'}\n";
print FH "BACKUP_DATE is $ENV{'BACKUP_DATE'}\n";
print FH "BACKUP_TIME is $ENV{'BACKUP_TIME'}\n";
print FH "STORAGE_SNAPSHOTS is $ENV{'STORAGE_SNAPSHOTS'}\n";
print FH "STORAGE_SNAPSHOT # is $ENV{'STORAGE_SNAPSHOT.1'}\n";

print FH "PWD is $ENV{'PWD'}\n";
print FH "INVOCATION_ID is $ENV{'INVOCATION_ID'}\n";

print FH "=========\n";
close (FH);

Example shell script

===============================================
#!/bin/bash
echo Stage $BACKUP_NAME >> /support/support/log_file.log
env >> /support/support/log_file.log
===============================================