rman duplicate (Local 복제테스트)
원격이 아닌 Local 환경에서 rman dulicate 테스트를 해 보자..
- 현재 Single 19c 환경에 ORCL 이라는 DB가 있다.
필요에 의해 ORCL2 이라는 이름으로 DB 복제하여 생성하고자 할 경우 아래과 같이 진행...
전체조건 : Source가 Archive mode 이여야 가능함 !!
테스트 환경은 19.23 으로 진행
1. parameter 화일 생성
vi /oracle/app/oracle/product/19.0.0/dbs/initORCL2.ora
DB_NAME=ORCL2
2. passwd 화일 생성
$ORACLE_HOME/dbs/orapwd file=orapwORCL2 password=oracle entries=10 format=12 force=y
3. 접속환경 구성
listener.ora 에 추가
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ora19c)(PORT = 1522))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ORCL2)
(ORACLE_HOME = /oracle/app/oracle/product/19.0.0)
(SID_NAME = ORCL2)
)
)
tnsnames.ora 에 추가
ORCL2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ora19c)(PORT = 1522))
)
(CONNECT_DATA =
(SERVICE_NAME = ORCL2)
)
)
[ORCL2]oracle@ora19c:/home/oracle# lsnrctl status
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 20-AUG-2024 16:02:21
Copyright (c) 1991, 2024, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.140)(PORT=1522)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date 20-AUG-2024 14:52:10
Uptime 0 days 1 hr. 10 min. 11 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /oracle/app/oracle/product/19.0.0/network/admin/listener.ora
Listener Log File /oracle/app/oracle/diag/tnslsnr/ora19c/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.140)(PORT=1522)))
Services Summary...
Service "ORCL" has 1 instance(s).
Instance "ORCL", status READY, has 1 handler(s) for this service...
Service "ORCL2" has 1 instance(s).
Instance "ORCL2", status UNKNOWN, has 1 handler(s) for this service...
Service "ORCLXDB" has 1 instance(s).
Instance "ORCL", status READY, has 1 handler(s) for this service...
The command completed successfully
3. 디렉토리 생성
mkdir -p /oracle/app/oracle/oradata/ORCL2
mkdir -p /oracle/app/oracle/admin/ORCL2/adump
mkdir -p /oracle/archive2
5. nomount 로 DB기동
export ORACLE_SID=ORCL2
sqlplus "/as sysdba"
startup nomount pfile=/oracle/app/oracle/product/19.0.0/dbs/initORCL2.ora
6. rman 접속
! rman target sys/oracle@ORCL auxiliary sys/oracle@ORCL2
RMAN>
DUPLICATE DATABASE TO ORCL2
FROM ACTIVE DATABASE
SPFILE
parameter_value_convert ('ORCL','ORCL2')
set db_file_name_convert='/oracle/app/oracle/oradata/ORCL/','/oracle/app/oracle/oradata/ORCL2/'
set log_file_name_convert='/oracle/app/oracle/oradata/ORCL/','/oracle/app/oracle/oradata/ORCL2/'
set control_files='/oracle/app/oracle/oradata/ORCL2/control01.ctl','/oracle/app/oracle/oradata/ORCL2/control02.ctl'
set log_archive_dest_1='location=/oracle/archive2'
;
- 여기서부터는 진행 로그
Starting Duplicate Db at 20-AUG-24
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=38 device type=DISK
current log archived
contents of Memory Script:
{
restore clone from service 'ORCL' spfile to
'/oracle/app/oracle/product/19.0.0/dbs/spfileORCL2.ora';
sql clone "alter system set spfile= ''/oracle/app/oracle/product/19.0.0/dbs/spfileORCL2.ora''";
}
executing Memory Script
Starting restore at 20-AUG-24
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: restoring SPFILE
output file name=/oracle/app/oracle/product/19.0.0/dbs/spfileORCL2.ora
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 20-AUG-24
sql statement: alter system set spfile= ''/oracle/app/oracle/product/19.0.0/dbs/spfileORCL2.ora''
contents of Memory Script:
{
sql clone "alter system set db_name =
''ORCL2'' comment=
''duplicate'' scope=spfile";
sql clone "alter system set audit_file_dest =
''/oracle/app/oracle/admin/ORCL2/adump'' comment=
'''' scope=spfile";
sql clone "alter system set db_name =
''ORCL2'' comment=
'''' scope=spfile";
sql clone "alter system set dispatchers =
''(PROTOCOL=TCP) (SERVICE=ORCL2XDB)'' comment=
'''' scope=spfile";
sql clone "alter system set local_listener =
''LISTENER_ORCL2'' comment=
'''' scope=spfile";
sql clone "alter system set db_file_name_convert =
''/oracle/app/oracle/oradata/ORCL/'', ''/oracle/app/oracle/oradata/ORCL2/'' comment=
'''' scope=spfile";
sql clone "alter system set log_file_name_convert =
''/oracle/app/oracle/oradata/ORCL/'', ''/oracle/app/oracle/oradata/ORCL2/'' comment=
'''' scope=spfile";
sql clone "alter system set control_files =
''/oracle/app/oracle/oradata/ORCL2/control01.ctl'', ''/oracle/app/oracle/oradata/ORCL2/control02.ctl'' comment=
'''' scope=spfile";
sql clone "alter system set log_archive_dest_1 =
''location=/oracle/archive2'' comment=
'''' scope=spfile";
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script
sql statement: alter system set db_name = ''ORCL2'' comment= ''duplicate'' scope=spfile
sql statement: alter system set audit_file_dest = ''/oracle/app/oracle/admin/ORCL2/adump'' comment= '''' scope=spfile
sql statement: alter system set db_name = ''ORCL2'' comment= '''' scope=spfile
sql statement: alter system set dispatchers = ''(PROTOCOL=TCP) (SERVICE=ORCL2XDB)'' comment= '''' scope=spfile
sql statement: alter system set local_listener = ''LISTENER_ORCL2'' comment= '''' scope=spfile
sql statement: alter system set db_file_name_convert = ''/oracle/app/oracle/oradata/ORCL/'', ''/oracle/app/oracle/oradata/ORCL2/'' comment= '''' scope=spfile
sql statement: alter system set log_file_name_convert = ''/oracle/app/oracle/oradata/ORCL/'', ''/oracle/app/oracle/oradata/ORCL2/'' comment= '''' scope=spfile
sql statement: alter system set control_files = ''/oracle/app/oracle/oradata/ORCL2/control01.ctl'', ''/oracle/app/oracle/oradata/ORCL2/control02.ctl'' comment= '''' scope=spfile
sql statement: alter system set log_archive_dest_1 = ''location=/oracle/archive2'' comment= '''' scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 3690983864 bytes
Fixed Size 8946104 bytes
Variable Size 721420288 bytes
Database Buffers 2952790016 bytes
Redo Buffers 7827456 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 =
''ORCL2'' 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 = ''ORCL2'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area 3690983864 bytes
Fixed Size 8946104 bytes
Variable Size 721420288 bytes
Database Buffers 2952790016 bytes
Redo Buffers 7827456 bytes
Starting restore at 20-AUG-24
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=7 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=/oracle/app/oracle/oradata/ORCL2/control01.ctl
output file name=/oracle/app/oracle/oradata/ORCL2/control02.ctl
Finished restore at 20-AUG-24
database mounted
contents of Memory Script:
{
set newname for datafile 1 to
"/oracle/app/oracle/oradata/ORCL2/system01.dbf";
set newname for datafile 2 to
"/oracle/app/oracle/oradata/ORCL2/sysaux01.dbf";
set newname for datafile 3 to
"/oracle/app/oracle/oradata/ORCL2/undotbs01.dbf";
set newname for datafile 4 to
"/oracle/app/oracle/oradata/ORCL2/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 20-AUG-24
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 /oracle/app/oracle/oradata/ORCL2/system01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
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 00002 to /oracle/app/oracle/oradata/ORCL2/sysaux01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
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 /oracle/app/oracle/oradata/ORCL2/undotbs01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
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 /oracle/app/oracle/oradata/ORCL2/users01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 20-AUG-24
sql statement: alter system archive log current
current log archived
contents of Memory Script:
{
restore clone force from service 'ORCL'
archivelog from scn 1080410;
switch clone datafile all;
}
executing Memory Script
Starting restore at 20-AUG-24
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=36
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=37
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 20-AUG-24
datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=1177516834 file name=/oracle/app/oracle/oradata/ORCL2/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=1177516834 file name=/oracle/app/oracle/oradata/ORCL2/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=7 STAMP=1177516834 file name=/oracle/app/oracle/oradata/ORCL2/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=1177516834 file name=/oracle/app/oracle/oradata/ORCL2/users01.dbf
contents of Memory Script:
{
set until scn 1080548;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 20-AUG-24
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 36 is already on disk as file /oracle/archive2/arch_1_1151767787_36.arc
archived log for thread 1 with sequence 37 is already on disk as file /oracle/archive2/arch_1_1151767787_37.arc
archived log file name=/oracle/archive2/arch_1_1151767787_36.arc thread=1 sequence=36
archived log file name=/oracle/archive2/arch_1_1151767787_37.arc thread=1 sequence=37
media recovery complete, elapsed time: 00:00:00
Finished recover at 20-AUG-24
contents of Memory Script:
{
delete clone force archivelog all;
}
executing Memory Script
released channel: ORA_AUX_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=80 device type=DISK
deleted archived log
archived log file name=/oracle/archive2/arch_1_1151767787_36.arc RECID=1 STAMP=1177516832
deleted archived log
archived log file name=/oracle/archive2/arch_1_1151767787_37.arc RECID=2 STAMP=1177516833
Deleted 2 objects
Oracle instance started
Total System Global Area 3690983864 bytes
Fixed Size 8946104 bytes
Variable Size 721420288 bytes
Database Buffers 2952790016 bytes
Redo Buffers 7827456 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''ORCL2'' 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 = ''ORCL2'' 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 3690983864 bytes
Fixed Size 8946104 bytes
Variable Size 721420288 bytes
Database Buffers 2952790016 bytes
Redo Buffers 7827456 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORCL2" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/oracle/app/oracle/oradata/ORCL2/redo01.log' ) SIZE 200 M REUSE,
GROUP 2 ( '/oracle/app/oracle/oradata/ORCL2/redo02.log' ) SIZE 200 M REUSE,
GROUP 3 ( '/oracle/app/oracle/oradata/ORCL2/redo03.log' ) SIZE 200 M REUSE
DATAFILE
'/oracle/app/oracle/oradata/ORCL2/system01.dbf'
CHARACTER SET AL32UTF8
contents of Memory Script:
{
set newname for tempfile 1 to
"/oracle/app/oracle/oradata/ORCL2/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/oracle/app/oracle/oradata/ORCL2/sysaux01.dbf",
"/oracle/app/oracle/oradata/ORCL2/undotbs01.dbf",
"/oracle/app/oracle/oradata/ORCL2/users01.dbf";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /oracle/app/oracle/oradata/ORCL2/temp01.dbf in control file
cataloged datafile copy
datafile copy file name=/oracle/app/oracle/oradata/ORCL2/sysaux01.dbf RECID=1 STAMP=1177516866
cataloged datafile copy
datafile copy file name=/oracle/app/oracle/oradata/ORCL2/undotbs01.dbf RECID=2 STAMP=1177516866
cataloged datafile copy
datafile copy file name=/oracle/app/oracle/oradata/ORCL2/users01.dbf RECID=3 STAMP=1177516866
datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=1177516866 file name=/oracle/app/oracle/oradata/ORCL2/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=1177516866 file name=/oracle/app/oracle/oradata/ORCL2/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=1177516866 file name=/oracle/app/oracle/oradata/ORCL2/users01.dbf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 20-AUG-24
RMAN>
복제 완료 !!
- 테스트후 ORCL2 drop
export ORACLE_SID=ORCL2
sqlplus "/as sysdba"
shutdown immediate
startup mount exclusive restrict;
drop database;
- 만일 이짓거리를 반복적으로 수행하고자 한다면..
1. vi dup.sql
DUPLICATE DATABASE TO ORCL2
FROM ACTIVE DATABASE
SPFILE
parameter_value_convert ('ORCL','ORCL2')
set db_file_name_convert='/oracle/app/oracle/oradata/ORCL/','/oracle/app/oracle/oradata/ORCL2/'
set log_file_name_convert='/oracle/app/oracle/oradata/ORCL/','/oracle/app/oracle/oradata/ORCL2/'
set control_files='/oracle/app/oracle/oradata/ORCL2/control01.ctl','/oracle/app/oracle/oradata/ORCL2/control02.ctl'
set log_archive_dest_1='location=/oracle/archive2'
;
2. vi dup.sh
export ORACLE_SID=ORCL2
sqlplus / as sysdba <<EOF
shutdown immediate;
startup mount exclusive restrict;
drop database;
EOF
export ORACLE_SID=ORCL2
sqlplus / as sysdba <<EOF
startup nomount pfile='/oracle/app/oracle/product/19.0.0/dbs/initORCL2.ora';
! rman target sys/oracle@ORCL auxiliary sys/oracle@ORCL2 cmdfile=/home/oracle/dup.sql log=/home/oracle/dup.log append
exit
EOF
3. crontab 등록해서 원하는 주기로 반복 사용 가능
00 23 * * * /home/oracle/dup.sh