#!/bin/sh
#***************************************************************************
# $Copyright: Copyright (c) 2022 Veritas Technologies LLC. All rights reserved $
#***************************************************************************
#
# ---------------------------------------------------------------------------
#                          data_archiver_import.sh
# ---------------------------------------------------------------------------
#  This script uses bporaimp to import Oracle table data that was previously
#  exported in XML format using the bporaexp utility.
#  It is assumed that this script will be executed
#  by user root. In order for the bporaimp utility to work properly we 
#  switch user (su -) to a user account that has the correct environment
#  for running a utility that accesses Oracle.
#  The operating system user account that was used to create the archive
#  must be used to perform the import.
#  If this script runs under this user account instead of as root
#  you should remove the switch user logic.
#
# ---------------------------------------------------------------------------
#
# ---------------------------------------------------------------------------
# Put output in <this file name>.out. Change as desired.
# Note: output directory requires write permission.
# ---------------------------------------------------------------------------

OUTF=${0}.out

# ---------------------------------------------------------------------------
# You may want to delete the output file so that backup information does
# not accumulate.  If not, delete the following lines.
# ---------------------------------------------------------------------------

if [ -f "$OUTF" ]
then
	rm -f "$OUTF"
fi

{ # output block

echo "`date` ----------------Beginning of Script------------"
echo "Script name: $0"

# ---------------------------------------------------------------------------
# Replace /db/oracle/product/ora102, below, with the Oracle home path.
# ---------------------------------------------------------------------------

ORACLE_HOME=/db/oracle/product/ora102
export ORACLE_HOME

# ---------------------------------------------------------------------------
# Replace ORA102, below, with the Oracle SID of the target database.
# ---------------------------------------------------------------------------

ORACLE_SID=ORA102
export ORACLE_SID

# ---------------------------------------------------------------------------
# Replace ora102, below, with the Oracle DBA user id (account).
# ---------------------------------------------------------------------------

ORACLE_USER=ora102

# ---------------------------------------------------------------------------
# Replace ${ORACLE_HOME}/scripts with the NetBackup Oracle script path.
# Since subsequent installs or deinstalls will remove this file, you will
# want to move this script from its installed location before making updates.
# ---------------------------------------------------------------------------

NB_ORA_SCRIPTS=${ORACLE_HOME}/scripts

# ---------------------------------------------------------------------------
# Replace ${NB_ORA_SCRIPTS}/bporaimp_tables.param with the location of the
# XML import parameter file.
# ---------------------------------------------------------------------------

NB_ORA_IMP_PARAMS=${NB_ORA_SCRIPTS}/bporaimp_tables.param

# ---------------------------------------------------------------------------
# Specify the location of the XML import utility.
# ---------------------------------------------------------------------------

BPORAIMP=/usr/openv/netbackup/bin/bporaimp

# ---------------------------------------------------------------------------
# Print out the value of the variables set by this script.
# ---------------------------------------------------------------------------

echo  
echo   "ORACLE_SID: $ORACLE_SID"
echo   "ORACLE_USER: $ORACLE_USER"
echo   "ORACLE_HOME: $ORACLE_HOME"
echo   "NB_ORA_SCRIPTS: $NB_ORA_SCRIPTS"
echo   "NB_ORA_IMP_PARAMS: $NB_ORA_IMP_PARAMS"
echo   "BPORAIMP: $BPORAIMP"
echo 

# ---------------------------------------------------------------------------
# Print out the value of the variables set by bphdb.
# Settings in bporaimp_tables.param will override
# NB_ORA_SERV value.
# ---------------------------------------------------------------------------

echo   "NB_ORA_SERV: $NB_ORA_SERV"
echo

# ---------------------------------------------------------------------------
# Call bporaimp
# ---------------------------------------------------------------------------

echo 
echo "% ${BPORAIMP} parfile=${NB_ORA_IMP_PARAMS}"
echo 

su - $ORACLE_USER -c "
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
ORACLE_HOME=$ORACLE_HOME
export ORACLE_HOME
NB_ORA_SERV=$NB_ORA_SERV
export NB_ORA_SERV
${BPORAIMP} parfile=${NB_ORA_IMP_PARAMS}
"
RETURN_STATUS=$?

echo 
echo "`date` ----------------End of Script------------------"
echo 
echo "exit $RETURN_STATUS"
exit $RETURN_STATUS

} >> $OUTF
