proddb1 [NOTSET]> more /oracle/bin/rman_bkup2fbra.ksh
#!/bin/ksh
# File: rman_bkup2fbra.ksh
# Purpose: Daily backup to Flashback Recovery Area
# Created: 2007-04-13 RnB - John Bening
P_SID=${1:-NOTSET} # SID to backup
P_MODE=${2:-NOTSET} # backup type: FULL | INC_D | INC_C
P_RETENTION=${3:-NOTSET} # recovery window in days
PROG=rman_bkup2fbra
if [[ "$P_SID" = NOTSET ]]; then
echo "\nUsage:"
echo " rman_bkup2fbra.ksh <SID> <FULL|INC_D|INC_C> <RETENTION_DAYS>"
echo ""
exit 1
fi
. /oracle/bin/oradbenv $P_SID
DB_TAG=${P_MODE}_`date +%y%m%d`
AL_TAG=ARC_`date +%y%m%d`
LC_SID=`echo $ORACLE_SID | tr "[:upper:]" "[:lower:]"` # lowercase SID
SID_ORABACK=`/oracle/bin/get_fbra_uniq.ksh`
#SID_ORABACK=/${LC_SID}/orafbra/${P_SID}
#SID_ORABACK=/u01/oraback/${ORACLE_SID}
mkdir -p $SID_ORABACK/etc >/dev/null 2>&1
FROMTIME="to_date('`date +%Y%m%d_%H%M%S`','yyyymmdd_hh24miss')"
echo "#"
echo "P_SID=$P_SID"
echo "P_MODE=$P_MODE"
echo "P_RETENTION=$P_RETENTION"
echo "DB_TAG=$DB_TAG"
echo "AL_TAB=$AL_TAG"
echo "FROMTIME=$FROMTIME"
echo "#"
# Switch to a temp working directory
TMP_DIR=/var/tmp/$PROG.$$
mkdir $TMP_DIR
cd $TMP_DIR
cp -p $ORACLE_HOME/dbs/orapw${ORACLE_SID} $SID_ORABACK/etc
cp -p $ORACLE_HOME/dbs/init${ORACLE_SID}.ora $SID_ORABACK/etc
cat >sql1.sql <<EOF
connect / as sysdba
alter database backup controlfile to trace as '$SID_ORABACK/etc/control.trc' re
use resetlogs;
create pfile='$SID_ORABACK/etc/spfile${ORACLE_SID}.txt' from spfile ;
column name format A25
column value format A50
column parameter format A25
set pagesize 10000
set echo on
REM
prompt hostname = `hostname`
prompt date = `date`
prompt ORACLE_HOME = $ORACLE_HOME
prompt ORACLE_SID = $ORACLE_SID
show sga
select * from v\$version ;
select * from v\$instance ;
select * from v\$database ;
select * from dba_tablespaces order by 1 ;
select * from dba_data_files order by 1 ;
select * from dba_temp_files order by 1 ;
select * from v\$logfile order by member ;
select * from v\$log order by 1 ;
select * from v\$nls_parameters order by 1 ;
select name, value from V\$PARAMETER where isdefault = 'FALSE' order by 1 ;
select name, value from V\$PARAMETER order by 1 ;
exit
EOF
sqlplus /nolog @sql1.sql >$SID_ORABACK/etc/misc1.txt
cat >rman1.rcv <<EOF
# File: rman1.rcv
#
set echo on
#
# RMAN persistent settings
configure controlfile autobackup off ;
configure retention policy to recovery window of $P_RETENTION days ;
configure device type disk backup type to compressed backupset ;
configure channel device type disk maxpiecesize 4000 M;
configure snapshot controlfile name to '$SID_ORABACK/etc/control.bak';
#
show all ;
#
allocate channel for maintenance type disk ;
crosscheck backup ;
crosscheck copy ;
delete noprompt obsolete ;
delete noprompt expired backup ;
delete noprompt expired copy ;
release channel ;
#
sql 'alter system archive log current' ;
EOF
case $P_MODE in
FULL) echo "backup incremental level 0 cumulative" >>rman1.rcv ;;
INC_D) echo "backup incremental level 1" >>rman1.rcv ;;
INC_C) echo "backup incremental level 1 cumulative" >>rman1.rcv ;;
esac
cat >>rman1.rcv <<EOF
as compressed backupset device type disk
tag '$DB_TAG' database spfile current controlfile for standby ;
#tag '$DB_TAG' tablespace tools ;
#
allocate channel for maintenance type disk ;
delete noprompt obsolete device type disk ;
release channel ;
#
sql 'alter system archive log current' ;
#
# The End
EOF
cp rman1.rcv $SID_ORABACK/etc/rman1.rcv
echo "##########################################################"
echo "# rman1.rcv"
echo "##########################################################"
cat rman1.rcv
echo "##########################################################"
echo "#"
echo "+rman target=/ nocatalog @rman1.rcv"
rman target=/ nocatalog @rman1.rcv
RMAN_EC=$?
if [[ $RMAN_EC = 0 ]] ; then
echo "# RMAN exit code was 0"
else
echo "*ERROR: non-zero RMAN exit code: $RMAN_EC"
fi
cat >rman2.rcv <<EOF
# File: rman2.rcv
#
# set echo on
#
sql 'alter system archive log current' ;
#
# configure controlfile autobackup on ;
# show all
#
backup as compressed backupset device type disk
tag '$AL_TAG' archivelog from time "${FROMTIME}" ;
#
backup as compressed backupset device type disk
tag '$AL_TAG' archivelog until time "(sysdate - 7)" ;
delete archivelog until time "(sysdate - 7)" backed up 1 times to device type disk ;
#
list backup completed after "(sysdate - 1.5)" ;
#
# backup as compressed backupset current controlfile for standby tag 'STANDBY' ;
#
# The End
EOF
cp rman2.rcv $SID_ORABACK/etc/rman2.rcv
echo "##########################################################"
echo "# rman2.rcv"
echo "##########################################################"
cat rman2.rcv
echo "##########################################################"
echo "#"
export NLS_DATE_FORMAT=YYYYMMDD_HH24MISS
echo "+rman target=/ nocatalog @rman2.rcv"
rman target=/ nocatalog @rman2.rcv
RMAN_EC=$?
if [[ $RMAN_EC = 0 ]] ; then
echo "# RMAN exit code was 0"
else
echo "*ERROR: non-zero RMAN exit code: $RMAN_EC"
fi
# cleanup
cd /var/tmp
rm -rf $TMP_DIR >/dev/null 2>&1
# The End