#!/bin/sh

#bcpyrght
#***************************************************************************
# $Copyright: Copyright (c) 2022 Veritas Technologies LLC. All rights reserved $
#***************************************************************************
#ecpyrght

#
#NOTE:IF your SAP user (in this script orasap) runs in C shell, environmental 
#variables can not be exported. In that case, you should modify this script to 
#work in your environment. For example:
#   SAP_SERVER=$SAP_SERVER; export SAP_SERVER; (Correct for Bourne and Korn shells)
#   can change into
#   setenv SAP_SERVER $SAP_SERVER; (Correct for C shell)
#

#
#These environment variables are created by NetBackup (bphdb)
#

echo "SAP_SCHEDULED = $SAP_SCHEDULED"
echo "SAP_USER_INITIATED = $SAP_USER_INITIATED"
echo "SAP_SERVER = $SAP_SERVER"
echo "SAP_POLICY = $SAP_POLICY"
echo "SAP_FULL = $SAP_FULL"
echo "SAP_CINC = $SAP_CINC"
echo "SAP_SCHED = $SAP_SCHED"

RETURN_STATUS=0

SET_ENV=""

#
# If SAP_SERVER exists then export it to make it available to backint 
#
if [ -n "$SAP_SERVER" ]
then
        SAP_ENV="$SAP_ENV SAP_SERVER=$SAP_SERVER; export SAP_SERVER;"
#If Oracel DBA account( orasap  user) uses C Shell, comment the above line and uncomment the next line
#       SAP_ENV="$SAP_ENV setenv SAP_SERVER $SAP_SERVER;"

fi

#
# If SAP_POLICY exists then export it to make it available to backint 
#
if [ -n "$SAP_POLICY" ]
then
        SAP_ENV="$SAP_ENV SAP_POLICY=$SAP_POLICY; export SAP_POLICY;"
#If Oracel DBA account( orasap  user) uses C Shell, comment the above line and uncomment the next line
#       SAP_ENV="$SAP_ENV setenv SAP_POLICY $SAP_POLICY;"
fi

#
# If SAP_SCHED exists then export it to make it available to backint.
#
if [ -n "$SAP_SCHED" ]
then
        SAP_ENV="$SAP_ENV SAP_SCHED=$SAP_SCHED; export SAP_SCHED;"
#if Oracle DBA account(orasap user) uses C Shell, comment the above line and uncomment the next line
#       SAP_ENV="$SAP_ENV setenv SAP_SCHED $SAP_SCHED;"
fi

if [ $SAP_FULL -eq 1 ]; then
	CMD_LINE="$SAP_ENV brbackup -d rman_util -t offline -m full -c"
elif [ $SAP_CINC -eq 1 ]; then
	CMD_LINE="$SAP_ENV brbackup -d rman_util -t offline -m incr -c"
fi

#
# The username on the "su" command needs to be replaced with the correct 
# user name.
# 
echo "Execute $CMD_LINE"
su - orasap -c "$CMD_LINE"

RETURN_STATUS=$?

exit $RETURN_STATUS
