Oracle 11g RMAN能够实现基于活动数据库进行异机克隆,从而省去需要先备份再ftp到辅助服务器的过程。这一切可以全部交给Oracle来搞定。在克隆期间,Oracle会读取Target DB的所有数据结构,无须人为的干预(不同的磁盘系统,文件路径与文件名要指定转换方式)。尽管如此,对于生产环境数据库在整个克隆期间性能会下降,其次在Target Server与Auxiliary Server中会产生较大的网络流量。如果这些可以接受的话,从活动数据库进行异机克隆是一个不错的选择。本文首先描述了克隆时不同的连接与克隆方式样本,最后演示了基于活动数据库的克隆。
1、RMAN不同克隆类型的连接方式
关于RMAN不同克隆类型,请参考: 基于 RMAN 的同机数据库克隆 基于RMAN的异机数据库克隆(rman duplicate)
$ export ORACLE_SID=sybo3
# 从备份集克隆,不连接到Target DB以及catalog,或者没有使用catalog
$ rman AUXILIARY /
# 从备份集克隆,无catalog,元数据来源于Target DB控制文件
$ rman TARGET sys/pwd@TAR AUXILIARY sys/pwd@AUX
# 从备份集克隆连接到catalog,但不连接到target DB,元数据库来自RMAN catalog
$ rman CATALOG rman/pwd@catalogdb AUXILIARY sys/pwd@AUX
# 同时连接到target DB以及catalog 元数据来源于Target DB控制文件或catalog,该方式支持从备份集克隆,从活动数据库克隆
$ rman TARGET sys/pwd@TAR CATALOG rman/pwd@catalogdb AUXILIARY sys/pwd@AUX
2、常用的数据库克隆场景
# Auxiliary DB使用与Target DB相同的磁盘系统,文件位置及文件名,下同。需要转换的情形请参考: RMAN 数据库克隆文件位置转换方法
DUPLICATE TARGET DATABASE TO sybo3
SPFILE
NOFILENAMECHECK;
# 将数据库克隆到Target DB一周以前的状态,注,备份集或归档日志应存在
DUPLICATE TARGET DATABASE TO sybo3
UNTIL TIME 'SYSDATE-7'
SPFILE
NOFILENAMECHECK;
# 备份集保存在不同于Target DB保存的位置,此时需要在RMAN中单独指定其位置
DUPLICATE DATABASE TO sybo3
SPFILE
BACKUP LOCATION '/u01/bak/fast_recovery_area/sybo3'
NOFILENAMECHECK;
3、基于活动数据库克隆图示
4、演示机遇活动数据库异机克隆
-
-
-
-
-
-
-
-
-
-
[oracle@linux3 database]$ cat /etc/issue
-
Enterprise Linux Enterprise Linux Server release 5.5 (Carthage)
-
Kernel \r on an \m
-
-
SQL> select * from v$version where rownum<2;
-
-
BANNER
-
-
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
-
-
-
SQL> select instance_name,host_name from v$instance;
-
-
INSTANCE_NAME HOST_NAME
-
-
sybo3 linux3.orasrv.com
-
-
-
SQL> select name,open_mode,log_mode from v$database;
-
-
NAME OPEN_MODE LOG_MODE
-
-
SYBO3 READ WRITE ARCHIVELOG
-
-
-
SQL> select * from t;
-
-
NAME ACTION
-
-
Robinson Transfer DB
-
Jackson Transfer DB by rman
-
-
-
-
-
[oracle@linux3 ~]$ export ORACLE_SID=sybo3
-
[oracle@linux3 ~]$ rman target /
-
RMAN> list backupset;
-
-
specification does not match any backup in the repository
-
-
RMAN> list copy;
-
-
specification does not match any datafile copy in the repository
-
specification does not match any control file copy in the repository
-
specification does not match any archived log in the repository
-
-
RMAN> list backup of archivelog all;
-
-
specification does not match any backup in the repository
-
-
-
a、在Auxiliary server创建相应的dump文件夹
-
[oracle@linux4 database]$ more sybo3.sh
-
#!/bin/sh
-
mkdir -p /u01/database
-
mkdir -p /u01/database/sybo3/adump
-
mkdir -p /u01/database/sybo3/controlf
-
mkdir -p /u01/database/sybo3/fra
-
mkdir -p /u01/database/sybo3/oradata
-
mkdir -p /u01/database/sybo3/redo
-
mkdir -p /u01/database/sybo3/dpdump
-
mkdir -p /u01/database/sybo3/pfile
-
[oracle@linux4 database]$ ./sybo3.sh
-
-
-
b、配置辅助实例参数文件
-
-
-
[oracle@linux3 ~]$ scp $ORACLE_HOME/dbs/initsybo3.ora 192.168.7.26:$ORACLE_HOME/dbs
-
-
-
c、生成辅助实例密码文件
-
-
-
[oracle@linux3 ~]$ scp $ORACLE_HOME/dbs/orapwsybo3 192.168.7.26:$ORACLE_HOME/dbs
-
-
-
d、在Auxiliary Server与Target Server配置监听(方式多样,不详述)
-
-
[oracle@linux4 admin]$ more listener.ora
-
SID_LIST_LISTENER_SYBO3 =
-
(SID_LIST =
-
(SID_DESC =
-
(GLOBAL_DBNAME = sybo3.orasrv.com)
-
(ORACLE_HOME = /u01/oracle/db_1)
-
(SID_NAME = sybo3)
-
)
-
)
-
-
LISTENER_SYBO3 =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.26)(PORT = 1531))
-
)
-
-
ADR_BASE_LISTENER_SYBO3 = /u01/oracle
-
[oracle@linux4 admin]$ more tnsnames.ora
-
TAR =
-
(DESCRIPTION =
-
(ADDRESS_LIST =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.25)(PORT = 1531))
-
)
-
(CONNECT_DATA =
-
(SERVICE_NAME = SYBO3.ORASRV.COM)
-
)
-
)
-
-
AUX =
-
(DESCRIPTION =
-
(ADDRESS_LIST =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.26)(PORT = 1531))
-
)
-
(CONNECT_DATA =
-
(SERVICE_NAME = SYBO3.ORASRV.COM)
-
)
-
)
-
-
-
[oracle@linux3 ~]$ more /u01/oracle/db_1/network/admin/listener.ora
-
# listener.ora Network Configuration File: /u01/oracle/db_1/network/admin/listener.ora
-
# Generated by Oracle configuration tools.
-
-
SID_LIST_LISTENER_SYBO3 =
-
(SID_LIST =
-
(SID_DESC =
-
(GLOBAL_DBNAME = sybo3.orasrv.com)
-
(ORACLE_HOME = /u01/oracle/db_1)
-
(SID_NAME = sybo3)
-
)
-
)
-
-
LISTENER_SYBO3 =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = linux3.orasrv.com)(PORT = 1531))
-
)
-
-
ADR_BASE_LISTENER_SYBO3 = /u01/oracle
-
-
[oracle@linux3 ~]$ more /u01/oracle/db_1/network/admin/tnsnames.ora
-
# tnsnames.ora Network Configuration File: /u01/oracle/db_1/network/admin/tnsnames.ora
-
# Generated by Oracle configuration tools.
-
# 注,在Target Server与Auxiliary Server的tnames.ora文件中,使用了相同的entry,即同时存在TAR与AUX
-
TAR =
-
(DESCRIPTION =
-
(ADDRESS_LIST =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.25)(PORT = 1531))
-
)
-
(CONNECT_DATA =
-
(SERVICE_NAME = SYBO3.ORASRV.COM)
-
)
-
)
-
-
AUX =
-
(DESCRIPTION =
-
(ADDRESS_LIST =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.26)(PORT = 1531))
-
)
-
(CONNECT_DATA =
-
(SERVICE_NAME = SYBO3.ORASRV.COM)
-
)
-
)
-
-
-
[oracle@linux3 admin]$ tnsping TAR
-
[oracle@linux3 admin]$ tnsping AUX
-
[oracle@linux4 admin]$ tnsping TAR
-
[oracle@linux4 admin]$ tnsping AUX
-
-
-
e、实施数据库克隆
-
[oracle@linux4 ~]$ export ORACLE_SID=sybo3
-
[oracle@linux4 ~]$ sqlplus / as sysdba
-
SQL> startup nomount;
-
SQL> exit
-
[oracle@linux4 ~]$ rman target sys/oracle@TAR auxiliary sys/oracle@AUX
-
-
Recovery Manager: Release 11.2.0.1.0 - Production on Fri Aug 2 11:44:09 2013
-
-
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
-
-
connected to target database: SYBO3 (DBID=2347733014)
-
connected to auxiliary database: SYBO3 (not mounted)
-
-
RMAN> duplicate database to sybo3 from active database spfile nofilenamecheck;
-
-
Starting Duplicate Db at 02-AUG-13
-
using target database control file instead of recovery catalog
-
allocated channel: ORA_AUX_DISK_1
-
channel ORA_AUX_DISK_1: SID=134 device type=DISK
-
-
contents of Memory Script:
-
{
-
backup as copy reuse
-
targetfile '/u01/oracle/db_1/dbs/spfilesybo3.ora' auxiliary format
-
'/u01/oracle/db_1/dbs/spfilesybo3.ora' ;
-
sql clone "alter system set spfile= ''/u01/oracle/db_1/dbs/spfilesybo3.ora''";
-
}
-
executing Memory Script
-
-
Starting backup at 02-AUG-13
-
allocated channel: ORA_DISK_1
-
channel ORA_DISK_1: SID=145 device type=DISK
-
Finished backup at 02-AUG-13
-
-
sql statement: alter system set spfile= ''/u01/oracle/db_1/dbs/spfilesybo3.ora''
-
-
contents of Memory Script:
-
{
-
sql clone "alter system set db_name =
-
''SYBO3'' comment=
-
''duplicate'' scope=spfile";
-
shutdown clone immediate;
-
startup clone nomount;
-
}
-
executing Memory Script
-
-
sql statement: alter system set db_name = ''SYBO3'' comment= ''duplicate'' scope=spfile
-
-
Oracle instance shut down
-
-
connected to auxiliary database (not started)
-
Oracle instance started
-
-
Total System Global Area 376635392 bytes
-
-
Fixed Size 1336652 bytes
-
Variable Size 285215412 bytes
-
Database Buffers 83886080 bytes
-
Redo Buffers 6197248 bytes
-
-
contents of Memory Script:
-
{
-
sql clone "alter system set db_name =
-
''SYBO3'' comment=
-
''Modified by RMAN duplicate'' scope=spfile";
-
sql clone "alter system set db_unique_name =
-
''SYBO3'' comment=
-
''Modified by RMAN duplicate'' scope=spfile";
-
shutdown clone immediate;
-
startup clone force nomount
-
backup as copy current controlfile auxiliary format '/u01/database/sybo3/controlf/control01.ctl';
-
restore clone controlfile to '/u01/database/sybo3/controlf/control02.ctl' from
-
'/u01/database/sybo3/controlf/control01.ctl';
-
alter clone database mount;
-
}
-
executing Memory Script
-
-
sql statement: alter system set db_name = ''SYBO3'' comment= ''Modified by RMAN duplicate'' scope=spfile
-
-
sql statement: alter system set db_unique_name = ''SYBO3'' comment= ''Modified by RMAN duplicate'' scope=spfile
-
-
Oracle instance shut down
-
-
Oracle instance started
-
-
Total System Global Area 376635392 bytes
-
-
Fixed Size 1336652 bytes
-
Variable Size 285215412 bytes
-
Database Buffers 83886080 bytes
-
Redo Buffers 6197248 bytes
-
-
Starting backup at 02-AUG-13
-
using channel ORA_DISK_1
-
channel ORA_DISK_1: starting datafile copy
-
copying current control file
-
output file name=/u01/oracle/db_1/dbs/snapcf_sybo3.f tag=TAG20130802T114449 RECID=5 STAMP=822397490
-
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
-
Finished backup at 02-AUG-13
-
-
Starting restore at 02-AUG-13
-
allocated channel: ORA_AUX_DISK_1
-
channel ORA_AUX_DISK_1: SID=133 device type=DISK
-
-
channel ORA_AUX_DISK_1: copied control file copy
-
Finished restore at 02-AUG-13
-
-
database mounted
-
RMAN-05538: WARNING: implicitly using DB_FILE_NAME_CONVERT
-
-
contents of Memory Script:
-
{
-
set newname for datafile 1 to
-
"/u01/database/sybo3/oradata/system01.dbf";
-
set newname for datafile 2 to
-
"/u01/database/sybo3/oradata/sysaux01.dbf";
-
set newname for datafile 3 to
-
"/u01/database/sybo3/oradata/undotbs01.dbf";
-
set newname for datafile 4 to
-
"/u01/database/sybo3/oradata/users01.dbf";
-
set newname for datafile 5 to
-
"/u01/database/sybo3/oradata/example01.dbf";
-
backup as copy reuse
-
datafile 1 auxiliary format
-
"/u01/database/sybo3/oradata/system01.dbf" datafile
-
2 auxiliary format
-
"/u01/database/sybo3/oradata/sysaux01.dbf" datafile
-
3 auxiliary format
-
"/u01/database/sybo3/oradata/undotbs01.dbf" datafile
-
4 auxiliary format
-
"/u01/database/sybo3/oradata/users01.dbf" datafile
-
5 auxiliary format
-
"/u01/database/sybo3/oradata/example01.dbf" ;
-
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
-
-
executing command: SET NEWNAME
-
-
Starting backup at 02-AUG-13
-
using channel ORA_DISK_1
-
channel ORA_DISK_1: starting datafile copy
-
input datafile file number=00001 name=/u01/database/sybo3/oradata/system01.dbf
-
output file name=/u01/database/sybo3/oradata/system01.dbf tag=TAG20130802T114457
-
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
-
channel ORA_DISK_1: starting datafile copy
-
input datafile file number=00002 name=/u01/database/sybo3/oradata/sysaux01.dbf
-
output file name=/u01/database/sybo3/oradata/sysaux01.dbf tag=TAG20130802T114457
-
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
-
channel ORA_DISK_1: starting datafile copy
-
input datafile file number=00005 name=/u01/database/sybo3/oradata/example01.dbf
-
output file name=/u01/database/sybo3/oradata/example01.dbf tag=TAG20130802T114457
-
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
-
channel ORA_DISK_1: starting datafile copy
-
input datafile file number=00003 name=/u01/database/sybo3/oradata/undotbs01.dbf
-
output file name=/u01/database/sybo3/oradata/undotbs01.dbf tag=TAG20130802T114457
-
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
-
channel ORA_DISK_1: starting datafile copy
-
input datafile file number=00004 name=/u01/database/sybo3/oradata/users01.dbf
-
output file name=/u01/database/sybo3/oradata/users01.dbf tag=TAG20130802T114457
-
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
-
Finished backup at 02-AUG-13
-
-
sql statement: alter system archive log current
-
-
contents of Memory Script:
-
{
-
backup as copy reuse
-
archivelog like "/u01/database/sybo3/fra/SYBO3/archivelog/2013_08_02/o1_mf_1_43_8zpbwsry_.arc" auxiliary format
-
"/u01/database/sybo3/fra/SYBO3/archivelog/2013_08_02/o1_mf_1_43_%u_.arc" ;
-
catalog clone recovery area;
-
switch clone datafile all;
-
}
-
executing Memory Script
-
-
Starting backup at 02-AUG-13
-
using channel ORA_DISK_1
-
channel ORA_DISK_1: starting archived log copy
-
input archived log thread=1 sequence=43 RECID=48 STAMP=822397594
-
output file name=/u01/database/sybo3/fra/SYBO3/archivelog/2013_08_02/o1_mf_1_43_1aog9ikr_.arc RECID=0 STAMP=0
-
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
-
Finished backup at 02-AUG-13
-
-
searching for all files in the recovery area
-
-
List of Files Unknown to the Database
-
=====================================
-
File Name: /u01/database/sybo3/fra/SYBO3/archivelog/2013_08_02/o1_mf_1_43_1aog9ikr_.arc
-
cataloging files...
-
cataloging done
-
-
List of Cataloged Files
-
=======================
-
File Name: /u01/database/sybo3/fra/SYBO3/archivelog/2013_08_02/o1_mf_1_43_1aog9ikr_.arc
-
-
datafile 1 switched to datafile copy
-
input datafile copy RECID=5 STAMP=822397596 file name=/u01/database/sybo3/oradata/system01.dbf
-
datafile 2 switched to datafile copy
-
input datafile copy RECID=6 STAMP=822397596 file name=/u01/database/sybo3/oradata/sysaux01.dbf
-
datafile 3 switched to datafile copy
-
input datafile copy RECID=7 STAMP=822397596 file name=/u01/database/sybo3/oradata/undotbs01.dbf
-
datafile 4 switched to datafile copy
-
input datafile copy RECID=8 STAMP=822397596 file name=/u01/database/sybo3/oradata/users01.dbf
-
datafile 5 switched to datafile copy
-
input datafile copy RECID=9 STAMP=822397596 file name=/u01/database/sybo3/oradata/example01.dbf
-
-
contents of Memory Script:
-
{
-
set until scn 1234019;
-
recover
-
clone database
-
delete archivelog
-
;
-
}
-
executing Memory Script
-
-
executing command: SET until clause
-
-
Starting recover at 02-AUG-13
-
using channel ORA_AUX_DISK_1
-
-
starting media recovery
-
-
archived log for thread 1 with sequence 43 is already on disk as file /u01/database/sybo3/fra/SYBO3/archivelog/
-
2013_08_02/o1_mf_1_43_1aog9ikr_.arc
-
archived log file name=/u01/database/sybo3/fra/SYBO3/archivelog/2013_08_02/o1_mf_1_43_1aog9ikr_.arc thread=1 sequence=43
-
media recovery complete, elapsed time: 00:00:00
-
Finished recover at 02-AUG-13
-
-
contents of Memory Script:
-
{
-
shutdown clone immediate;
-
startup clone nomount;
-
sql clone "alter system set db_name =
-
''SYBO3'' 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
-
-
database dismounted
-
Oracle instance shut down
-
-
connected to auxiliary database (not started)
-
Oracle instance started
-
-
Total System Global Area 376635392 bytes
-
-
Fixed Size 1336652 bytes
-
Variable Size 285215412 bytes
-
Database Buffers 83886080 bytes
-
Redo Buffers 6197248 bytes
-
-
sql statement: alter system set db_name = ''SYBO3'' 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 376635392 bytes
-
-
Fixed Size 1336652 bytes
-
Variable Size 285215412 bytes
-
Database Buffers 83886080 bytes
-
Redo Buffers 6197248 bytes
-
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "SYBO3" RESETLOGS ARCHIVELOG
-
MAXLOGFILES 16
-
MAXLOGMEMBERS 3
-
MAXDATAFILES 100
-
MAXINSTANCES 8
-
MAXLOGHISTORY 292
-
LOGFILE
-
GROUP 1 SIZE 50 M ,
-
GROUP 2 SIZE 50 M ,
-
GROUP 3 SIZE 50 M
-
DATAFILE
-
'/u01/database/sybo3/oradata/system01.dbf'
-
CHARACTER SET AL32UTF8
-
-
-
contents of Memory Script:
-
{
-
set newname for tempfile 1 to
-
"/u01/database/sybo3/oradata/temp01.dbf";
-
switch clone tempfile all;
-
catalog clone datafilecopy "/u01/database/sybo3/oradata/sysaux01.dbf",
-
"/u01/database/sybo3/oradata/undotbs01.dbf",
-
"/u01/database/sybo3/oradata/users01.dbf",
-
"/u01/database/sybo3/oradata/example01.dbf";
-
switch clone datafile all;
-
}
-
executing Memory Script
-
-
executing command: SET NEWNAME
-
-
renamed tempfile 1 to /u01/database/sybo3/oradata/temp01.dbf in control file
-
-
cataloged datafile copy
-
datafile copy file name=/u01/database/sybo3/oradata/sysaux01.dbf RECID=1 STAMP=822397612
-
cataloged datafile copy
-
datafile copy file name=/u01/database/sybo3/oradata/undotbs01.dbf RECID=2 STAMP=822397612
-
cataloged datafile copy
-
datafile copy file name=/u01/database/sybo3/oradata/users01.dbf RECID=3 STAMP=822397612
-
cataloged datafile copy
-
datafile copy file name=/u01/database/sybo3/oradata/example01.dbf RECID=4 STAMP=822397612
-
-
datafile 2 switched to datafile copy
-
input datafile copy RECID=1 STAMP=822397612 file name=/u01/database/sybo3/oradata/sysaux01.dbf
-
datafile 3 switched to datafile copy
-
input datafile copy RECID=2 STAMP=822397612 file name=/u01/database/sybo3/oradata/undotbs01.dbf
-
datafile 4 switched to datafile copy
-
input datafile copy RECID=3 STAMP=822397612 file name=/u01/database/sybo3/oradata/users01.dbf
-
datafile 5 switched to datafile copy
-
input datafile copy RECID=4 STAMP=822397612 file name=/u01/database/sybo3/oradata/example01.dbf
-
-
contents of Memory Script:
-
{
-
Alter clone database open resetlogs;
-
}
-
executing Memory Script
-
-
database opened
-
Finished Duplicate Db at 02-AUG-13
-
-
-
f、验证结果
-
[oracle@linux4 ~]$ sqlplus / as sysdba
-
-
SQL> select * from t;
-
-
NAME ACTION
-
-
Robinson Transfer DB
-
Jackson Transfer DB by rman
-
-
SQL> set linesize 190
-
SQL> select host_name,instance_name from v$instance;
-
-
HOST_NAME INSTANCE_NAME
-
-
linux4.orasrv.com sybo3
5、后记
a、无论使用何种方式进行数据库克隆,都是使用了基于时间点的不完全恢复,都需要使用open resetlog方式打开数据库。
b、从活动数据库进行克隆时,需要保证Target DB处于归档模式。
c、从活动数据库进行克隆应当保证Target Server与Auxiliary Server 的tnsnames文件中都存在到Target DB与Auxiliary DB的连接字符串。
d、可以在Target Server与Auxiliary Server任意一端发布duplicate database to newdb from active database进行克隆。
e、从活动数据库克隆应保证Traget DB与Auxiliary DB具有相同的密码(位于密码文件)或者直接从Target Server复制密码文件到Auxiliary Server。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23490154/viewspace-1062381/
,如需转载,请注明出处,否则将追究法律责任。