Learn how to a build a cloud-first strategyRegister Now



Posted on 2007-10-09
Medium Priority
Last Modified: 2012-06-27
Hi all

I have created two rman scripts that are stored in my catalog. These are level0 and level 1. This run ok when I execute them manually run {execute stored script scriptname;}

I would like to schedule this to run through crotab out of hours, and also to send me an email notification once the backup has completed. Can someone please help?

My level0 script is below

{allocate channel level0 type disk;
backup incremental level 0
format '/oraback/rman_inc/ora_df%t_s%s_s%p'
filesperset = 3
include current controlfile;
backup archivelog all;
release channel level0;

Question by:novicedbaUK

Expert Comment

ID: 20039729
create file eg. crontab_def.txt
put following into it
0 * * * * path_to_your_script >> path_to_some_log_file 2>&1
crontab crontab_def.txt
-- this will run your script each hour
make crontab_def.txt executable: r-xr-x-r-x
put calling rman into script
put mail notification to the end of script (using unix mail)

Author Comment

ID: 20039807
my script is stored in the recovery catalogue, how do i find its path name?
LVL 35

Expert Comment

by:Mark Geerlings
ID: 20040475
The "cron" scheduler can run shell scripts, but it cannot look inside of Oracle and refer directly to things in the database.  Rman can use script files that are stored as ASCII text files in the O/S, so it is possible to have cron run rman and use a script file (we do that).  But, another thing to be aware of is the fact that "cron" jobs *DO NOT* have the same environment variables set by default as you do when you run a command interactively.  So, your shell script that runs rman may first need to set the environment variables that rman needs.

I have no UNIX experience (and only limited Linux experience) so I am not an expert on cron.  I am not an expert on rman either (I've been doing Oracle backups for 15 years, since long before rman was an option).  But we do have cron running rman for us successfully.  There may be other ways to get this combination to work, but I can post the shell scripts, rman scripts and crontab entries that we use here if you would like.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 20040687
Many thanks for your response. If you coud please send me your scripts that would be great.
LVL 35

Accepted Solution

Mark Geerlings earned 200 total points
ID: 20041014
Here is the top part of our "crontab" file with the line that runs RMAN for us:
# Warning! "cron" jobs run without setting environment defaults!
# To suppress cron output going to mail automatically, add "> /dev/null"
# To also suppress possible error messages going to mail, add: " 2>&1" to the end of that
#cron job fields (6) are:
#Minute - Hour - Day of month - Month - Day of week - command (shell script) to run
5      12         *      *      *      /home/oracle2/scripts/rmanLDB1.sh  > /dev/null 2&>1      
-*-*-* (end of clip from "crontab)-*-*-*

Here is the shell scipt: rmanLDB1.sh:
(Note the two actual passwords have been replaced by: [password]

#set env info for oracle
. /home/oracle2/scripts/set_LDB1.sh
#set a date format that includes the time-of-day portion
# Compress the older archive_log files, so we can keep more on disk,
#  have the most recent day's uncompressed, and try to prevent RMAN from deleting them as "obsolete".
cd /san/archive
find . -name 'arc*.log' -mtime +1 -exec nice gzip -9 {} \;
cd /archive1/LDB1_arc
find . -name 'arc*.log' -mtime +1 -exec nice gzip -9 {} \;
# Run RMAN with "nice" to minimize impact on other processes:
nice $ORACLE_HOME/bin/rman target system/[password] catalog=rman/[password]@rman log='/var/ora_logs/LDB1/rman.log' @/home/oracle2/scripts/backdb_rman.sql
cd /var/ora_logs/LDB1
# Rename today's *.log file to include the current month, day, hour and minute:
mv rman.log rman_`date '+%m%d%H%M'`.log
# The RMAN syntax for a compressed backup is:
#backup as compressed backupset database
# (instead of the simple: "backup database" command, but it took 2-3 times longer when tested
# with 10gR1 on Aug. 11, 2006 and gave only a 33% reduction in space used)
-*-*-* (end of file: rmanLDB1.sh)-*-*-*

Here is the shell script that is called from the previous one to set the environment variables.  (Note the syntax for how it is called: "dot" "space" [full path] - that is important!)

# Environment variables for oracle/LDB1
# This can be called from: .bash_profile, .xstartup, and any/all shell scripts that cron will run
ORACLE_BASE=/opt/ora_base2; export ORACLE_BASE
#following "PATH" statement doesn't work as expected
PATH=/usr/kerberos/bin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/home/oracle2/scripts:/opt/ora_base2/ora10gR1/bin; export PATH
# ld_library_path added 22-Sep-2005 for Oracle
-*-*-* (end of file: set_LDB1.sh)-*-*-*

Here is the RMAN script we use, named "backdb_rman.sql":
(Note that we have our "retention policy" for RMAN set to: "redundancy 2" so we always keep two older RMAN backups on disk, plus the current one.)

delete noprompt obsolete;
crosscheck archivelog all;
delete noprompt expired archivelog all;
resync catalog;
backup database;

Expert Comment

ID: 20591397
Forced accept.

EE Admin

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Suggested Courses
Course of the Month21 days, 2 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question