Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

commenton Oracle 18c – Table recovery using RMAN Backup

Duplicate a Database
Using RMAN in
Oracle Database 12c
Release 2
Description:-

This is the article which will guide you step-by-step Duplicating a Database Using RMAN in
Oracle Database 12c Release 2

SOURCE DATABASE (ORCL):

Step1:-Copy the password file to target database 

oracle:dbs] scp orapworcl oracle@clone:$ORACLE_HOME/dbs/orapwclone


orapworcl 100% 3584 3.5KB/s 00:00

Step2:-Create pfile from SOURCE database for TARGET database

SQL> show parameter spfile;


NAME     TYPE    VALUE
———————————— ———————
spfile    string /oradb/app/oracle/product/12.2.0.1/db_1/dbs/spfileorcl.ora

SQL> create pfile from spfile;


File created.

Step3:-Copy the pfile to the target database

[oracle@orcl:dbs] scp initorcl.ora oracle@clone:$ORACLE_HOME/dbs/initclone.ora


initorcl.ora 100% 1095 1.1KB/s 00:00

TARGET DATABASE:
Step 4:-Create required directories in the TARGET location

Create adump,datafiles and logfiles location

mkdir -p /oradb/app/oracle/admin/clone/adump
mkdir -p /oradb/app/oracle/oradata/clone/

Step 5:-Edit the db_name and necessary directories name in pfile.

 Edit db_name to new database name


 Add the below the entries for datafiles and logfiles creation

*.db_file_name_convert=’/oradb/app/oracle/oradata/orcl’,’/oradb/app/oracle/oradata/clone’
*.log_file_name_convert=’/oradb/app/oracle/oradata/orcl’,’/oradb/app/oracle/oradata/clone’

vi initclone.ora (PFILE Target Database Clone)

*.audit_file_dest=’/oradb/app/oracle/admin/clone/adump’
*.db_file_name_convert=’/oradb/app/oracle/oradata/orcl’,’/oradb/app/oracle/oradata/clone’

*.log_file_name_convert=’/oradb/app/oracle/oradata/orcl’,’/oradb/app/oracle/oradata/clone’

*.control_files=’/oradb/app/oracle/oradata/clone/control01.ctl’,’/oradb/app/oracle/oradata/
clone/control02.ctl’

*.db_name=’clone’

Step 6:-Set the Environment for CLONE database,

clone()
{
ORACLE_HOME=/oradb/app/oracle/product/12.2.0.1/db_1
export ORACLE_HOME
ORACLE_BASE=/oradb/app/oracle
export ORACLE_BASE
ORACLE_SID=clone
export ORACLE_SID
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:.
export LD_LIBRARY_PATH
LIBPATH=$ORACLE_HOME/lib32:$ORACLE_HOME/lib:/usr/lib:/lib
export LIBPATH
TNS_ADMIN=${ORACLE_HOME}/network/admin
export TNS_ADMIN
PATH=$ORACLE_HOME/bin:$PATH:.
export PATH
}

Step 7:-Open the CLONE database in NOMOUNT state using modified pfile,

SQL>startup pfile nomount=’$ORACLE_HOME/dbs/initclone.ora’


ORACLE instance started.

Total System Global Area 1610612736 bytes


Fixed Size 8621232 bytes
Variable Size 1040188240 bytes
Database Buffers 553648128 bytes
Redo Buffers 8155136 bytes

Step 8:-Configure the listener & tnsnames on both server

cd $ORACLE_HOME/network/admin

LISTENER ENTRY:

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = orcl.localdomain.com)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = clone.localdomain.com)(PORT = 1521))
)

TNSNAMES ENTRY:
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = orcl.localdomain.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl.localdomain.com)
)
)

CLONE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = clone.localdomain.com)(PORT = 1521))
(CONNECT_DATA =
(out = DEDICATED)
(SERVICE_NAME = clone.localdomain.com)
)
)

RMAN Active Duplication:

NOFILENAMECHECK: If you want the duplicate filenames to be the same as the target
filenames, and if the databases are in different hosts, then you must
specify NOFILENAMECHECK

db_file_name_convert: This parameter specifies from where to where the datafiles should be


cloned.

log_file_name_convert:This parameter specifies from where to where the redo logfiles should
be cloned

Connect as auxiliary database to create a new database in TARGET location

[oracle@clone:admin clone] rman target sys/oracle@orcl auxiliary sys/oracle

