#!/bin/ksh
#***********************************************************************
#*                                                                     *
#*             Copyright (c) Ultra Electronics Limited 2007            *
#*                         All rights reserved                         *
#*                                                                     *
#***********************************************************************
#*
#* Filename:           rman_config.ksh
#* Subsystem Name:     RMAN backup
#* Originating Author: Gary Roberts
#* Design Reference:   UAS/FALCP/CA/02517
#*
#***********************************************************************
#*
#* Description:
#*     This script configures the system for using RMAN. If a recovery
#*     catalog is to be used then the script will register the database
#*     in the recovery catalog. The script also sets the non-default
#*     RMAN config parameters correctly. These parameters are important,
#*     and if not set may cause backups to fail. If a recovery catalog
#*     is used, its connection details must be passed into this script
#*     as an argument (see Usage below).
#*
#* Usage:
#*     rman_config.ksh <user>/<password>@<recovery catalog tns name>
#*
#*
#**********************************************************************/

CATALOG_CONN=""
if [ "$1" != "" ]
then
    echo "Registering the database in the recovery catalog... "
    CATALOG_CONN="catalog $1"
    rman target / ${CATALOG_CONN} << EOF
    register database;
EOF
fi

echo "Setting RMAN configuration parameters... "
rman target / ${CATALOG_CONN} << EOF
CONFIGURE CHANNEL 1 DEVICE TYPE DISK MAXPIECESIZE 7000M;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 3 DAYS;
EOF

echo "Making backup scripts executable... "
SUM_RET=0
chmod 755 /shared/tagtrak/bin/database_backup.ksh
SUM_RET=`expr $SUM_RET + $?`
chmod 755 /shared/tagtrak/bin/rman_db_backup.ksh
SUM_RET=`expr $SUM_RET + $?`
chmod 755 /shared/tagtrak/bin/move_files_to_tape.ksh
SUM_RET=`expr $SUM_RET + $?`

if [ $SUM_RET -ne 0 ]
then
    echo "-----------------------------------------------------------------"
    echo "WARNING: A problem occurred whilst making the backup"
    echo "scripts executable. You must now manually ensure that"
    echo "the files: database_backup.ksh, rman_db_backup.ksh and"
    echo "move_files_to_tape.ksh are in the directory:"\
         "/shared/tagtrak/bin"
    echo "and ensure that they have executable permissions."
    echo "-----------------------------------------------------------------"

else
    echo "Backup scripts are now executable."
fi

