Posted on 2007-10-09
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
    LVL 9

    Expert Comment

    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

    my script is stored in the recovery catalogue, how do i find its path name?
    LVL 34

    Expert Comment

    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.

    Author Comment

    Many thanks for your response. If you coud please send me your scripts that would be great.
    LVL 34

    Accepted Solution

    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/  > /dev/null 2&>1      
    -*-*-* (end of clip from "crontab)-*-*-*

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

    #set env info for oracle
    . /home/oracle2/scripts/
    #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:*-*-*

    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:*-*-*

    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;
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Join & Write a Comment

    Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
    Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
    This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
    This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

    733 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now