Showing posts with label RMAN. Show all posts
Showing posts with label RMAN. Show all posts

25 July 2014

How to restore archive logs from rman backup

If some one need archive log to extract on disk for various purpose (cloning/Apply to DR) then we can follow below mention steps. For example purpose I will extract required archive log in /usr/tmp location. If we do not mention location the archive will be extracted to default location i.e $IRACLE_HOME/dbs


Step 1. Connect to rman (Target or catalog)

rman target /

 
Step 2. Example to restore 10 archive log from logseq 112710 to 112720

run
{
set archivelog destination to '/usr/tmp';
restore archivelog from logseq=112710 until logseq=112720 thread 1;
}

Other examples:-

1. Restore single archive log
 
run
{
set archivelog destination to '/usr/tmp';
restore archivelog from logseq=112710  thread 1;
}

2. Restore archive log in RAC environment 
If we want to restore archive log from Node 2 RAC then user thread 2, or use thread 1 for Node 1.
 
run
{
set archivelog destination to '/usr/tmp';
restore archivelog from logseq=112710 until logseq=112720 thread 2;
}

5 June 2014

Duplicate Database Using RMAN backup location 11gR2


Introduction

RMAN has the ability to duplicate a database from a backup. It is possible to create a duplicate database on a remote server with the same file structure, a remote server will a different file structure or the local server with a different file structure.
The article assumes the duplicate database is being created on a separate server, using the same SID (TEST) and the same file structure as the source database. 

  • Create a password file for the duplicate instance.
$ orapwd file=/u01/app/oracle/product/11.2.0/db_1/dbs/orapwPROD password=password entries=10

scp password file to TEST server ($ORACLE_HOME/dbs location) 
  •  Make proper entries in tnsnames.ora in both PROD and TEST database
Sample entry as below mention:-
# Generated by Oracle configuration tools.
PROD =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = prod.localdomain.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PROD) (UR=A)
    )
  )

TEST =
 (DESCRIPTION =
 (ADDRESS = (PROTOCOL = TCP)(HOST = test.localdomain.com)(PORT = 1521))
 (CONNECT_DATA =
 (SERVER = DEDICATED)
 (SERVICE_NAME = TEST)(UR=A)
 )
 )
 
Preparation of TEST database.
        
  •  Create pfile (ORACLE_HOME/dbs/initTEST.ora) with below mention parameters.
*.DB_NAME=TEST
*.DB_UNIQUE_NAME=TEST
*.COMPATIBLE='11.2.0'
*.db_block_size=8192
*.db_files=500
*.diagnostic_dest='/u01/app/test/db/tech_st/11.2.0/admin/TEST_test'
*.db_file_name_convert='/d01/oracle/PROD/data/','/d01/oracle/TEST/data/','/d01/oracle/PROD/archive/','/d01/oracle/TEST/archive/'
*.log_file_name_convert=
'/d01/oracle/PROD/data/','/d01/oracle/TEST/data/','/d01/oracle/PROD/archive/','/d01/oracle/TEST/archive/' *.Memory_TARGET=1068937216

  • Make proper entries in tnsnames.ora and listener.ora
Sample entry is as below mention
cat tnsnames.ora


# Generated by Oracle configuration tools.
PROD =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = prod.localdomain.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PROD) (UR=A)
    )
  )

TEST =
 (DESCRIPTION =
 (ADDRESS = (PROTOCOL = TCP)(HOST = test.localdomain.com)(PORT = 1521))
 (CONNECT_DATA =
 (SERVER = DEDICATED)
 (SERVICE_NAME = TEST)(UR=A)
 )
 )

  • Test connection from both database (PROD/TEST). We should be able to connect sqlplus from both PROD and TEST database.
sqlplus sys/Welcome123@PROD as sysdba
sqlplus sys/Welcome123@TEST as sysdba

  • Connect to the duplicate instance.

$ ORACLE_SID=TEST; export ORACLE_SID $ sqlplus / as sysdba

Start the database in NOMOUNT mode.

SQL> STARTUP NOMOUNT pfile='$ORACLE_HOME/dbs/initTEST.ora';

