Shell basics

Here’s an example of how to call RMAN commands from a shell script:

#!/bin/ksh
#----------------------------------------------
export TARGET_CONN=sys/gober@brdstn
export CATALOG_CONN=rman_cat_owner/gando@rman_cat
#----------------------------------------------
rman <<EOF
# Connect to the target and the catalog
connect target ${TARGET_CONN}
connect catalog ${CATALOG_CONN}
# Run the backup command.
        run { allocate channel d1 type disk;
              backup full format
                '/d0102/backup/rman_%U.bus' database; }
EOF
#
exit

There are several things to note about this example. Notice that two variables, TARGET_CONN and CATALOG_CONN, are used to hold the connection information. These variables are used as the connection strings after RMAN has been called within the script. This keeps the password from being visible in the process list.

The EOF text strings act as markers that tell Unix that any commands between the EOFs are commands associated with the command to the immediate left of the `` characters. While the EOF can be any text string, we’ll use the EOF text as a standard in our shell script examples throughout this book.

If RMAN encounters an error, it returns a nonzero exit code that can be evaluated within the O/S shell script. For example:

... #Test for success of RMAN operation
if [ $? -ne 0 ]; then
# notify adminstrator of problem
fi

Before you run a shell script, ensure that the correct file permissions have been set so that the file is executable and does not have world-read permissions. ...

Get Oracle RMAN Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.