RMAN backup script failing

oraclerman

I have a few linux machines and each of them have a few Oracle databases. On each machine we have 2 shell scripts to run the backups. The TSM scheduler calls a script which calls a different backup script for each DB on the machine.

The problem is if I create an array of SIDs and create a loop through the SIDs the backup fails.

#!/bin/bash

LEVEL="$1"

declare -a SIDS=('SID1' 'SID2' 'SID3')
su - oracle

for SID in ${SIDS[@]}
do
  ORACLE_SID=$SID; export ORACLE_SID
  export ORACLE_HOME='/u01/app/oracle/product/10.2.0.2'
  ORAENV_ASK=NO
  . /usr/local/bin/oraenv
  LD_LIBRARY_PATH=$ORACLE_HOME/lib; export LD_LIBRARY_PATH
  /usr/local/adm/backup-incrn.sh $LEVEL $SID 35
done

There is no error in the Logs on the TSM server and it is almost as if the scripts is never called. The logs that are on the machine are not updated with any error messages.

If I use this syntax the backups work perfectly

su - oracle -c "/usr/local/adm/backup-incrn.sh $LEVEL SID1 35"

su - oracle -c "/usr/local/adm/backup-incrn.sh $LEVEL SID2 35"

I think this has to be an error in my script, some variable not being set properly.

Can anyone see the obvious mistake I've made and point it out to me?

GĂ­sli

Best Answer

"su - oracle" is the culprit

Remove that line from the script. You can switch the user before you actually run the script. if you switch user in shell script, then it gives you new shell environment loosing further shell instructions. (there are other ways to do it)