3 Replies Latest reply: Apr 18, 2013 5:40 AM by FreddieEssex RSS

    Using variables in RMAN - Unix Shell script

    Sivaprasad S
      I am new to Oracle and would appreciate advise on my requirement below.

      Environment:

      Oracle DB Version     11.2.0.3.0
      Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production with 2 nodes RAC.

      Requirement :

      Daily at morning 5:00, Flashback the database to the yesterday restore point.
      It has to be scheduled to be done automatically. Now it being performed manually.


      Psuedo code:

      1. Shutdown the RAC database

      2. Bring up the RAC database with mount mode

      3. Flashback the database to yesterday restore point

      4. Create new restore point to be used on next day

      5. Bring up other instance of the RAC database.


      #!/bin/ksh
      #######################################################################
      
      # Shutdown databases and bring up one instance in NOMOUNT mode.
      #
      #######################################################################
      
      # Set Oracle 11gR2 Enviornment variables
      . ora11gr2setup
      
      # Check the status of the database
      echo srvctl status database -d TestDB
      srvctl status database -d TestDB
      
      # Stop the RAC database
      echo srvctl stop database -d TestDB
      srvctl stop database -d TestDB
      
      # Start one instance of the database with mount mode 
      echo srvctl start instance -d TestDB -i TestDB1 -o mount
      srvctl start instance -d TestDB -i TestDB1 -o mount
      
      # Set database contect
      . setdb TestDB
      
      start_dt=`date +%Y%m%d_%H%M`
      job=`basename $0 ".sh"`
      rman  >> ${job}_${start_dt}.log  2>&1 <<eof
      set echo on;
      
      #connect catalog rman/rman@recovery_catalog_database
      connect catalog rman/rman123@rmandb
      connect target / ; #(instance name, not database name)
      
      run {
      allocate CHANNEL dev_2  TYPE 'SBT_TAPE' format '%U' PARMS  'SBT_LIBRARY=/opt/omni/lib/libob2oracle8_64bit.so,ENV=(OB2BARTYPE=Oracle8)';
      allocate CHANNEL dev_3  TYPE 'SBT_TAPE' format '%U' PARMS  'SBT_LIBRARY=/opt/omni/lib/libob2oracle8_64bit.so,ENV=(OB2BARTYPE=Oracle8)';
      allocate CHANNEL dev_4  TYPE 'SBT_TAPE' format '%U' PARMS  'SBT_LIBRARY=/opt/omni/lib/libob2oracle8_64bit.so,ENV=(OB2BARTYPE=Oracle8)';
      
      flashback database to restore point BEFORE_TEST_20130416_5AM;
      sql "alter database open resetlogs";
      release channel dev_2;
      release channel dev_3;
      release channel dev_4;
      
      # create new restore point, which will be used on next day
      sql "create restore point BEFORE_TEST_20130417_5AM";
      }
      show all;
      exit
      eof
      
      echo srvctl status database -d TestDB
      srvctl status database -d TestDB
      
      echo srvctl start instance -d TestDB -i TestDB2 -o mount
      srvctl start instance -d TestDB -i TestDB2 -o mount
      
      echo srvctl status database -d TestDB
      srvctl status database -d TestDB
      
      eof
      Questions:

      1. How can i get the laterst restore point for the database and pass it on the RMAN FLASHBACK command?
      2. How can I create new restore point with todays date suffixed with lable like BEFORE_TEST_20130417_5AM, with in RMAN ?