RE: RMAN Scripts Part 2

RE: RMAN Scripts Part 2

 

  

########################################################################
#
# set oracle environment
#
########################################################################
. /usr/local/bin/oraenvset ${ORACLE_SID} # set
oracle environment
oraenvset_code=3D$? # wait
until logfile stream has started to write error and exit.

# check if oracle environment was set correctly.
if [ ${oraenvset_code} -ne 0 ]
then
echo ""
echo "unable to set oracle environment, error code ${oraenvset_code}
returned from "
echo "/usr/local/bin/oraenvset"
echo ""
echo "Check your ORACLE_SID parameter. You entered ${ORACLE_SID}"
echo "Terminating backup"
subject=3D"${PROCESS} unable to set oracle environment `date`."
echo ""
echo "Incorect Usage: $@"
mutt -s "`hostname`: ${subject}" ${MAILGROUP} < ${PRG_LOGFILE} # mail
-s "`hostname`: ${subject}" ${MAILGROUP} < ${PRG_LOGFILE}
exit 1
fi

########################################################################
#
# Check for space before continuing, terminate if over threshold. #
########################################################################
#
# begin logfile time, date, and with beginning size of backup directory.
echo Starting Backup: `date`: Beginning size \"${RDIR}\": `ls -ltr
${RDIR} | \
awk '{total +=3D $5} END {print total}'`

echo ""
usedspace=3D`df -k ${RDIR} | awk '{print $5}' | grep -v Use | awk -F%
'{print $1}'` if [ $usedspace -gt $SPACE_THRESHOLD ] then
let spaceavail=3D100-usedspace
echo "used space =3D $usedspace; space available =3D $spaceavail"
echo "Terminating backup"
subject=3D"${PROCESS} terminated OUT OF SPACE on `date`."
mutt -s "`hostname`: ${subject}" ${MAILGROUP} < ${PRG_LOGFILE} # mail
-s "`hostname`: ${subject}" ${MAILGROUP} < ${PRG_LOGFILE}
exit 1
fi

########################################################################
#
# BEGIN RMAN BACKUP.
#
# alter system set control_file_record_keep_time =3D 14 scope=3Dboth; #
# Backup is dependent upon defaults. For Example:
#
# CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
# CONFIGURE BACKUP OPTIMIZATION ON;
# CONFIGURE DEFAULT DEVICE TYPE TO DISK;
# CONFIGURE CONTROLFILE AUTOBACKUP ON;
# CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO
'/u01/backup/rman/GHANA1/ora_cf%F';
# CONFIGURE DEVICE TYPE DISK PARALLELISM 4;
# CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
# CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; #
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT
'/u01/backup/rman/GHANA1/ora_df_t%t_s%s_p%p_c%c';
# CONFIGURE MAXSETSIZE TO UNLIMITED;
# CONFIGURE SNAPSHOT CONTROLFILE NAME TO
'/u01/backup/rman/GHANA1/snapcf_GHANA1';
#
# sql "create pfile=3D'${RDIR}/init${ORACLE_SID}_${TODAY}.ora' from
spfile";
########################################################################
# BACKUP ARCHIVELOG ALL NOT BACKED UP 2 TIMES delete input; rman
nocatalog 1>${RMAN_LOGFILE} 2>&1 << EOF connect target / show all; sql
"alter system archive log current"; BACKUP INCREMENTAL LEVEL=3D${RLEV}
DATABASE; BACKUP ARCHIVELOG ALL NOT BACKED UP 2 TIMES; crosscheck
backup; crosscheck archivelog all; backup validate database archivelog
all; delete noprompt archivelog all backed up 2 times to DEVICE TYPE
DISK completed before 'sysdate-1'; delete noprompt obsolete; list
backup; restore database validate; exit EOF
########################################################################
#connect target /
#show all;
#BACKUP INCREMENTAL LEVEL=3D${RLEV} DATABASE;
#sql "alter system archive log current";
# bug 4612903 do:
# backup archivelog all 'delete input';
# before delete noprompt obsolete;
# also
# backup validate database archivelog all;
# before 'delete input'
# backup validate database archivelog all;
# BACKUP ARCHIVELOG ALL NOT BACKED UP 2 TIMES delete input; #crosscheck
backup; #crosscheck archivelog all; #delete noprompt archivelog all
backed up 2 times to DEVICE TYPE DISK completed before 'sysdate-1';
#delete noprompt obsolete; #list backup; #restore database validate;
#backup validate database archivelog all; #exit
########################################################################

########################################################################
# change archivelog all validate;
# BACKUP ARCHIVELOG ALL NOT BACKED UP 2 TIMES;
#crosscheck backup;
#crosscheck archivelog all;
#delete noprompt obsolete;
#Delete noprompt archivelog all backed up 2 times to DEVICE TYPE DISK
completed before 'sysdate-1'; #exit #EOF
########################################################################

result_code=3D$?

# print sucess or failure message
########################################################################
#
# CLEANUP:
# Delete excess logfiles.
# a. script logfiles older than ${DAYSTOKEEP_LOGS}
# b. RMAN logfiles older than ${DAYSTOKEEP_BACKUPS}
#
########################################################################
if [ ${result_code} -ne 0 ]
then
errors=3D`expr ${errors} + 1`
echo "RMAN Backup of ${ORACLE_SID} on ${BOX} failed: `date`."
echo " (See ${RMAN_LOGFILE}} for details)."
echo " Check level ${RLEV} RMAN backups..."
echo ""
else
echo "RMAN Backup of ${ORACLE_SID} on ${BOX} completed successfully on
`date`."
echo " (See ${RMAN_LOGFILE}} for details)."
echo ""
# Clean up 'script log' files and itemize.
echo "Deleting old script logs older than ${DAYSTOKEEP_LOGS} days."
find ${PRG_LOGDIR} -type f -name "rman_*.log" ! -mtime
-${DAYSTOKEEP_LOGS} | while read -r filename ; do
echo "Removing script logfile: $filename"
rm $filename
done

# Clean up 'rman log' files and itemize.
echo "Deleting RMAN logs older than ${DAYSTOKEEP_LOGS} days."
find ${RMAN_LOGDIR} -type f -name "rman_${ORACLE_SID}_*.log" ! -mtime
-${DAYSTOKEEP_LOGS} | while read -r filename ; do
echo "Removing RMAN logfile: $filename"
rm $filename
done

# Clean up 'RMAN backup' files and itemize.
echo "Deleting RMAN backup files older than ${DAYSTOKEEP_BACKUPS}
days."
find ${RDIR} -type f -name "*.gz" ! -mtime -${DAYSTOKEEP_BACKUPS} |
while read -r filename ; do
echo "Removing rman backup file: $filename"
rm $filename
done

# Compressing RMAN backup files.
echo ""
# echo Begin gzip: `date`: size \"${RDIR}\" is: `ls -ltr ${RDIR} | \
# awk '{total +=3D $5} END {print total}'`
echo "zipping has been commented out for this backup."
echo ""
# find ${RDIR}/* | grep -v .gz | while read -r filename ; do
# echo "Zipping up rman backup file: $filename"
# gzip -9 $filename
# done
echo End Backup: `date`: Ending size \"${RDIR}\": `ls -ltr
${RDIR} | \
awk '{total +=3D $5} END {print total}'`

fi

################################################################
#
# Mail the log file to the DBA's.
# ################################################################

if [ ${errors} -eq 0 ]
then
subject=3D"${PROCESS} terminated SUCESSFULLY on `date`."
else
# more than one error would occur is backing up more than
# one database in a loop. For example looping through oratab.
# subject=3D"${PROCESS} FAILED with ${errors} errors on `date`."
subject=3D"${PROCESS} FAILED on `date`."
fi

mutt -s "`hostname`: ${subject}" -a ${RMAN_LOGFILE} ${MAILGROUP} <
${PRG_LOGFILE}

# mail -s "`hostname`: ${subject}" ${MAILGROUP} < ${PRG_LOGFILE} # mail
-s "`hostname`: ${subject}" [Email address protected] < ${PRG_LOGFILE}

-----Original Message-----
From: Shergill Gurmohan
[mailto:oracledba-ezmlmshield-x5916008.[Email address protected]
Sent: Thursday, January 05, 2006 4:31 PM
To: LazyDBA Discussion
Subject: RE: RMAN Scripts

I am sorry I forgot to put I need them to work in Oracle 9i.

gurmohan

> -----Original Message-----
> From: Shergill, Gurmohan
> Sent: Thursday, January 05, 2006 4:30 PM
> To: '[Email address protected]
> Subject: RMAN Scripts
>
> Can some one point me to a place where I can find some ready made RMAN
scripts for backups and restores. Or, if someone of you have them I'd
like to share them please.
>
> G Shergill
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
> Gurmohan Shergill | Database Administrator
> [ p ] 631.547.2982 [ f ] 631.547.xxxx [ e ] [Email address protected]
>
> AutoOne Insurance Company | LAD / Personal Auto Operations
> 201 Old Country Road | P.O. Box 9027 | Melville, NY 11747
>
> What Drives You?
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * *
> This e-mail, including attachments, is for the use of the intended
recipient only
> and may contain information that is privileged, proprietary,
confidential or exempt
> from disclosure under applicable law. Any unauthorized dissemination,
distribution,
> disclosing or copying of this communication, including attachments, is
prohibited
> and may be unlawful. If you are not the intended recipient, please
delete this
> e-mail, including any attachments and copies, and notify the sender
immediately.
>
>


--------
website: http://www.LazyDBA.com
Please don't reply to RTFM questions
Oracle documentation is here: http://tahiti.oracle.com
To unsubscribe: see http://www.lazydba.com/unsubscribe.html
To subscribe: see http://www.lazydba.com
By using this list you agree to these
terms:http://www.lazydba.com/legal.html



Oracle LazyDBA home page