Restore archivelogs

How the Oracle DBA can restore archivelogs from tape with an Oracle RMAN Script:

DBA Oracle
Compatibility: Oracle 8i 9i 10g 11g
Creator: Vincent Fenoll – Montreal

 run {      
	allocate channel t1 type 'sbt_tape' parms 'ENV=(TDPO_OPTFILE=xxxxxx)';
	restore archivelog from logseq 2212 until logseq 2213 thread 1;
	release channel t1;
     }

Duplicate db using RMAN script

################################################
#
# Compatible: Oracle 8i 9i 10g 11g
#
################################################
#
# Duplicate a database until time…
# Database must be in « startup nomount » mode
#
################################################


connect catalog rman/****@rman
connect target sys/****@****.world
connect auxiliary / ;
run {
        set until time= "to_date('25/08/2009 06:18:01','dd/mm/yyyy hh24:mi:ss')";

        # if restoring from tape (else Allocate type disk):
        allocate channel ch1 type 'sbt_tape' parms 'ENV=(NSR_SERVER=*****,NSR_DATA_VOLUME_POOL=*****,NSR_CLIENT=*****)';
        allocate auxiliary channel aux1  type 'sbt_tape' parms 'ENV=(NSR_SERVER=*****,NSR_DATA_VOLUME_POOL=*****,NSR_CLIENT=*****)';
        duplicate target database to MYNEWDB nofilenamecheck;
        release channel ch1;
}

Restore until time rman script

################################################
#
# Compatible: Oracle 8i 9i 10g 11g
#
################################################
#
# Restore a database until time...
# Database must be in "startup mount" mode
#
################################################

connect target /
connect catalog rman/***@rman

RUN
{
  # if restoring from tape (else Allocate type disk):
  ALLOCATE CHANNEL chan1 TYPE 'SBT_TAPE';
  # SEND 'NSR_ENV=(NSR_SERVER=xxxxx, NSR_DATA_VOLUME_POOL=xxxxx)';

  set until time= "to_date('02/03/2011 17:00:00','dd/mm/yyyy hh24:mi:ss')";
  RESTORE DATABASE;
  RECOVER DATABASE;
  RELEASE CHANNEL chan1;
}

Delete from catalogue

-- ################################################
-- # Creator: Vincent Fenoll, Arnaud Michel
-- # Compatible: Oracle 8i 9i 10g
-- #
-- ################################################
-- #
-- # Delete an Oracle database from the RMAN catalogue
-- #
-- ################################################

In RMAN database:
sqlplus rman/****@rman


-- PART I: Unregister One Database

SQL> SELECT db_key, db_id FROM db WHERE db_id = 1231274694;
This query should return exactly one row.
DB_KEY DB_ID
---------- ----------
1 1237603294
1 row selected.

SQL> EXECUTE dbms_rcvcat.unregisterdatabase(db_key, db_id)


-- PART II: Unregister several databases with a PL*SQL Loop

set serveroutput on
exec dbms_output.enable(1000000);
DECLARE 
CURSOR C_DBKEY IS
  SELECT db_key, db_id FROM db WHERE db_id in (838734099,2567483700,4125117868,2420232503);

BEGIN
 For Cur IN C_DBKEY Loop
     dbms_rcvcat.unregisterdatabase(cur.db_key, cur.db_id);
     -- dbms_output.put_line( 'exec dbms_rcvcat.unregisterdatabase(' || To_char( Cur.db_key ) || ' , ' || Cur.db_id  || ');' ) ;
 End loop ;
END;
/

Duplicate db using Shell & RMAN

# Author: Vincent Fenoll another Oracle DBA Montreal

#!/usr/bin/ksh
# SCRIPT: duplicate_db_from_time.sh
################################################
#
# Created: 2009/01/01
# Compatible: Oracle 8i 9i 10g 11g
#
################################################
#
# Duplicate database using rman
#
################################################
#
# PRE-REQUISITES:
#    * Instance: NOMOUNT
#    * local variables setted
#    * Oracle variables setted: log_file_name_convert, db_file_name_convert
#
# EXAMPLE:    ./duplicate_db_from_time.sh sys/***@OLDBASE rman/***@rman "08-03-2009 06:16:49″ host_source
#
# Please modify with your value  :      duplicate target database to NEWBASE
#
################################################


if [ "$ORACLE_HOME" = "" ]; then
        echo "Erreur: ORACLE_HOME must be defined"
        exit 1
fi

if [ "$1" = "" -o "$2" = "" -o "$3" = "" -o "$4" = "" ]; then
        echo "Synt: $0 [connect_target] [connect_rmancatalog] [date=DD-MM-YYYY HH24:MI:SS] [server_source_name]"
        exit 1
fi

export NLS_DATE_FORMAT="DD-MM-YYYY HH24:MI:SS"

$ORACLE_HOME/bin/rman target $1 rcvcat $2 auxiliary / << EOF run { set until time "to_date('$3', 'DD-MM-YYYY HH24:MI:SS')"; allocate auxiliary channel t1 type 'SBT_TAPE'; -- If using Networker send 'NSR_ENV=(NSR_SERVER=networkerxxx, NSR_DATA_VOLUME_POOL=FULLxxx, NSR_CLIENT=$4)'; set command id to 'rman_duplicate_from_time'; duplicate target database to NEWBASE NOFILENAMECHECK; release channel t1; } exit; EOF egrep "RMAN-|ORA-" /tmp/resto_rman_$$.log > /dev/null
  if [ $? -eq 0 ]
  then
    return 12
  fi

  return 0