Forum Discussion

nbustarter380's avatar
9 years ago

Pre/Post script commands for backup

Hello,

 

Pre/Post script commands for Solaris backup

 

We need to freeze the “Data Store” on a backup via a pre-script command

  

How would this work?

 

the application “Data Store” needs to be placed in a read-only mode prior to any backups being taken, known as a freeze.

 

To unfreeze (immediately) the Data Store once backup is done -

 

Would it be possible to do this using the policy settings or we have to insert into a directory?

 

Any Help, comments or Ideas are appreciated

 

 

Solaris client

NBU Client Level 7.6.0.3

 

Thanks

 

12 Replies

  • If this "data store" application is on the same host/server/client as the backup client software - i.e. if the backup job is backing up what appears to be local file-systems/mount-points (i.e. NOT backing up NFS or SMB network paths) then you should not need to use an "ssh" construct, and instead you should be able to get away with using "su -c command username" in your bpstart_notify and bpend_notify scripts, to call the commands to freeze and unfreeze the "data store" application.

    Below is a script that you should be able to modify and drop in the commands that you need.

    A word of advice... please take the time to read it carefully and slowly.  It's not that difficult to work out what is going on, but you will save yourself a lot headache and time, if you first spend a few minutes absorbing the script.

    Take a look in the "log" function, you can uncomment a line there when you test it... BUT... don't forget to comment it out again when you put the code live.

    .

    N.B:  I have tried to make a script which can be used as either or both of bpstart_notify and/or bpend_notify - i.e. so that you only have one piece of code to modify, and thus only one piece of code to drop in as either of, or both of, bpstart_notify or bpend_notify.

    N.B:  If your NetBackup backup policy uses multi-streaming then this script is not suitable.

    N.B:  If your client exists in one than one policy then you will very likely need to use the ".POLICYNAME" construct on the file names of the bpstart_notify and bpend_notify scripts.

    N.B:  Test it first.

    N.B:  You will see that you will need to modify a few parts - e.g. the cat of redhat-release file, to instead cat the Solaris release file.  No doubt there will be a few other parts to tweak for Solaris.  Apologies, but I do not have a Solaris system to hand to test this on.  Maybe if you get really stuck, someone else on here will step in, take the code below and tweak it up for you for Solaris.

    Good luck.

    .

    Here's the script:

    #!/bin/bash
    
    #############################################################################################################
    #  File:     bpstart_notify[.POLICYNAME[.SCHEDULENAME]]
    #            bpend_notify[.POLICYNAME[.SCHEDULENAME]]
    #  Purpose:  bpstart_notify    is called by NetBackup Client at the start of a backup.
    #            bpend_notify      is called by NetBackup Client at the end   of a backup.
    #
    #  Vers    Date          Who    Description
    #  ----    ----          ---    -----------
    #  v0.01   14-Apr-2016   sdo    Initial draft.
    #  v0.02   16-APR-2016   sdo    Fix NBU version file.  Handle both start and end.
    #  v0.03   16-APR-2016   sdo    List contents of application script.  Show whoami.
    #  v0.04   16-APR-2016   sdo    bpstart_notify receives 4 parameters, bpend_notify receives 5 parameters.
    #  v0.05   19-APR-2016   sdo    Call the application script as user "appadmin".
    #  v0.06   20-APR-2016   sdo    Added steps to show application status before and after application call.
    #############################################################################################################
    SCRIPT_VERSION="v0.06"
    #############################################################################################################
    #  !!! WARNING and DISCLAIMER !!!
    #  !!! WARNING and DISCLAIMER !!!
    #  !!! WARNING and DISCLAIMER !!!
    #
    #  Before using this script, be aware of the following points:
    #  - Use of this script is entirely at the end user's own risk.
    #  - Neither the author of this script, nor Veritas, will accept any responsbility for issues or
    #    problems or data loss caused by use, or mis-use, of this script, in either its original form or
    #    a modified form.
    #  - This script is not endorsed by Veritas.
    #  - This script is not supported by Veritas.
    #  - This script has not been tested by Veritas.
    #  - This script may not be suitable for use in any given NetBackup environment.
    #  - This script is furnished on an example basis only.
    #  - Whilst every effort has been made, by the author of this script, to produce something that is
    #    useful and viable, bugs and errors may exist which may cause data loss.
    #############################################################################################################
    #  Notes
    #  -----
    #  1) Both bpstart_notify and bpend_notify must run silently and not generate any output at all on stdout nor
    #     on stderr.
    #  2) The Unix/Linux based bpstart_notify scripts do not return their result via "results" file, as the
    #     Windows versions do.  Instead "bpstart_notify" returns an "exist status".
    #  3) The scripts are called by NetBackup Client, and are waited for, up to to a certain client timeout
    #     value.
    #  4) With default NetBackup Client settings, then if either script takes more than five minutes (i.e. 300
    #     seconds) to complete, then the backup jobs will be considered as havng failed.
    #  5) It its current v0.06 form, this script does not handle multi-streaming.
    #############################################################################################################
    
    function abort {
      log "Script aborting..."
      if [ -z "$STS"  ] ; then STS=-1; fi
      if [ $STS -eq 0 ] ; then STS=-1; fi
      exit $STS
    }
    
    function log {
      LOGDT=`date "+%d/%m/%Y %H:%M:%S"`
    # Uncomment this next line during testing..."
    # echo "$LOGDT  $1"
      echo "$LOGDT  $1">>"$FILELOG"
    # sleep 0.1
    }
    
    #################################################################################
    #################################################################################
    
    SCRIPT_PATH="`dirname $0`"
    SCRIPT_PATH="`readlink -f ""$SCRIPT_PATH""`"
    SCRIPT_NAME="`basename $0`"
    SCRIPT_NAME="${SCRIPT_NAME%%.*}"
    
    FILELOG="$SCRIPT_PATH/$SCRIPT_NAME.log"
    FILETMP="$SCRIPT_PATH/$SCRIPT_NAME.tmp"
    
    #don't delete the log file, instead accumulate the log file...
    #if [ -e "$FILELOG" ] ; then rm "$FILELOG" ; fi
     if [ -e "$FILETMP" ] ; then rm "$FILETMP" ; fi
    
    ((STEP=0))
    
    #################################################################################
    #################################################################################
    
    ((STEP++))
    
    log ""
    log ""
    log "Step $STEP - show script details..."
    log "...script name:     $SCRIPT_NAME"
    log "...script path:     $SCRIPT_PATH"
    log "...script log:      $FILELOG"
    log "...script version:  $SCRIPT_VERSION"
    log "...done..."
    
    #################################################################################
    #################################################################################
    
    ((STEP++))
    
    log ""
    log "Step $STEP - show server details..."
    log "...OS kernel:     `uname -r`"
    log ".. OS date:       `uname -v`"
    log "...OS platform:   `uname -m -p -i -o`"
    log "...OS release:    `cat /etc/redhat-release`"
    log "...hostname:      $HOSTNAME"
    log "...process ID:    $$"
    log "...num params:    $#"
    log "...username:      `whoami`"
    log "...current path:  `pwd`"
    log "...done..."
    
    #################################################################################
    #################################################################################
    
    ((STEP++))
    
    log ""
    log "Step $STEP - show NetBackup details..."
    log "...NetBackup version:  `cat /usr/openv/netbackup/bin/version`"
    log ".. client name:        $1"
    log "...policy name:        $2"
    log "...schedule name:      $3"
    log "...schedule type:      $4"
    log "...parameter 5:        $5"
    log "...BACKUPID:           $BACKUPID"
    log "...BACKUPTIME:         $BACKUPTIME"
    log "...STREAM_NUMBER:      $STREAM_NUMBER"
    log "...STREAM_COUNT:       $STREAM_COUNT"
    log "...STREAM_PID:         $STREAM_PID"
    
    if [ "`echo $SCRIPT_NAME | cut -d "_" -f 1`" = "bpstart" ]
    then
      SCRIPT_MODE="bpstart"
    else
      if [ "`echo $SCRIPT_NAME | cut -d "_" -f 1`" = "bpend" ]
      then
        SCRIPT_MODE="bpend"
      else
        log "...unable to determine script mode from file name of NetBackup script name, script aboting..."
        abort
      fi
    fi
    
    if [ "$SCRIPT_MODE" = "bpstart" ]
    then
      if [ "$#" -ne 4 ]
      then
        log "...incorrect number of parameters '$#', expected '4', script aborting..."
        abort
      fi
    else
      if [ "$#" - ne 5 ]
      then
        log "...incorrect number of parameters '$#', expected '5', script aborting..."
        abort
      fi
    fi
    
    if [ "$SCRIPT_MODE" = "bpstart" ]
    then
      log "...RESTARTED:          $RESTARTED"
    else
      log "...FINISHED:           $FINISHED"
    fi
    
    log "...done..."
    
    #################################################################################
    #################################################################################
    
    ((STEP++))
    
    log ""
    log "Step $STEP - show current application status, before taking action..."
    
    #command-to-display-application-status >>"$FILELOG" 2>&1
    STSDSP=$?
    
    log "...return status from application show was '$STSDSP', script continuing..."
    
    log "...done..."
    
    #################################################################################
    #################################################################################
    
    ((STEP++))
    
    log ""
    log "Step $STEP - locate and call script to start/stop application..."
    
    if [ "$SCRIPT_MODE" = "bpstart" ]
    then
      APP_SCRIPT="/home/application/scripts/stop_APP.sh"
    else
      APP_SCRIPT="/home/application/scripts/start_APP.sh"
    fi
    
    log "...the application script file to call is named:  $APP_SCRIPT"
    
    if [ ! -e "$APP_SCRIPT" ]
    then
      log "...unable to locate application script file, script aborting..."
      abort
    fi
    
    log "...listing application script file..."
    ls -lash $APP_SCRIPT >>"$FILELOG" 2>&1
    
    log "...showing application script file contents..."
    cat $APP_SCRIPT >>"$FILELOG" 2>&1
    
    log "...calling application script..."
    su -c $APP_SCRIPT appadmin >>"$FILELOG" 2>&1
    STS=$?
    if [ $STS -ne 0 ]
    then
      if [ "$SCRIPT_MODE" = "bpstart" ]
      then
    # comment and uncomment the next one/two/three lines to change the behaviour of this script...
        log "...call to application script failed, status '$STS', script continuing..."
    #   log "...call to application script failed, status '$STS', script aborting..."
    #   abort
      else
        log "...call to application script failed, status '$STS', script aborting..."
        abort
      fi
    fi
    
    log "...done..."
    
    #################################################################################
    #################################################################################
    
    ((STEP++))
    
    log ""
    log "Step $STEP - show current application status, after taking action..."
    
    #command-to-show-application-status >>"$FILELOG" 2>&1
    STSDSP=$?
    
    log "...return status from application show was '$STSDSP', script continuing..."
    
    log "...done..."
    
    #################################################################################
    #################################################################################
    
    log ""
    log "Script exiting..."
    
    exit 0
  • Hi Sdo,

     

    Thank you very for that script I really appreciate you taking time to post it. I will read it over carefully as it is something I could not have come up with.

    Best Regards