Recovery Manager: Release 12.2.0.1.0 – Production on Fri May 25 23:17:41 2018


Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1504791090)
connected to auxiliary database: CLONE (not mounted)

RMAN> duplicate database to ‘clone’ from active database NOFILENAMECHECK;


Starting Duplicate Db at 25-MAY-18 23:17:57

using target database control file instead of recovery catalog

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=35 device type=DISK

current log archived

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 1610612736 bytes

Fixed Size 8621232 bytes

Variable Size 1040188240 bytes

Database Buffers 553648128 bytes

Redo Buffers 8155136 bytes

contents of Memory Script:

sql clone "alter system set db_name =

''ORCL'' comment=

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

sql clone "alter system set db_unique_name =

''clone'' comment=

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

shutdown clone immediate;

startup clone force nomount

restore clone from service 'ORCL' primary controlfile;

alter clone database mount;

}
executing Memory Script

sql statement: alter system set db_name = ''ORCL'' comment= ''Modified by RMAN
duplicate'' scope=spfile

sql statement: alter system set db_unique_name = ''clone'' comment= ''Modified


by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area 1610612736 bytes

Fixed Size 8621232 bytes

Variable Size 1040188240 bytes

Database Buffers 553648128 bytes

Redo Buffers 8155136 bytes

Starting restore at 25-MAY-18 23:18:46

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=34 device type=DISK

channel ORA_AUX_DISK_1: starting datafile backup set restore

channel ORA_AUX_DISK_1: using network backup set from service ORCL

channel ORA_AUX_DISK_1: restoring control file

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

output file name=/oradb/app/oracle/oradata/clone/control01.ctl


output file name=/oradb/app/oracle/oradata/clone/control02.ctl

Finished restore at 25-MAY-18 23:18:47

database mounted

contents of Memory Script:

set newname for datafile 1 to

"/oradb/app/oracle/oradata/clone/system01.dbf";

set newname for datafile 3 to

"/oradb/app/oracle/oradata/clone/sysaux01.dbf";

set newname for datafile 4 to

"/oradb/app/oracle/oradata/clone/undotbs01.dbf";

set newname for datafile 7 to

"/oradb/app/oracle/oradata/clone/users01.dbf";

restore

from nonsparse from service

'ORCL' clone database;

sql 'alter system archive log current';

executing Memory Script


executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 25-MAY-18 23:18:52

using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore

channel ORA_AUX_DISK_1: using network backup set from service ORCL

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

channel ORA_AUX_DISK_1: restoring datafile 00001 to


/oradb/app/oracle/oradata/clone/system01.dbf

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:37

channel ORA_AUX_DISK_1: starting datafile backup set restore

channel ORA_AUX_DISK_1: using network backup set from service ORCL

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

channel ORA_AUX_DISK_1: restoring datafile 00003 to


/oradb/app/oracle/oradata/clone/sysaux01.dbf

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:26

channel ORA_AUX_DISK_1: starting datafile backup set restore

channel ORA_AUX_DISK_1: using network backup set from service ORCL


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

channel ORA_AUX_DISK_1: restoring datafile 00004 to


/oradb/app/oracle/oradata/clone/undotbs01.dbf

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:05

channel ORA_AUX_DISK_1: starting datafile backup set restore

channel ORA_AUX_DISK_1: using network backup set from service ORCL

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

channel ORA_AUX_DISK_1: restoring datafile 00007 to


/oradb/app/oracle/oradata/clone/users01.dbf

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

Finished restore at 25-MAY-18 23:20:01

sql statement: alter system archive log current

current log archived

contents of Memory Script:

restore clone force from service 'ORCL'

archivelog from scn 1788668;

switch clone datafile all;

executing Memory Script


Starting restore at 25-MAY-18 23:20:02

using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting archived log restore to default destination

channel ORA_AUX_DISK_1: using network backup set from service ORCL

channel ORA_AUX_DISK_1: restoring archived log

archived log thread=1 sequence=16

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

channel ORA_AUX_DISK_1: starting archived log restore to default destination

channel ORA_AUX_DISK_1: using network backup set from service ORCL

channel ORA_AUX_DISK_1: restoring archived log

archived log thread=1 sequence=17

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

Finished restore at 25-MAY-18 23:20:05

datafile 1 switched to datafile copy

input datafile copy RECID=5 STAMP=977095205 file


name=/oradb/app/oracle/oradata/clone/system01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=6 STAMP=977095205 file


name=/oradb/app/oracle/oradata/clone/sysaux01.dbf

