Creating pretask, post-task, and policy scripts

Contributors akseldavis Download PDF of this page

SnapManager enables you to create the scripts for the preprocessing activity, the post-processing activity, and policy tasks of the backup, restore, and clone operations. You must place the scripts in the correct installation directory to execute the preprocessing activity, post-processing activity, and policy tasks of the SnapManager operation.

Pretask and post-task script content

All scripts must include the following:

  • Specific operations (check, describe, and execute)

  • (Optional) Predefined environment variables

  • Specific error handling code (return code (rc))

You must include correct error handling code to validate the script.

You can use the pretask scripts for many purposes, for example, cleaning up a disk space before the SnapManager operation starts. You can also use the post-task scripts, for instance, to estimate whether SnapManager has enough disk space to complete the operation.

Policy task script content

You can execute the policy script without using specific operations such as check, describe, and execute. The script includes the predefined environmental variables (optional) and specific error handling code.

The policy script is executed before the backup, restore, and clone operations.

Supported format

A shell script file with a .sh extension can be used as the prescript and post-script.

Script installation directory

The directory in which you install the script affects how it is used. You can place the scripts in the directory and execute the script before or after the backup, restore, or clone operation takes place. You must place the script in the directory specified in the table and use it on an optional basis when you specify the backup, restore, or clone operation.

You must ensure that the plugins directory has the executable permission before using the scripts for the SnapManager operation.
Activity Backup Restore Clone






<default_installation_directory>/ plugins/backup/create/post







Sample scripts locations

The following are some samples of the pretask and post-task scripts for the backup and clone operations available in the installation directory path:

  • <default_installation_directory>/plugins/examples/backup/create/pre

  • <default_installation_directory>/plugins/examples/backup/create/post

  • <default_installation_directory>/plugins/examples/clone/create/pre

  • <default_installation_directory>/plugins/examples/clone/create/post

What you can change in the script

If you are creating a new script, you can change only the describe and execute operations. Each script must contain the following variables: context, timeout, and parameter.

The variables you have described in the describe function of the script must be declared at the start of the script. You can add new parameter values in parameter=() and then use the parameters in the execute function.

Sample script

The following is a sample script with a user-specified return code for estimating the space in the SnapManager host:

    # $Id: //depot/prod/capstan/main/src/plugins/unix/examples/backup/create/pre/ $
    name="disk space estimation ($(basename $0))"
    description="pre tasks for estimating the space on the target system"
    PRESERVE_DIR="/tmp/preserve/$(date +%Y%m%d%H%M%S)"
    function _exit {
       echo "Command complete."
       exit $rc
    function usage {
       echo "usage: $(basename $0) { -check | -describe | -execute }"
       _exit 99
    function describe {
       echo "SM_PI_NAME:$name"
       echo "SM_PI_DESCRIPTION:$description"
       echo "SM_PI_CONTEXT:$context"
       echo "SM_PI_TIMEOUT:$timeout"
       for entry in ${parameter[@]}; do
           echo "SM_PI_PARAMETER:$entry"
       _exit 0
    function check {
       _exit 0
    function execute {
       echo "estimating the space on the target system"
       # Shell script to monitor or watch the disk space
       # It will display alert message, if the (free available) percentage
       # of space is >= 90%
       # ----------------------------------------------------------------------
       # Linux shell script to watch disk space (should work on other UNIX oses )
       # set alert level 90% is default
       df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
         #echo $output
         usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
         partition=$(echo $output | awk '{ print $2 }' )
       if [ $usep -ge $ALERT ]; then
           echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
      _exit 0
    function preserve {
        [ $# -ne 2 ] && return 1
        save=$(echo ${2:0:1} | tr [a-z] [A-Z])
        [ "$save" == "Y" ] || return 0
        if [ ! -d "$PRESERVE_DIR" ] ; then
           mkdir -p "$PRESERVE_DIR"
           if [ $? -ne 0 ] ; then
               echo "could not create directory [$PRESERVE_DIR]"
               return 1
        if [ -e "$file" ] ; then
            mv "$file" "$PRESERVE_DIR/."
        return $?
    case $(echo $1 | tr [A-Z] [a-z]) in
        -check)    check
        -execute)  execute
        -describe) describe
     *)         echo "unknown option $1"