Skip to main content
SnapManager for SAP

Create pretask, post-task, and policy scripts

Contributors

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.

About this task

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))

Note 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.

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

Preprocessing

<default_installation_directory>/plugins/backup/create/pre

<default_installation_directory>/plugins/restore/create/pre

<default_installation_directory>/plugins/clone/create/pre

Post-processing

<default_installation_directory>/ plugins/backup/create/post

<default_installation_directory>/plugins/restore/create/post

<default_installation_directory>/plugins/clone/create/post

Policy-based

<default_installation_directory>/plugins/backup/create/policy

<default_installation_directory>/plugins/restore/create/policy

<default_installation_directory>/plugins/clone/create/policy

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:

    #!/bin/bash
    # $Id: //depot/prod/capstan/main/src/plugins/unix/examples/backup/create/pre/disk_space_estimate.sh#5 $
    name="disk space estimation ($(basename $0))"
    description="pre tasks for estimating the space on the target system"
    context=
    timeout="0"
    parameter=()
    EXIT=0
    PRESERVE_DIR="/tmp/preserve/$(date +%Y%m%d%H%M%S)"
    function _exit {
       rc=$1
       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"
       IFS=^
       for entry in ${parameter[@]}; do
           echo "SM_PI_PARAMETER:$entry"
       done
       _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
       ALERT=90
       df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
       do
         #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)" |
       fi
       done
      _exit 0
     }
    function preserve {
        [ $# -ne 2 ] && return 1
        file=$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
           fi
        fi
        if [ -e "$file" ] ; then
            mv "$file" "$PRESERVE_DIR/."
        fi
        return $?
    }
    case $(echo $1 | tr [A-Z] [a-z]) in
        -check)    check
                  ;;
        -execute)  execute
                  ;;
        -describe) describe
                  ;;
     *)         echo "unknown option $1"
              usage
              ;;
     esac