datafile 4 switched to datafile copy


input datafile copy RECID=7 STAMP=977095205 file
name=/oradb/app/oracle/oradata/clone/undotbs01.dbf

datafile 7 switched to datafile copy

input datafile copy RECID=8 STAMP=977095205 file


name=/oradb/app/oracle/oradata/clone/users01.dbf

contents of Memory Script:

set until scn 1789727;

recover

clone database

delete archivelog;

executing Memory Script

executing command: SET until clause

Starting recover at 25-MAY-18 23:20:05

using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 16 is already on disk as file


/oradb/app/oracle/product/12.2.0.1/db_1/dbs/arch1_16_977010357.dbf

archived log for thread 1 with sequence 17 is already on disk as file


/oradb/app/oracle/product/12.2.0.1/db_1/dbs/arch1_17_977010357.dbf
archived log file
name=/oradb/app/oracle/product/12.2.0.1/db_1/dbs/arch1_16_977010357.dbf
thread=1 sequence=16

archived log file


name=/oradb/app/oracle/product/12.2.0.1/db_1/dbs/arch1_17_977010357.dbf
thread=1 sequence=17

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

Finished recover at 25-MAY-18 23:20:06

Oracle instance started

Total System Global Area 1610612736 bytes

Fixed Size 8621232 bytes

Variable Size 1040188240 bytes

Database Buffers 553648128 bytes

Redo Buffers 8155136 bytes

contents of Memory Script:

sql clone "alter system set db_name =

''CLONE'' comment=

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

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

}
executing Memory Script

sql statement: alter system set db_name = ''CLONE'' comment= ''Reset to


original value by RMAN'' scope=spfile

sql statement: alter system reset db_unique_name scope=spfile

Oracle instance started

Total System Global Area 1610612736 bytes

Fixed Size 8621232 bytes

Variable Size 1040188240 bytes

Database Buffers 553648128 bytes

Redo Buffers 8155136 bytes

sql statement: CREATE CONTROLFILE REUSE SET DATABASE "CLONE" RESETLOGS


ARCHIVELOG

MAXLOGFILES 16

MAXLOGMEMBERS 3

MAXDATAFILES 100

MAXINSTANCES 8

MAXLOGHISTORY 292

LOGFILE

GROUP 1 ( '/oradb/app/oracle/oradata/clone/redo01.log' ) SIZE 200 M REUSE,

GROUP 2 ( '/oradb/app/oracle/oradata/clone/redo02.log' ) SIZE 200 M REUSE,


GROUP 3 ( '/oradb/app/oracle/oradata/clone/redo03.log' ) SIZE 200 M REUSE

DATAFILE

'/oradb/app/oracle/oradata/clone/system01.dbf'

CHARACTER SET AL32UTF8

contents of Memory Script:

set newname for tempfile 1 to

"/oradb/app/oracle/oradata/clone/temp01.dbf";

switch clone tempfile all;

catalog clone datafilecopy "/oradb/app/oracle/oradata/clone/sysaux01.dbf",

"/oradb/app/oracle/oradata/clone/undotbs01.dbf",

"/oradb/app/oracle/oradata/clone/users01.dbf";

switch clone datafile all;

executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /oradb/app/oracle/oradata/clone/temp01.dbf in control


file

cataloged datafile copy


datafile copy file name=/oradb/app/oracle/oradata/clone/sysaux01.dbf RECID=1
STAMP=977095231

cataloged datafile copy

datafile copy file name=/oradb/app/oracle/oradata/clone/undotbs01.dbf RECID=2


STAMP=977095231

cataloged datafile copy

datafile copy file name=/oradb/app/oracle/oradata/clone/users01.dbf RECID=3


STAMP=977095231

datafile 3 switched to datafile copy

input datafile copy RECID=1 STAMP=977095231 file


name=/oradb/app/oracle/oradata/clone/sysaux01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=2 STAMP=977095231 file


name=/oradb/app/oracle/oradata/clone/undotbs01.dbf

datafile 7 switched to datafile copy

input datafile copy RECID=3 STAMP=977095231 file


name=/oradb/app/oracle/oradata/clone/users01.dbf

contents of Memory Script:

Alter clone database open resetlogs;

executing Memory Script

database opened
Finished Duplicate Db at 25-MAY-18 23:21:07

Step 9:-Verify the status of TARGET database status,

SQL> select name,open_mode from v$database;

NAME      OPEN_MODE
——   — ——–
CLONE     READ WRITE

You might also like