RMAN Backup. Example of backup log
backup /cygdrive/p/backup/ora_online/20151118_1714
Recovery Manager: Release 11.1.0.7.0 - Production on Wed Nov 18 17:14:41 2015
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: IGT (DBID=933592012)
RMAN> run {
2> configure controlfile autobackup on;
3> configure backup optimization on;
4> set controlfile autobackup format for device type disk to 'p:\backup\ora_online\20151118_1714\%F';
5> allocate channel 'dev_0' type disk format = 'p:\backup\ora_online\20151118_1714\dbf_%d_%T_%U';
6> backup full database;
7> backup archivelog from time = 'sysdate-10/1440' format 'p:\backup\ora_online\20151118_1714\arch_%d_%T_%U';
8> release channel 'dev_0';
9> }
10>
using target database control file instead of recovery catalog
old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
old RMAN configuration parameters:
CONFIGURE BACKUP OPTIMIZATION ON;
new RMAN configuration parameters:
CONFIGURE BACKUP OPTIMIZATION ON;
new RMAN configuration parameters are successfully stored
executing command: SET CONTROLFILE AUTOBACKUP FORMAT
allocated channel: dev_0
channel dev_0: SID=271 device type=DISK
Starting backup at 18-NOV-15
channel dev_0: starting full datafile backup set
channel dev_0: specifying datafile(s) in backup set
input datafile file number=00006 name=D:\ORACLE_DB\DB1\DB_IGT\ORA_IGT_TABLE_01.DBF
input datafile file number=00005 name=D:\ORACLE_DB\DB1\DB_IGT\ORA_GININDEX_01.DBF
input datafile file number=00004 name=D:\ORACLE_DB\DB1\DB_IGT\ORA_GIN_01.DBF
input datafile file number=00003 name=D:\ORACLE_DB\DB1\DB_IGT\ORA_UNDOTBS_01.DBF
input datafile file number=00007 name=D:\ORACLE_DB\DB1\DB_IGT\ORA_IGT_INDEX_01.DBF
input datafile file number=00002 name=D:\ORACLE_DB\DB1\DB_IGT\ORA_SYSAUX_01.DBF
input datafile file number=00001 name=D:\ORACLE_DB\DB1\DB_IGT\ORA_SYSTEM_01.DBF
input datafile file number=00008 name=D:\ORACLE_DB\DB1\DB_IGT\ORA_WORKAREA_01.DBF
input datafile file number=00009 name=D:\ORACLE_DB\DB1\DB_IGT\ORA_DWH_TABLE_01.DBF
input datafile file number=00010 name=D:\ORACLE_DB\DB1\DB_IGT\ORA_DWH_INDEX_01.DBF
channel dev_0: starting piece 1 at 18-NOV-15
channel dev_0: finished piece 1 at 18-NOV-15
piece handle=P:\BACKUP\ORA_ONLINE\20151118_1714\DBF_IGT_20151118_GSQMJ9O6_1_1 tag=TAG20151118T171445 comment=NONE
channel dev_0: backup set complete, elapsed time: 00:06:45
Finished backup at 18-NOV-15
Starting backup at 18-NOV-15
current log archived
channel dev_0: starting archived log backup set
channel dev_0: specifying archived log(s) in backup set
input archived log thread=1 sequence=143097 RECID=143087 STAMP=896116533
input archived log thread=1 sequence=143098 RECID=143088 STAMP=896116892
channel dev_0: starting piece 1 at 18-NOV-15
channel dev_0: finished piece 1 at 18-NOV-15
piece handle=P:\BACKUP\ORA_ONLINE\20151118_1714\ARCH_IGT_20151118_GTQMJA4T_1_1 tag=TAG20151118T172133 comment=NONE
channel dev_0: backup set complete, elapsed time: 00:00:07
Finished backup at 18-NOV-15
Starting Control File and SPFILE Autobackup at 18-NOV-15
piece handle=P:\BACKUP\ORA_ONLINE\20151118_1714\C-933592012-20151118-00 comment=NONE
Finished Control File and SPFILE Autobackup at 18-NOV-15
released channel: dev_0
Recovery Manager complete.
fullRmanBackup: 18-11-2015 17:21:45 INFO- rman target backup has finished
Recovery Manager: Release 11.1.0.7.0 - Production on Wed Nov 18 17:21:45 2015
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: IGT (DBID=933592012)
RMAN>
using target database control file instead of recovery catalog
Report of obsolete backups and copies
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set 6500 09-NOV-15
Backup Piece 6500 09-NOV-15 P:\BACKUP\ORA_ONLINE\20151109_0300\DBF_IGT_20151109_FJQLQ09U_1_1
Backup Set 6501 09-NOV-15
Backup Piece 6501 09-NOV-15 P:\BACKUP\ORA_ONLINE\20151109_0300\ARCH_IGT_20151109_FKQLQ0M0_1_1
Archive Log 142553 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142563_695307596.ARC
Backup Set 6502 09-NOV-15
Backup Piece 6502 09-NOV-15
P:\BACKUP\ORA_ONLINE\20151109_0300\C-933592012-20151109-00
Archive Log 142554 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142564_695307596.ARC
Archive Log 142555 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142565_695307596.ARC
Archive Log 142556 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142566_695307596.ARC
Archive Log 142557 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142567_695307596.ARC
Archive Log 142558 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142568_695307596.ARC
Archive Log 142559 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142569_695307596.ARC
Archive Log 142560 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142570_695307596.ARC
Archive Log 142561 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142571_695307596.ARC
Archive Log 142562 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142572_695307596.ARC
Archive Log 142563 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142573_695307596.ARC
Archive Log 142564 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142574_695307596.ARC
Archive Log 142565 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142575_695307596.ARC
Archive Log 142566 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142576_695307596.ARC
Archive Log 142567 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142577_695307596.ARC
Archive Log 142568 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142578_695307596.ARC
Archive Log 142569 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142579_695307596.ARC
Archive Log 142570 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142580_695307596.ARC
Archive Log 142571 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142581_695307596.ARC
Archive Log 142572 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142582_695307596.ARC
Archive Log 142573 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142583_695307596.ARC
Archive Log 142574 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142584_695307596.ARC
Archive Log 142575 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142585_695307596.ARC
Archive Log 142576 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142586_695307596.ARC
Archive Log 142577 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142587_695307596.ARC
Archive Log 142578 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142588_695307596.ARC
Archive Log 142579 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142589_695307596.ARC
Archive Log 142580 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142590_695307596.ARC
RMAN>
Recovery Manager complete.
fullRmanBackup: 18-11-2015 17:21:53 INFO- setting acls
fullRmanBackup: 18-11-2015 17:21:53 INFO- deleting obsolete backup sets
Recovery Manager: Release 11.1.0.7.0 - Production on Wed Nov 18 17:21:53 2015
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: IGT (DBID=933592012)
RMAN>
using target database control file instead of recovery catalog
allocated channel: ORA_MAINT_DISK_1
channel ORA_MAINT_DISK_1: SID=238 device type=DISK
RMAN>
List of Archived Log Copies for database with db_unique_name IGT
=====================================================================
Key Thrd Seq S Low Time
------- ---- ------- - ---------
143087 1 143097 A 18-NOV-15
Name: M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_143097_695307596.ARC
143088 1 143098 A 18-NOV-15
Name: M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_143098_695307596.ARC
deleted archived log
archived log file name=M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_143097_695307596.ARC RECID=143087 STAMP=896116533
deleted archived log
archived log file name=M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_143098_695307596.ARC RECID=143088 STAMP=896116892
Deleted 2 objects
RMAN>
RMAN>
Deleting the following obsolete backups and copies:
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set 6500 09-NOV-15
Backup Piece 6500 09-NOV-15 P:\BACKUP\ORA_ONLINE\20151109_0300\DBF_IGT_20151109_FJQLQ09U_1_1
Backup Set 6501 09-NOV-15
Backup Piece 6501 09-NOV-15 P:\BACKUP\ORA_ONLINE\20151109_0300\ARCH_IGT_20151109_FKQLQ0M0_1_1
Archive Log 142553 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142563_695307596.ARC
Backup Set 6502 09-NOV-15
Backup Piece 6502 09-NOV-15
P:\BACKUP\ORA_ONLINE\20151109_0300\C-933592012-20151109-00
Archive Log 142554 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142564_695307596.ARC
Archive Log 142555 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142565_695307596.ARC
Archive Log 142556 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142566_695307596.ARC
Archive Log 142557 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142567_695307596.ARC
Archive Log 142558 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142568_695307596.ARC
Archive Log 142559 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142569_695307596.ARC
Archive Log 142560 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142570_695307596.ARC
Archive Log 142561 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142571_695307596.ARC
Archive Log 142562 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142572_695307596.ARC
Archive Log 142563 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142573_695307596.ARC
Archive Log 142564 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142574_695307596.ARC
Archive Log 142565 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142575_695307596.ARC
Archive Log 142566 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142576_695307596.ARC
Archive Log 142567 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142577_695307596.ARC
Archive Log 142568 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142578_695307596.ARC
Archive Log 142569 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142579_695307596.ARC
Archive Log 142570 09-NOV-15 M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142580_695307596.ARC
deleted backup piece
backup piece handle=P:\BACKUP\ORA_ONLINE\20151109_0300\DBF_IGT_20151109_FJQLQ09U_1_1 RECID=6500 STAMP=895287616
deleted backup piece
backup piece handle=P:\BACKUP\ORA_ONLINE\20151109_0300\ARCH_IGT_20151109_FKQLQ0M0_1_1 RECID=6501 STAMP=895288000
deleted archived log
archived log file name=M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142563_695307596.ARC RECID=142553 STAMP=895289800
deleted backup piece
backup piece handle=P:\BACKUP\ORA_ONLINE\20151109_0300\C-933592012-20151109-00 RECID=6502 STAMP=895288009
deleted archived log
archived log file name=M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142564_695307596.ARC RECID=142554 STAMP=895291599
deleted archived log
archived log file name=M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142565_695307596.ARC RECID=142555 STAMP=895293401
deleted archived log
archived log file name=M:\ORACLE_DB\DB2\DB_IGT\ARCH\ARCH001_142566_695307596.ARC RECID=142556 STAMP=895295201
Deleted 102 objects
RMAN>
released channel: ORA_MAINT_DISK_1
RMAN>
Recovery Manager complete.
fullRmanBackup: 18-11-2015 17:23:47 INFO- removing empty directories
backup.ini
RMAN_BACKUP_DIR=/backup/ora_online
RMAN_RETENTION_REDUNDANCY=1
RMAN_GENERAL_LOG=/etc/sh/backup/log/backup_general.log
RMAN_ARCH_BACKUP_THRESHOLD=20
RMAN_ARCH_DELETE_THRESHOLD=10
#RMAN_READRATE=4
REPORT_SMTP_SERVER=x.y.z.w
REPORT_SMTP_TO=user@someplace.com
backuptab
#@ backuptab file format:
#@
#@ sid:backup-type:arch-dest
#@
#@ sid - name of sid to backup
#@ backup-type - F (full) or I (incremental, NYI)
#@ arch-dest - a comma-separated archive destination locations
igt:F:/oracle_db/db2/db_igt/arch
gin:F:/cygdrive/m/oracle_db/db2/db_gin/arch
backupFunctions.sh
#!/bin/bash
#@ backupFunctions
#@
#@ this script is used by other backup scripts to load common functions.
#@
#@ available functions:
#@ createTmpFile - generates a name for a temporary file
#@ getBackupLogName - translates the backup log name to the appropriate
#@ platform (windows vs. *nix)
#@ getFromIni - retrieves a parameter from the backup.ini file
#@ getOsFilename - translates a filename to a platform specific form
#@ getRmanScriptName - translates the rman script name to the appropriate
#@ platform (windows vs. *nix)
#@ loadOracle - loads the oracle environment variable for a specific
#@ instance
#@ setSymbols - sets symbols for common execution files such as awk,
#@ and rman for the specific platofrm (gawk vs. awk, etc.)
#@ showVersion - display the version number of the running script
#@ according to the Revision cvs parameter
#@
# written by Amir Kibbar
#
# $Revision: 543 $
#
# Changelog:
# +-------------+------+-------------------------------------------------------+
# | 12-DEC-2004 | Amir | Initial version |
# +-------------+------+-------------------------------------------------------+
showVersion() {
version=`grep "# \\$Revision" $0 | awk -F"$" '{print $2}' | cut -d " " -f2`
echo "$FACILITY version $version"
exit
}
createTmpFile() {
if [ $OS = "SunOS" ]; then
# the sleep here is to make sure the filename is unique. Solaris does not
# support milliseconds
sleep 1
tmpFile="/tmp/rman_$$`date '+%M%S'`"
touch $tmpFile
elif [ ! -x /usr/bin/mktemp -a ! -x /bin/mktemp ]; then
tmpFile="/tmp/rman_$$`date +%s`"
touch $tmpFile
else
tmpFile=`mktemp /tmp/rman_XXXXXX`
fi
}
getFromIni() {
local param=$1
iniValue=`grep -v "#" $BACKUPINI | grep $param`
if [ -n "$iniValue" ]; then
iniValue=`echo $iniValue | cut -d= -f2`
fi
}
loadOracle() {
local oraSid=$1
echo $FACILITY `date` INFO- loading Oracle env for $oraSid
. $ORASH/oracle_login.sh $oraSid
FACILITY=`basename $0 .sh`\:
if [ -z "$ORACLE_ENV_DEFINED" ]; then
echo "$FACILITY `date` ERR- can't load Oracle env for $oraSid"
exit
fi
}
setSymbols() {
if [ -z "$ORACLE_HOME" -a -n "$CYG_ORACLE_HOME" ]; then
RMAN=$CYG_ORACLE_HOME/bin/rman
else
RMAN=$ORACLE_HOME/bin/rman
fi
AWK=awk
GREP=grep
PATH_SEP=/
LINE_SEP=\\n
OS=`uname | cut -d_ -f1`
SUDO=sudo
if [ $OS = "Linux" ]; then
DF="df -klP"
elif [ $OS = "SunOS" ]; then
AWK=/usr/sfw/bin/gawk
DF="df -k"
GREP="ggrep"
elif [ $OS = "CYGWIN" ]; then
DF="df -k"
PATH_SEP=\\
LINE_SEP=\\r\\n
SUDO=false
fi
}
getOsFilename() {
if [ $OS = "CYGWIN" ]; then
filename=`cygpath -w $1`
else
filename=$1
fi
}
getRmanScriptName() {
local tmpFile=$1
getOsFilename $tmpFile
rmanScript=$filename
}
getBackupLogName() {
local backupDest=$1
getOsFilename $backupDest
backupLog=$filename
}
if [ "$1" = "--help" ]; then
setSymbols
grep ^"#@" $0 | $AWK -F "#@" '{print $2}'
fi
rmanBackup.sh
#!/bin/bash
#@ rmanBackup [-h | -v] | [[-tab backuptab] [-ini backup.ini] instance-name]
#@
#@ backs up a database instance using rman
#@
#@ -h - this message
#@ -v - display version number
#@ instance-name - name of instance to backup.
#@ Default: ORACLE_SID
#@ -tab backuptab - use backuptab at the specified location.
#@ Default: BACKUPTAB
#@ -ini backup.ini - use backup.ini at the specified location.
#@ Default: BACKUPINI
#@
#@
#
# written by Amir Kibbar
#
# $Revision: 243 $
#
# Changelog:
# +-------------+------+-------------------------------------------------------+
# | 12-DEC-2004 | Amir | Initial version |
# +-------------+------+-------------------------------------------------------+
BACKUPTAB=$BACKUP_ROOT/backuptab
BACKUPINI=$BACKUP_ROOT/backup.ini
FACILITY=`basename $0 .sh`\:
DATE=`date`
sid=$ORACLE_SID
. $BACKUP_ROOT/internal/backupFunctions.sh
usage() {
grep ^"#@" $0 | awk -F "#@" '{sub("ORACLE_SID",ORACLE_SID,$2); sub("BACKUPTAB",BACKUPTAB,$2); sub("BACKUPINI",BACKUPINI,$2); print $2}' ORACLE_SID=$ORACLE_SID BACKUPTAB=$BACKUPTAB BACKUPINI=$BACKUPINI
echo
grep ^"#@" $BACKUPTAB | awk -F "#@" '{print $2}'
exit
}
while [ -n "$1" ]; do
case "$1" in
-h)
usage
;;
-v)
showVersion
;;
-tab)
shift
BACKUPTAB=$1
if [ -z "$BACKUPTAB" ]; then
echo $FACILITY `date` ERR- must specify backuptab location
exit
fi
;;
-ini)
shift
BACKUPINI=$1
if [ -z "$BACKUPINI" ]; then
echo "$FACILITY `date` ERR- must specify backup.ini location"
exit
fi
;;
*)
sid=$1
;;
esac
shift
done
if [ ! -r $BACKUPTAB ]; then
echo "$FACILITY `date` ERR- can't read $BACKUPTAB. Permission denied or file not found"
exit
fi
if [ ! -r $BACKUPINI ]; then
echo "$FACILITY `date` ERR- can't read $BACKUPINI. Permission denied or file not found"
exit
fi
if [ -z "$sid" ]; then
echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` ERR- must specify ORACLE_SID"
exit
fi
loadOracle $sid
tabLine=`grep $sid $BACKUPTAB`
backupType=`echo $tabLine | cut -d: -f2`
getFromIni RMAN_GENERAL_LOG
generalLog=$iniValue
case $backupType in
F)
echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` INFO- executing Oracle full backup using rman for sid: $sid" | tee -a $generalLog
$BACKUP_ROOT/internal/fullRmanBackup.sh $sid $BACKUPTAB $BACKUPINI
esac
fullRmanBackup.sh
#!/bin/bash
#@ fullRmanBackup [-h | -v] sid backuptab backupini
#@
#@ backs up a database instance using rman with the full-backup scheme. This
#@ script is an internal script, and is only intended to be run from the
#@ backup.sh script. However, it is possible to run this script on its own,
#@ just make sure the parameters are passed correctly - it does not verify them
#@
#@ -h - this message
#@ -v - display version
#@ sid - Oracle sid to backup
#@ backuptab - backuptab location
#@ backupini - backupini location
#@
#@
#
# written by Amir Kibbar
#
# $Revision: 7026 $
#
# Changelog:
# +-------------+------+-------------------------------------------------------+
# | 12-DEC-2004 | Amir | Initial version |
# +-------------+------+-------------------------------------------------------+
# | 31-JAN-2010 |Yossi | Adapt to streams; write more to log; keep logs longer |
# +-------------+------+-------------------------------------------------------+
FACILITY=`basename $0 .sh`\:
. $BACKUP_ROOT/internal/backupFunctions.sh
setSymbols
usage() {
grep ^"#@" $0 | $AWK -F "#@" '{print $2}'
exit
}
if [ "$1" = "-h" ]; then
usage
fi
if [ "$1" = "-v" ]; then
showVersion
fi
sid=$1
shift
BACKUPTAB=$1
shift
BACKUPINI=$1
shift
getFromIni RMAN_BACKUP_DIR
backupDestRoot=$iniValue
getFromIni RMAN_RETENTION_REDUNDANCY
retentionRedundancy=$iniValue
getFromIni RMAN_GENERAL_LOG
generalLog=$iniValue
getFromIni RMAN_READRATE
readRate=$iniValue
echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` INFO- rman backup started for instance $sid" | tee -a $generalLog
#echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` INFO- creating backup destination"
TIMESTAMP=`date +%Y%m%d_%H%M`
backupDest=$backupDestRoot/$TIMESTAMP
#echo $backupDest
mkdir -p $backupDest
# this is done to allow oracle to write in the backup dest, even if the running
# user is not oracle
#echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` INFO- setting acls" | tee -a $backupLog
$SUDO $INFRA_ROOT/bin/set_rman_perm.sh
if [ ! -d $backupDestRoot/for_backup/log ]; then
mkdir -p $backupDestRoot/for_backup/log
fi
if [ $OS = "CYGWIN" ]; then
rmanBackupDest=`cygpath -w $backupDest`
pathSep=\\
lineSep=\\r\\n
else
rmanBackupDest=$backupDest
pathSep=/
lineSep=\\n
fi
createTmpFile
#echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` INFO- creating rman script"
# the current backup script only backs up using autobackup because of rman
# bug #4110708
# We aim to backup all archivelog needed for restore.
# using sysdate-10/1440 (10 mins) might miss some archives for long running backup
# Instead we take timestamp at the beginning of backup session.
BACKUP_TIMESTAMP="TO_DATE('`date +%Y:%m:%d:%H:%M`','YYYY:MM:DD:HH24:MI')-10/1400"
echo "run {" >> $tmpFile
echo " configure controlfile autobackup on;" >> $tmpFile
echo " configure backup optimization on;" >> $tmpFile
echo " set controlfile autobackup format for device type disk to '${rmanBackupDest}${pathSep}%F';" >> $tmpFile
echo " allocate channel 'dev_0' type disk format = '${rmanBackupDest}${pathSep}dbf_%d_%T_%U';" >> $tmpFile
if [ -n "$readRate" ]; then
echo " set limit channel 'dev_0' readrate=$readRate;" >> $tmpFile
fi
echo " backup full database;" >> $tmpFile
#echo " backup current controlfile format '${rmanBackupDest}${pathSep}ctl_%d_%T_%U';" >> $tmpFile
#echo " backup spfile format '${rmanBackupDest}${pathSep}spfile_%d_%T_%U' ;" >> $tmpFile
echo " backup archivelog from time = \"$BACKUP_TIMESTAMP\" format '${rmanBackupDest}${pathSep}arch_%d_%T_%U';" >> $tmpFile
echo " release channel 'dev_0';" >> $tmpFile
echo "}" >> $tmpFile
#echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` INFO- running rman script"
getRmanScriptName $tmpFile
getBackupLogName $backupDestRoot/backup.log
if [ -f $backupLog ]; then
# echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` INFO- rotating backup log"
for ((i=$retentionRedundancy ; i>0 ; --i )) do
let c=i-1
if [ -f ${backupLog}.${c} ]; then
\mv -f ${backupLog}.${c} ${backupLog}.${i}
fi
done
\mv -f $backupLog ${backupLog}.1
fi
echo "backup $backupDest" >> $backupLog
$RMAN target / @ $rmanScript >> $backupLog
\rm -f $tmpFile
echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` INFO- rman target backup has finished" >> $backupLog
# move backup to the for_backup directory
echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` INFO- moving finished backup to for_backup" >> $backupLog
\mv $backupDest $backupDestRoot/for_backup/$TIMESTAMP
createTmpFile
obsoleteFile=$tmpFile.obsolete
# get the obsolete directories list
echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` INFO- obtaining obsolete directories list" >> $backupLog
$RMAN target / << zZ | tee -a $backupLog > $obsoleteFile
report obsolete redundancy = $retentionRedundancy;
exit;
zZ
dirList=`cat $obsoleteFile | grep "Backup Piece" | $AWK '{print $5}' | $AWK -F"$PATH_SEP" '{print $(NF-1)}' | sort | uniq`
# Moving backup directories containing obsolete files from the for_backup to root directory
# It maybe that directory was already moved in previous run of the script
# as the data files and control file backup kits were obsolete but archives were still required,
# thus the backup directory is already located at the root dir.
for currDir in $dirList ; do
if [ -a $backupDestRoot/for_backup/$currDir ]; then
echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` INFO- moving $currDir from for_backup to backup root" >> $backupLog
\mv $backupDestRoot/for_backup/$currDir $backupDestRoot/
fi
done
\rm -f $obsoleteFile
# this is required again to allow a user other than oracle that is running the
# script to delete the files that rman create. These files are always created
# owned by oracle:dba
#echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` INFO- setting acls" | tee -a $backupLog
$SUDO $INFRA_ROOT/bin/set_rman_perm.sh
#check if oracle streams capture is defined on the DB
sqlplus /nolog << EOD | grep -qi -e "streams0streams"
connect /
select 'streams'||count(*)||'streams' from dba_capture;
exit
EOD
streams_status=$?
echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` INFO- deleting obsolete backup sets" >> $backupLog
if [ $streams_status -eq 0 ]; then
# Streams capture not configured on the db
$RMAN target / << zZ >> $backupLog
allocate channel for delete type disk;
delete noprompt force archivelog all backed up $retentionRedundancy times to device type disk;
delete noprompt force copy of archivelog all completed before 'sysdate-10';
delete noprompt force obsolete redundancy = $retentionRedundancy;
release channel;
exit;
zZ
else
# Streams capture configured on the db
# We would like to avoid delegation of archives required by streams
# Delete obsolete is streams aware (note id 421176.1)
$RMAN target / << zZ >> $backupLog
allocate channel for delete type disk;
delete noprompt force obsolete redundancy = $retentionRedundancy;
release channel;
exit;
zZ
fi
echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` INFO- removing empty directories" >> $backupLog
for currDir in $dirList ; do
echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` INFO- removing $currDir" >> $backupLog
if [ $(ls -A $backupDestRoot/$currDir | wc -l) -eq 0 ]; then
# direcory is empty
if [ $OS != "SunOS" ]; then
\rmdir --ignore-fail-on-non-empty $backupDestRoot/$currDir
else
\rmdir $backupDestRoot/$currDir
fi
fi
done
# keep copy of backup log
cp $backupLog $backupDestRoot/for_backup/log/rman_$TIMESTAMP.log
# Purge old log and err files older than 60 days
find $backupDestRoot/for_backup/log/ -mtime +60 \( -name '*.log' -o -name '*.err' \) -exec rm -f {} \;
echo "$FACILITY `date +"%d-%m-%Y %H:%M:%S"` INFO- rman backup finished for sid $sid" | tee -a $generalLog