rman target / sys/sys@prod log=$HOME/restore.log
connect auxiliary sys/sys@TEST
run
{
allocate auxiliary channel d1 type disk;
allocate auxiliary channel d2 type disk;
allocate auxiliary channel d3 type disk;
allocate auxiliary channel d4 type disk;
allocate auxiliary channel d5 type disk;
allocate auxiliary channel d6 type disk;
duplicate database to TEST backup location '/backups/PROD/RMAN/01Jun';
release channel d1;
release channel d2;
release channel d3;
release channel d4;
release channel d5;
release channel d6;
}

Your duplicate database is ready.

sqlplus > select name from v$database;
TEST

cheers!!!

 


29 April 2014

Unregister a Database From RMAN Recovery Catalog

There are multiple ways to unregister a database from an RMAN recovery catalog.
  • UNREGISTER DATABASE (Catalog and Database)
  • UNREGISTER DATABASE (Catalog Only)
  • DBMS_RCVCAT (Catalog Only)
UNREGISTER DATABASE (Catalog and Database)
This option is available from Oracle 10g onward. If you still have access to the database you can start RMAN, connecting to both the target database and the catalog.
rman target=sys/password@TEST catalog=rman/rman@catdb
You may wish to perform some clean-up first, like deleting the existing backups.
RMAN> LIST BACKUP SUMMARY;
RMAN> DELETE BACKUP DEVICE TYPE SBT;
RMAN> DELETE BACKUP DEVICE TYPE DISK;
When ready, use the UNREGISTER DATABASE command.
RMAN> UNREGISTER DATABASE;

OR

RMAN> UNREGISTER DATABASE NOPROMPT;

UNREGISTER DATABASE (Catalog Only)

This option is available from Oracle 10g onward. If you no longer have access to the target database, you can still unregister it from the catalog using the UNREGISTER DATABASE command in RMAN.
Start RMAN, connecting only to the catalog.
rman catalog=rman/rman@catdb
Unregister the database by name.

RMAN> UNREGISTER DATABASE TEST NOPROMPT;
If there is more than one database in the catalog with the same name, you will need to use the DBID to identify the database to unregister. You can find this using the LIST INCARNATION command.

RMAN> LIST INCARNATION OF DATABASE TEST;
Once you have the DBID, you can unregister the database using the following script.
RUN
{ 
  SET DBID 1312293510;
  UNREGISTER DATABASE TEST NOPROMPT;
}

DBMS_RCVCAT (Catalog Only)

If you no longer have access to the target database, you can still unregister it from the catalog using the DBMS_RCVCAT package in SQL.
Connect to the catalog database using SQL*Plus, then query the DB_KEY and DBID values as follows.

SQL> CONNECT rman/rman@catdb
Connected.

SQL> SELECT db_key, dbid, name FROM rc_database WHERE name = 'TEST';

    DB_KEY       DBID NAME
---------- ---------- --------
     23085 1312293510 TEST

1 row selected.

SQL>
The resulting DB_KEY and DBID can then be used to unregister the database using the DBMS_RCVCAT package.
SQL> EXECUTE dbms_rcvcat.unregisterdatabase(23085 , 1312293510);

PL/SQL procedure successfully completed.

SQL>

11 April 2014

How to change RMAN Global script

Connect to Catalog database 

rman target / catalog rman/rman@RMAN

Print RMAN global script 

PRINT GLOBAL SCRIPT level0_backup_full;

Print RMAN global script to a text file


PRINT GLOBAL SCRIPT level0_backup_full TO FILE '/usr/tmp/level0_backup_full.txt';

Modify your text file. 

Update global script from modified file.


REPLACE GLOBAL SCRIPT level0_backup_full FROM FILE '/usr/tmp/level0_backup_full.txt';

Verify again new global script

rman target / catalog rman/rman@RMAN


PRINT GLOBAL SCRIPT level0_backup_full;

5 April 2014

Steps to create RMAN Active duplicate in 11gR2

Steps to create RMAN Active duplicate in 11gR2

Introduction
RMAN has the ability to duplicate, or clone, a database from a backup or from an active database. It is possible to create a duplicate database on a remote server with the same file structure, a remote server will a different file structure or the local server with a different file structure.
The article assumes the active duplicate database is being created on a separate server. In this test case the target database is PROD and duplicate database will be TEST.

Preparation of PROD database
  • Create password file on PROD and scp to TEST DB ($ORACLE_HOME/dbs location)
orapwd file=$ORACLE_HOME/dbs/orapwTEST password=password entries=10

scp password file to TEST server ($ORACLE_HOME/dbs location)
  • Make proper entries in tnsnames.ora in both PROD and TEST database
Sample entry as below mention:-
# Generated by Oracle configuration tools.
PROD =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = dev1.localdomain.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PROD) (UR=A)
    )
  )

TEST =
 (DESCRIPTION =
 (ADDRESS = (PROTOCOL = TCP)(HOST = dev2.localdomain.com)(PORT = 1521))
 (CONNECT_DATA =
 (SERVER = DEDICATED)
 (SERVICE_NAME = TEST)(UR=A)
 )
 )

Preparation of TEST database.
  • Create pfile (ORACLE_HOME/dbs/initTEST.ora)
*.DB_NAME=TEST
*.DB_UNIQUE_NAME=TEST
*.diagnostic_dest='/u01/app/oracle'
*.db_block_size=8192
*.Memory_TARGET=843055104
*.COMPATIBLE= 11.2.0.0.0
*.local_listener='(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = dev2.localdomain.com)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = TEST)(UR=A)))'
*.log_file_name_convert='/u01/app/oracle/oradata/ora11g/','/u01/app/oracle/oradata/TEST/','/u01/app/oracle/oradata/PROD/','/u01/app/oracle/oradata/TEST/'
*.db_file_name_convert='/u01/app/oracle/oradata/ora11g/','/u01/app/oracle/oradata/TEST/','/u01/app/oracle/oradata/PROD/','/u01/app/oracle/oradata/TEST/'


  • Make proper entries in tnsnames.ora and listener.ora
Sample entry is as below mention
cat tnsnames.ora
# Generated by Oracle configuration tools.
PROD =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = dev1.localdomain.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PROD) (UR=A)
    )
  )

TEST =
 (DESCRIPTION =
 (ADDRESS = (PROTOCOL = TCP)(HOST = dev2.localdomain.com)(PORT = 1521))
 (CONNECT_DATA =
 (SERVER = DEDICATED)
 (SERVICE_NAME = TEST)(UR=A)
 )
)

cat listener.ora
INBOUND_CONNECT_TIMEOUT_LISTENER = 0
TEST =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = dev2.localdomain.com)(PORT = 1521))
      )
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
      )
    )
  )

SID_LIST_TEST =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u01/app/oracle/product/11.3.0)
      (PROGRAM = extproc)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = TEST)
      (ORACLE_HOME = /u01/app/oracle/product/11.3.0)
      (SID_NAME = TEST)
    )
  )

ADR_BASE_REPL = /u01/app/oracle

  • Make proper directory structure on TEST DB for Datafile and logfile
  •  Test connection from both database (PROD/TEST). We should be able to connect sqlplus from both PROD and TEST database.
sqlplus sys/Welcome123@PROD as sysdba
sqlplus sys/Welcome123@TEST as sysdba

  • Start TEST database in nomount
export ORACLE_HOME= /u01/app/oracle/product/11.3.0
export ORACLE_SID=TEST
export PATH=$ORACLE_HOME/bin:$PATH

sqlplus >startup nomount pfile=’$ORACLE_HOME/dbs/initTEST.ora’
  • Connect with RMAN
rman target sys/Welcome123@PROD
connect auxiliary sys/Welcome123@TEST

[oracle@dev2 dbs]$ rman target sys/Welcome123@PROD

Recovery Manager: Release 11.2.0.3.0 - Production on Sat Apr 5 11:45:02 2014

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: PROD (DBID=255635113)

RMAN> connect auxiliary sys/Welcome123@TEST

connected to auxiliary database: TEST (not mounted)

RMAN>

DUPLICATE TARGET DATABASE TO "TEST" FROM ACTIVE DATABASE;

SQL> select name from v$database;

NAME
---------
TEST

Sqlplus > create pfile from spfile;

Your TEST database is ready now.