Thursday, September 3, 2015

RMAN DUPLICATE DATABASE WITH CONNECTION TO RECOVERY CATALOG

RMAN DUPLICATE DATABASE WITH CONNECTION TO RECOVERY CATALOG


In this post, I will demonstrate how to duplicate a database using its backups.
This method requires connection to recovery catalog only to get information about the
backups. Connection with the target database is not needed.
********************************
  source database  orcl (ASM)
  Duplicate database  orclt (ASM)
  Recovery catalog database : rcat
***********************************
Overview:
on the source  host
  • - Create recovery catalog in rcat database
  • - Register source database orcl with recovery catalog
  • - BACKUP DATABASE PLUS ARCHIVELOG AND CONTROLFILE while connected to recovery catalog
  • - Copy these backup files to the server where you want to create the duplicate copy.
  • - CREATE PFILE FROM SOURCE DATABASE
on the target host
  • - Add a line in the file /etc/oratab to reflect the database instance(orclt) you are going
  • to copy
  • - create folders
  • - Copy the initialization parameter file from the source database add edit it.
  • - Copy the password file
  • - Startup the duplicate database (orclt) in nomount mode using modified parameter file
  • - Using RMAN  connect to the catalog database(rcat) as target database and duplicate
  • database (orclt) as auxiliary instance
  • - duplicate the database orcl to orclt
———————-
on the source  host
———————-
- Create recovery catalog in rcat database
  .create tablespace to hold recovery catalog data –
sql>create tablespace rcat datafile '+data/rcat01.dbf' size 15m;
  . create recovery catalog owner
sql>create user rcatowner identified by oracle

    default tablespace rcat quota unlimited on rcat;
    grant recovery_catalog_owner to rcatowner;
  . Create recovery catalog
$rman catalog rcatowner/oracle@rcat
RMAN>CREATE CATALOG;
- Register source database orcl with recovery catalog
$RMAN TARGET sys/oracle@orcl CATALOG rcatowner/oracle@rcat
RMAN>REGISTER DATABASE;
– Make a folder to stage the backup
oracle$mkdir /home/orale/stage
– Take the backup of the source database
oracle$. oraenv orcl
         rman target /
RMAN>CONFIGURE CONTROLFILE AUTOBACKUP ON;
     backup database format '/home/oracle/stage/%U.rmb';
     backup archivelog all  format '/home/oracle/stage/arc_%r_%s_%t.log';
The controlfile backup is also required. If you have configured the controlfile
autobackup, the backup would contain the controlfile as well. If you want to be sure,
 ors you have not configured controlfile autobackup, you can backup the controlfile
explicitly.
– CREATE PFILE FROM SOURCE DATABASE
SQL>CREATE PFILE='/u01/app/oracle/oradata/orcl/initsource.ora'
            FROM SPFILE
———————
on the target host.
————————
 — Copy the backup files to the server where you want to create the duplicate copy.
$mkdir -p /home/oracle/stage
 scp sourcehost:/home/oracle/stage/*.rmb desthost::/home/oracle/stage/

– Add a line in the file /etc/oratab to reflect the database instance you are going to    copy:
orclt:/u01/app/oracle/product/11.2.0/db_1:N
– Now set the Oracle SID as the duplicated database SID:
# . oraenv
ORACLE_SID = [orclt] ?
– create folders
 $mkdir -p /u01/app/oracle/oradata/orclt
  mkdir -p /u01/app/oracle/flash_recovery_area/orclt
  mkdir -p /u01/app/oracle/admin/orclt/adump
  mkdir -p /u01/app/oracle/admin/orclt/dpdump
– Copy the initialization parameter file from the main database.
– If u are duplicating on the same host
$cp  /u01/app/oracle/oradata/orcl/initsource.ora
/u01/app/oracle/oradata/orclt/inittarget.ora
OR
– If u are duplicating on the different host
$scp  soucehost:/u01/app/oracle/oradata/orcl/initsource.ora
/u01/app/oracle/oradata/orclt/inittarget.ora
– Edit parameter file
$vi /u01/app/oracle/oradata/orclt/inittarget.ora
   – Change db_name = orclt
   – Edit it to reflect the new locations that might be appropriate
     such as control file locations,audit dump destinations, datafile
     locations, etc.
   – add these lines –
     db_file_name_convert = (“+DATA/orcl”,”+DATA/orclt”)
     log_file_name_convert = (“+DATA/orcl”,”+DATA/orclt”, “+FRA/orcl”,”+FRA/orclt”)
————————————–
– Copy the password file as well
$ cp /u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl  /u01/app/oracle/product/11.2.0/db_1/dbs/orapworclt
OR
$ scp sourcehost:/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl  /u01/app/oracle/product/11.2.0/db_1/dbs/orapworclt

– Startup the duplicate database in nomount mode using modified parameter file
$ . oraenv
ORACLE_SID = [orclt] ?
$sqlplus sys/oracle as sysdba
SQL> startup nomount pfile='/u01/app/oracle/oradata/orclt/inittarget.ora';
          create spfile from pfile='/u01/app/oracle/oradata/orclt/inittarget.ora';

- Using RMAN  connect to the catalog database (rcat) and duplicate database   (orclt) as
auxiliary instance
$rman catalog rcatowner/oracle@rcat  auxiliary sys/oracle@orclt

– duplicate the database orcl to orclt
– the command performs the following steps:
    * Creates an SPFILE
    * Shuts down the instance and restarts it with the new spfile
    * Restores the controlfile from the backup
    * Mounts the database
    * Performs restore of the datafiles. In this stage it creates the files in the
      converted names.
    * Recovers the datafiles up to the time specified and opens the database
RMAN>duplicate  database orcl to orclt;
– check that duplicate database is up
$sqlplus / as sysdba
sql>conn hr/hr
    select * from tab;
– Note that  DBID is different from the main database so it can be backed up
   independently and using the same catalog as well.
SQL> select dbid from v$database;
      DBID
———-
3780202035
SQL>conn sys/oracle@orcl as sysdba
    select dbid from v$database;
      DBID
———-
1327232823

No comments: