oracle db cloning using rman

13
Database Cloning using RMAN with Backup based Duplication on the Local Host Introduction Use the DUPLICATE command to create a copy of a source database. RMAN can create either of the following types of databases: A duplicate database, which is a copy of the source database (or a subset of the source database) with a unique DBID. Because a duplicate database has a unique DBID, it is independent of the source database and can be registered in the same recovery catalog. Typically, duplicate databases are used for testing. A standby database, which is a special copy of the source database (called a primary database in a Data Guard environment) that is updated by applying archived redo log files from the primary database. A standby database is not assigned a new DBID. Prerequisites 1. Backup should be taken. 2. RMAN must be connected as TARGET to the source database, which is the database that is being copied. The source database must be mounted or open. The source database must not be a standby database. 3. RMAN must be connected as AUXILIARY to the instance of the duplicate database. The instance of the duplicate database is called the auxiliary instance. The auxiliary instance must be started with the NOMOUNT option. Prerequisites Specific to Backup-Based Duplication 1. When you execute DUPLICATE without FROM ACTIVE DATABASE, at least one auxiliary channel is required, but no normal channels are required in the source database. 2. When you duplicate the database from backups, all backups and archived redo logs used for creating and recovering the duplicate database must be accessible by the server session on the destination host. If the destination host is not the same as the source host, then you must make backups on disk on the source host available to the destination host with the same full path name as in the source database. RMAN can perform the duplication in any of the following supported modes: 1. Active duplication 2. RMAN duplicates the files directly from either an open or mounted database. 3. Backup-based duplication without a target connection

Upload: subramanian-k

Post on 19-Jan-2016

69 views

Category:

Documents


4 download

DESCRIPTION

DB CLONING

TRANSCRIPT

Database Cloning using RMAN with Backup based

Duplication on the Local Host

Introduction

Use the DUPLICATE command to create a copy of a source database. RMAN can create either of the

following types of databases:

A duplicate database, which is a copy of the source database (or a subset of the source database) with

a unique DBID. Because a duplicate database has a unique DBID, it is independent of the source

database and can be registered in the same recovery catalog. Typically, duplicate databases are used for

testing.

A standby database, which is a special copy of the source database (called a primary database in a

Data Guard environment) that is updated by applying archived redo log files from the primary database.

A standby database is not assigned a new DBID.

Prerequisites

1. Backup should be taken.

2. RMAN must be connected as TARGET to the source database, which is the database that is being

copied. The source database must be mounted or open. The source database must not be a

standby database.

3. RMAN must be connected as AUXILIARY to the instance of the duplicate database. The instance

of the duplicate database is called the auxiliary instance. The auxiliary instance must be started

with the NOMOUNT option.

Prerequisites Specific to Backup-Based Duplication

1. When you execute DUPLICATE without FROM ACTIVE DATABASE, at least one auxiliary channel

is required, but no normal channels are required in the source database.

2. When you duplicate the database from backups, all backups and archived redo logs used for

creating and recovering the duplicate database must be accessible by the server session on the

destination host. If the destination host is not the same as the source host, then you must make

backups on disk on the source host available to the destination host with the same full path

name as in the source database.

RMAN can perform the duplication in any of the following supported modes:

1. Active duplication

2. RMAN duplicates the files directly from either an open or mounted database.

3. Backup-based duplication without a target connection

4. RMAN creates duplicate files from pre-existing RMAN backups and copies. The DUPLICATE

command must have been issued with the DATABASE clause. This form requires a connection to

an auxiliary instance and a recovery catalog.

5. This mode is useful when the target database is not available or a connection to it is not

desirable (as mandated by security policy restrictions or a firewall).

6. Backup-based duplication with a target connection.

7. RMAN creates duplicate files from pre-existing RMAN backups and copies.

8. Backup-based duplication without connection to target and recovery catalog

9. RMAN creates duplicate files from RMAN backups and copies that were placed in a designated

BACKUP LOCATION.

Procedure

1. Create Listener for the Database and add the entry of the following

SID_LIST_LISTENER_TEST =

(SID_LIST =

(SID_DESC =

(SID_NAME = TEST)

(ORACLE_HOME = /oracle/product/11.2.0/dbhome_1)

)

)

2. Make entry in tnsnames.ora

TEST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.10)(PORT = 1529))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = TEST)

)

)

3. Create an Oracle password file for the auxiliary instance.

$orapwd file=/oracle/product/11.2.0/dbhome_1/dbs/orapwTEST password=<passwd>

entries=10

4. Create an initialization parameter file for the auziliary instance and make the following changes.

SQL> create pfile='/oracle/product/11.2.0/dbhome_1/dbs/initTEST.ora' from spfile;

File created.

vi initTEST.ora

*.LOG_FILE_NAME_CONVERT='/data7/redo/SRCTEST/','/data9/redo/TEST/','/data8/red

o/SRCTEST/','/data10/redo/TEST/','/index4/redo/SRCTEST/','/index5/redo/TEST/'

*.control_files='/data9/controlfile/TEST/control01.ctl','/data10/controlfile/TEST/control

02.ctl','/index5/controlfile/TEST/control03.ctl' #Restore Controlfile

*.audit_file_dest='/oracle/admin/TEST/adump'

*.audit_trail='db'

*.compatible='11.2.0.0.0'

*.db_block_size=8192

*.db_domain=''

*.db_files=2000

*.db_name='TEST'

*.db_unique_name=’TEST’

*.instance_name=’TEST’

*.db_writer_processes=8

*.diagnostic_dest='/oracle'

*.log_archive_dest_1='LOCATION=/archive4/archives/TEST'

*.log_archive_format='%t_%s_%r.arc'

*.memory_max_target=12G

*.memory_target=10G

*.open_cursors=1000

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.standby_file_management=’AUTO’

*.undo_tablespace=’UNDOTBS1’

5. Create directories necessary to start the duplicate database.

$mkdir –p /data9/tbs/TEST/

$mkdir –p /data9/redo/TEST/

$mkdir –p /data9/controlfile/TEST/

$mkdir –p /data10 /tbs/TEST/

$mkdir –p /data10 /redo/TEST/

$mkdir –p /data10 /controlfile/TEST/

$mkdir –p /index5/tbs/TEST/

$mkdir –p /index5/redo/TEST/

$mkdir –p /index5/controlfile/TEST/

$mkdir –p /archive4/archives/TEST

$mkdir –p /oracle/admin/TEST/adump

6. Connect to the auxiliary instance.

$ORACLE_SID=TEST; export ORACLE_SID

$ sqlplus / as sysdba

7. Start the auxiliary instance with SQL*Plus.

SQL> STARTUP NOMOUNT pfile='/oracle/product/11.2.0/dbhome_1/initTEST.ora;

ORACLE instance started.

Total System Global Area 1.2827E+10 bytes

Fixed Size 2233480 bytes

Variable Size 7583304568 bytes

Database Buffers 5234491392 bytes

Redo Buffers 7340032 bytes

SQL>

8. Connect to RMAN

$rman auxiliary sys/<passwd>@TEST

run {

allocate auxiliary channel c1 type disk;

allocate auxiliary channel c2 type disk;

set newname for datafile 1 to '/data9/tbs/TEST/system01.dbf';

set newname for datafile 2 to '/data9 /tbs/TEST/sysaux01.dbf';

set newname for datafile 3 to '/data9 /tbs/TEST/undotbs01.dbf';

set newname for datafile 4 to '/data9 /tbs/TEST/users01.dbf';

set newname for datafile 33 to '/data9/tbs/TEST/undotbs02.dbf';

set newname for tempfile 1 to '/data9/tbs/TEST/temp01.dbf';

duplicate target database to TEST

backup location '/backup5/rmanbkp/08052014';

}

Output of the above command:

allocated channel: c1

channel c1: SID=156 device type=DISK

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting Duplicate Db at 09-MAY-14

contents of Memory Script:

{

sql clone "create spfile from memory";

}

executing Memory Script

sql statement: create spfile from memory

contents of Memory Script:

{

shutdown clone immediate;

startup clone nomount;

}

executing Memory Script

Oracle instance shut down

connected to auxiliary database (not started)

Oracle instance started

Total System Global Area 12827369472 bytes

Fixed Size 2233480 bytes

Variable Size 7616859000 bytes

Database Buffers 5200936960 bytes

Redo Buffers 7340032 bytes

allocated channel: c1

channel c1: SID=156 device type=DISK

contents of Memory Script:

{

sql clone "alter system set db_name =

''SRCTEST'' comment=

''Modified by RMAN duplicate'' scope=spfile";

sql clone "alter system set db_unique_name =

''TEST'' comment=

''Modified by RMAN duplicate'' scope=spfile";

shutdown clone immediate;

startup clone force nomount

restore clone primary controlfile from

'/backup5/rmanbkp/08052014/SRCTEST_CTR_T847062738_S7158.bkp';

alter clone database mount;

}

executing Memory Script

sql statement: alter system set db_name = ''SRCTEST'' comment= ''Modified by RMAN

duplicate'' scope=spfile

sql statement: alter system set db_unique_name = ''TEST'' comment= ''Modified by RMAN

duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area 12827369472 bytes

Fixed Size 2233480 bytes

Variable Size 7616859000 bytes

Database Buffers 5200936960 bytes

Redo Buffers 7340032 bytes

allocated channel: c1

channel c1: SID=156 device type=DISK

Starting restore at 09-MAY-14

channel c1: restoring control file

channel c1: restore complete, elapsed time: 00:00:01

output file name=/data9/controlfile/TEST/control01.ctl

output file name=/data10/controlfile/TEST/control02.ctl

output file name=/index5/controlfile/TEST/control03.ctl

Finished restore at 09-MAY-14

database mounted

contents of Memory Script:

{

set until scn 426152786;

set newname for datafile 1 to

"/data9/tbs/TEST/system01.dbf";

set newname for datafile 2 to

"/data9/tbs/TEST/sysaux01.dbf";

set newname for datafile 3 to

"/data9/tbs/TEST/undotbs01.dbf";

set newname for datafile 4 to

"/data9/tbs/TEST/users01.dbf";

set newname for datafile 33 to

"/data9/tbs/TEST/undotbs02.dbf";

restore

clone database

;

}

executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 09-MAY-14

channel c1: starting datafile backup set restore

channel c1: specifying datafile(s) to restore from backup set

channel c1: restoring datafile 00001 to /data9/tbs/TEST/system01.dbf

channel c1: restoring datafile 00003 to /data9/tbs/TEST/undotbs01.dbf

channel c1: restoring datafile 00033 to /data9/tbs/TEST/undotbs02.dbf

channel c1: reading from backup piece

/backup5/rmanbkp/08052014/SRCTEST_T847062007_S7151.bkp

channel c1: piece handle=/backup5/rmanbkp/08052014/SRCTEST_T847062007_S7151.bkp

tag=TAG20140508T230007

channel c1: restored backup piece 1

channel c1: restore complete, elapsed time: 00:03:45

channel c1: starting datafile backup set restore

channel c1: specifying datafile(s) to restore from backup set

channel c1: restoring datafile 00002 to /data9/tbs/TEST/sysaux01.dbf

channel c1: restoring datafile 00004 to /data9/tbs/TEST/users01.dbf

contents of Memory Script:

{

switch clone datafile all;

}

executing Memory Script

contents of Memory Script:

{

catalog clone datafilecopy "/data9/tbs/TEST/system01.dbf",

"/data9/tbs/TEST/sysaux01.dbf",

"/data9/tbs/TEST/undotbs01.dbf",

"/data9/tbs/TEST/users01.dbf",

"/data9/tbs/TEST/undotbs02.dbf",

switch clone datafile 1 to datafilecopy

"/data9/tbs/TEST/system01.dbf";

switch clone datafile 2 to datafilecopy

"/data9/tbs/TEST/sysaux01.dbf";

switch clone datafile 3 to datafilecopy

"/data9/tbs/TEST/undotbs01.dbf";

switch clone datafile 4 to datafilecopy

"/data9/tbs/TEST/users01.dbf";

switch clone datafile 33 to datafilecopy

"/data9/tbs/TEST/undotbs02.dbf";

switch clone datafile all;

}

executing Memory Script

cataloged datafile copy

datafile copy file name=/data9/tbs/TEST/system01.dbf RECID=2 STAMP=847137151

cataloged datafile copy

datafile copy file name=/data9/tbs/TEST/sysaux01.dbf RECID=3 STAMP=847137151

cataloged datafile copy

datafile copy file name=/data9/tbs/TEST/undotbs01.dbf RECID=4 STAMP=847137151

cataloged datafile copy

datafile copy file name=/data9/tbs/TEST/users01.dbf RECID=5 STAMP=847137151

cataloged datafile copy

datafile copy file name=/data9/tbs/TEST/undotbs02.dbf RECID=34 STAMP=847137151

datafile 1 switched to datafile copy

input datafile copy RECID=2 STAMP=847137857 file name=/data9/tbs/TEST/system01.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=3 STAMP=847137857 file name=/data9/tbs/TEST/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=4 STAMP=847137857 file name=/data9/tbs/TEST/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=5 STAMP=847137857 file name=/data9/tbs/TEST/users01.dbf

datafile 33 switched to datafile copy

input datafile copy RECID=34 STAMP=847137857 file name=/data9/tbs/TEST/undotbs02.dbf

contents of Memory Script:

{

set until scn 426152786;

recover

clone database

delete archivelog

;

}

executing Memory Script

executing command: SET until clause

Starting recover at 09-MAY-14

starting media recovery

channel c1: starting archived log restore to default destination

channel c1: restoring archived log

archived log thread=1 sequence=97839

channel c1: restoring archived log

archived log thread=1 sequence=97840

channel c1: restoring archived log

archived log thread=1 sequence=97841

channel c1: reading from backup piece

/backup5/rmanbkp/08052014/TEST_ARC_T847062750_S7179.bkp

channel c2: starting archived log restore to default destination

channel c2: restoring archived log

archived log thread=1 sequence=97842

channel c2: reading from backup piece

/backup5/rmanbkp/08052014/TEST_ARC_T847062750_S7180.bkp

channel c1: piece handle=/backup5/rmanbkp/08052014/TEST_ARC_T847062750_S7179.bkp

tag=TAG20140508T231220

channel c1: restored backup piece 1

channel c1: restore complete, elapsed time: 00:00:01

archived log file name=/archive4/archives/TEST/1_97839_802349084.arc thread=1

sequence=97839

channel clone_default: deleting archived log(s)

archived log file name=/archive4/archives/TEST/1_97839_802349084.arc RECID=2

STAMP=847137862

archived log file name=/archive4/archives/TEST/1_97840_802349084.arc thread=1

sequence=97840

channel clone_default: deleting archived log(s)

archived log file name=/archive4/archives/TEST/1_97840_802349084.arc RECID=1

STAMP=847137861

archived log file name=/archive4/archives/TEST/1_97841_802349084.arc thread=1

sequence=97841

channel clone_default: deleting archived log(s)

archived log file name=/archive4/archives/TEST/1_97841_802349084.arc RECID=4

STAMP=847137862

channel c2: piece handle=/backup5/rmanbkp/08052014/TEST_ARC_T847062750_S7180.bkp

tag=TAG20140508T231220

channel c2: restored backup piece 1

channel c2: restore complete, elapsed time: 00:00:03

archived log file name=/archive4/archives/TEST/1_97842_802349084.arc thread=1

sequence=97842

channel clone_default: deleting archived log(s)

archived log file name=/archive4/archives/TEST/1_97842_802349084.arc RECID=3

STAMP=847137862

media recovery complete, elapsed time: 00:00:01

Finished recover at 09-MAY-14

Oracle instance started

Total System Global Area 12827369472 bytes

Fixed Size 2233480 bytes

Variable Size 7616859000 bytes

Database Buffers 5200936960 bytes

Redo Buffers 7340032 bytes

contents of Memory Script:

{

sql clone "alter system set db_name =

''TEST'' comment=

''Reset to original value by RMAN'' scope=spfile";

sql clone "alter system reset db_unique_name scope=spfile";

shutdown clone immediate;

startup clone nomount;

}

executing Memory Script

sql statement: alter system set db_name = ''TEST'' comment= ''Reset to original value by

RMAN'' scope=spfile

sql statement: alter system reset db_unique_name scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)

Oracle instance started

Total System Global Area 12827369472 bytes

Fixed Size 2233480 bytes

Variable Size 7616859000 bytes

Database Buffers 5200936960 bytes

Redo Buffers 7340032 bytes

allocated channel: c1

channel c1: SID=156 device type=DISK

allocated channel: c2

channel c2: SID=189 device type=DISK

sql statement: CREATE CONTROLFILE REUSE SET DATABASE "TEST" RESETLOGS ARCHIVELOG

MAXLOGFILES 40

MAXLOGMEMBERS 3

MAXDATAFILES 100

MAXINSTANCES 8

MAXLOGHISTORY 18688

LOGFILE

GROUP 1 ( '/index5/redo/TEST/redo01b.log', '/data9/redo/TEST/redo01a.log' ) SIZE 50 M

REUSE,

GROUP 2 ( '/data9/redo/TEST/redo02b.log', '/data10/redo/TEST/redo02a.log' ) SIZE 50 M

REUSE,

GROUP 3 ( '/index5/redo/TEST/redo03a.log', '/data10/redo/TEST/redo03b.log' ) SIZE 50 M

REUSE,

GROUP 4 ( '/data9/redo/TEST/redo04a.log', '/index5/redo/TEST/redo04b.log' ) SIZE 50 M

REUSE,

GROUP 5 ( '/data10/redo/TEST/redo05a.log', '/data9/redo/TEST/redo05b.log' ) SIZE 50 M

REUSE,

GROUP 6 ( '/index5/redo/TEST/redo06a.log', '/data10/redo/TEST/redo06b.log' ) SIZE 50 M

REUSE

DATAFILE

'/data9/tbs/TEST/system01.dbf'

CHARACTER SET WE8ISO8859P1

contents of Memory Script:

{

set newname for tempfile 1 to

"/data9/tbs/TEST/temp01.dbf";

set newname for tempfile 2 to

"/data9/tbs/TEST/temp_TEST_01.dbf";

switch clone tempfile all;

catalog clone datafilecopy "/data9/tbs/TEST/sysaux01.dbf",

"/data9/tbs/TEST/undotbs01.dbf",

"/data9/tbs/TEST/users01.dbf",

"/data9/tbs/TEST/undotbs02.dbf",

switch clone datafile all;

switch clone datafile 2 to datafilecopy

"/data9/tbs/TEST/sysaux01.dbf";

switch clone datafile 3 to datafilecopy

"/data9/tbs/TEST/undotbs01.dbf";

switch clone datafile 4 to datafilecopy

"/data9/tbs/TEST/users01.dbf";

switch clone datafile 33 to datafilecopy

"/data9/tbs/TEST/undotbs02.dbf";

}

executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /data9/tbs/TEST/temp01.dbf in control file

cataloged datafile copy

datafile copy file name=/data9/tbs/TEST/sysaux01.dbf RECID=1 STAMP=847137888

cataloged datafile copy

datafile copy file name=/data9/tbs/TEST/undotbs01.dbf RECID=2 STAMP=847137888

cataloged datafile copy

datafile copy file name=/data9/tbs/TEST/users01.dbf RECID=3 STAMP=847137888

cataloged datafile copy

datafile copy file name=/data9/tbs/TEST/undotbs02.dbf RECID=32 STAMP=847137889

datafile 2 switched to datafile copy

input datafile copy RECID=1 STAMP=847137888 file name=/data9/tbs/TEST/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=2 STAMP=847137888 file name=/data9/tbs/TEST/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=3 STAMP=847137888 file name=/data9/tbs/TEST/users01.dbf

datafile 33 switched to datafile copy

input datafile copy RECID=32 STAMP=847137889 file name=/data9/tbs/TEST/undotbs02.dbf

Reenabling controlfile options for auxiliary database

Executing: alter database force logging

contents of Memory Script:

{

Alter clone database open resetlogs;

}

executing Memory Script

database opened

Finished Duplicate Db at 09-MAY-14

released channel: c1

released channel: c2

Recovery Manager complete.