1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash

BACKUP_DATE=`date "+%Y%m%d"`
LOGDIR=/u01/app/oracle/admin/rman/logs
DB_NAME=$1
BACKUP_TYPE=$2

if [ "$#" -ne 2 ]; then
        echo "Usage: DB_NAME BACKUP_TYPE"
        exit 1
else
        grep -q $DB_NAME /etc/oratab
        if [ $? == 1 ]; then
                echo "Invalid input for parameter 1: Verify ORACLE_SID exists in oratab"
		exit 1
        else
                if [ $BACKUP_TYPE == "full" ] || [ $BACKUP_TYPE == "incr" ] || [ $BACKUP_TYPE == "arch" ]; then
			export ORACLE_SID=$DB_NAME
			export ORAENV_ASK=NO
			export PATH=/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:$PATH
			. oraenv

			$ORACLE_HOME/bin/rman <<- RUN_RMAN_BACKUP 
				connect target "dbuser/password@${ORACLE_SID} as sysbackup" ;
				connect catalog rcatuser/password@rmancat
				spool log to '${LOGDIR}/${DB_NAME}/${DB_NAME}_${BACKUP_TYPE}_backup.log' append ;

				set command id to '${ORACLE_SID}_${BACKUP_TYPE}_${BACKUP_DATE}' ;

				RUN { EXECUTE SCRIPT gbl_${BACKUP_TYPE}_db_backup USING ${ORACLE_SID} "${BACKUP_TYPE}" ${BACKUP_DATE}; }

				exit ;
			RUN_RMAN_BACKUP
		else
                        echo "Invalid input for parameter 2: Expecting full/incr/arch"
			exit 1

                fi

        fi

fi