具体duplicate介绍就不多废话了。
duplicate可以直接duplicate from active database这样不需要rman的备份文件。
主要步骤:
1.目标端创建参数文件
2.目标端新建密码文件
3.目标端修改监听,使用静态监听
4.创建相关文件目录
5.修改源端tnsnames.ora,保证可以连接到目标端
注意点:
duplicate可以直接duplicate from active database这样不需要rman的备份文件。
主要步骤:
1.目标端创建参数文件
2.目标端新建密码文件
3.目标端修改监听,使用静态监听
4.创建相关文件目录
5.修改源端tnsnames.ora,保证可以连接到目标端
6.使用rman开始duplicate数据库
环境:
源端:
hostname;11g1
db_name:squan
sid:squan
目标端:
hostname:11g2
db_name:suq
sid:suq
具体操作如下,目标端:
[oracle@11g2 dbs]$ orapwd file=orapwsuq password=manager entries=10
[oracle@11g2 dbs]$ cat initsuq.ora
audit_file_dest="/opt/oracle/admin/suq/adump"
audit_trail=DB
compatible=11.2.0.0.0
control_files=/opt/oracle/oradata/suq/control01.ctl, /opt/oracle/flash_recovery_area/suq/control02.ctl
db_block_size=8192
db_domain=""
db_name="suq"
db_recovery_file_dest_size=5218762752
db_recovery_file_dest="/opt/oracle/flash_recovery_area"
diagnostic_dest=/opt/oracle
memory_target=1073741824
open_cursors=300
processes=150
remote_login_passwordfile=EXCLUSIVE
service_names=suq
undo_tablespace=UNDOTBS1
db_file_name_convert=('squan','suq')
[oracle@11g2 dbs]$ mkdir -p /opt/oracle/admin/suq/adump
[oracle@11g2 dbs]$ mkdir -p /opt/oracle/oradata/suq/ /opt/oracle/flash_recovery_area/suq
[oracle@11g2 dbs]$ export ORACLE_SID=suq
[oracle@11g2 dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on 星期六 5月 24 18:59:08 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
已连接到空闲例程。
SQL> startup nomount;
ORACLE 例程已经启动。
Total System Global Area 1068937216 bytes
Fixed Size 2260088 bytes
Variable Size 616563592 bytes
Database Buffers 444596224 bytes
Redo Buffers 5517312 bytes
SQL>
[oracle@11g2 admin]$ cat listener.ora
# listener.ora Network Configuration File: /opt/oracle/product/OraHome/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /opt/oracle/product/OraHome11204)
(PROGRAM = extproc)
)
(SID_DESC =
(SID_NAME = suq)
(ORACLE_HOME = /opt/oracle/product/OraHome11204)
(GLOBAL_DBNAME=suq)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 11g2)(PORT = 1521))
)
)
[oracle@11g2 admin]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 24-5月 -2014 18:58:56
Copyright (c) 1991, 2013, Oracle. All rights reserved.
正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=11g2)(PORT=1521)))
LISTENER 的 STATUS
------------------------
别名 LISTENER
版本 TNSLSNR for Linux: Version 11.2.0.4.0 - Production
启动日期 24-5月 -2014 18:58:46
正常运行时间 0 天 0 小时 0 分 10 秒
跟踪级别 off
安全性 ON: Local OS Authentication
SNMP OFF
监听程序参数文件 /opt/oracle/product/OraHome11204/network/admin/listener.ora
监听程序日志文件 /opt/oracle/diag/tnslsnr/11g2/listener/alert/log.xml
监听端点概要...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=11g2)(PORT=1521)))
服务摘要..
服务 "PLSExtProc" 包含 1 个实例。
实例 "PLSExtProc", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
服务 "suq" 包含 1 个实例。
实例 "suq", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
命令执行成功
源端操作如下:
[oracle@11g1 admin]$ rman target sys/manager
Recovery Manager: Release 11.2.0.4.0 - Production on Sat May 24 20:18:02 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: SQUAN (DBID=3808450041)
RMAN> connect auxiliary sys/manager@suq
connected to auxiliary database: SUQ (not mounted)
duplicate target database to suq
from active database
logfile
'/opt/oracle/oradata/suq/redo01.log' size 50m,
'/opt/oracle/oradata/suq/redo02.log' size 50m,
6> '/opt/oracle/oradata/suq/redo03.log' size 50m;
Starting Duplicate Db at 24-MAY-14
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=10 device type=DISK
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 1068937216 bytes
Fixed Size 2260088 bytes
Variable Size 620757896 bytes
Database Buffers 440401920 bytes
Redo Buffers 5517312 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''SQUAN'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''SUQ'' comment=
''Modified by RMAN duplicate'' scope=spfile";
shutdown clone immediate;
startup clone force nomount
backup as copy current controlfile auxiliary format '/opt/oracle/oradata/suq/control01.ctl';
restore clone controlfile to '/opt/oracle/flash_recovery_area/suq/control02.ctl' from
'/opt/oracle/oradata/suq/control01.ctl';
alter clone database mount;
}
executing Memory Script
sql statement: alter system set db_name = ''SQUAN'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set db_unique_name = ''SUQ'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area 1068937216 bytes
Fixed Size 2260088 bytes
Variable Size 620757896 bytes
Database Buffers 440401920 bytes
Redo Buffers 5517312 bytes
Starting backup at 24-MAY-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=17 device type=DISK
channel ORA_DISK_1: starting datafile copy
copying current control file
output file name=/opt/oracle/product/OraHome11204/dbs/snapcf_squan.f tag=TAG20140524T201835 RECID=4 STAMP=848434716
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 24-MAY-14
Starting restore at 24-MAY-14
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 24-MAY-14
database mounted
contents of Memory Script:
{
set newname for datafile 1 to
"/opt/oracle/oradata/suq/system01.dbf";
set newname for datafile 2 to
"/opt/oracle/oradata/suq/sysaux01.dbf";
set newname for datafile 3 to
"/opt/oracle/oradata/suq/undotbs01.dbf";
set newname for datafile 4 to
"/opt/oracle/oradata/suq/users01.dbf";
set newname for datafile 5 to
"/opt/oracle/oradata/suq/test02.dbf";
set newname for datafile 6 to
"/opt/oracle/oradata/suq/test01.dbf";
backup as copy reuse
datafile 1 auxiliary format
"/opt/oracle/oradata/suq/system01.dbf" datafile
2 auxiliary format
"/opt/oracle/oradata/suq/sysaux01.dbf" datafile
3 auxiliary format
"/opt/oracle/oradata/suq/undotbs01.dbf" datafile
4 auxiliary format
"/opt/oracle/oradata/suq/users01.dbf" datafile
5 auxiliary format
"/opt/oracle/oradata/suq/test02.dbf" datafile
6 auxiliary format
"/opt/oracle/oradata/suq/test01.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
executing command: SET NEWNAME
Starting backup at 24-MAY-14
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/opt/oracle/oradata/squan/system01.dbf
output file name=/opt/oracle/oradata/suq/system01.dbf tag=TAG20140524T201844
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:05
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/opt/oracle/oradata/squan/sysaux01.dbf
output file name=/opt/oracle/oradata/suq/sysaux01.dbf tag=TAG20140524T201844
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/opt/oracle/oradata/squan/undotbs01.dbf
output file name=/opt/oracle/oradata/suq/undotbs01.dbf tag=TAG20140524T201844
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/opt/oracle/oradata/squan/users01.dbf
output file name=/opt/oracle/oradata/suq/users01.dbf tag=TAG20140524T201844
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/opt/oracle/oradata/squan/test02.dbf
output file name=/opt/oracle/oradata/suq/test02.dbf tag=TAG20140524T201844
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/opt/oracle/oradata/squan/test01.dbf
output file name=/opt/oracle/oradata/suq/test01.dbf tag=TAG20140524T201844
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 24-MAY-14
sql statement: alter system archive log current
contents of Memory Script:
{
backup as copy reuse
archivelog like "/opt/arch/1_46_846708003.dbf" auxiliary format
"/opt/oracle/flash_recovery_area/SUQ/archivelog/2014_05_24/o1_mf_1_46_%u_.arc" ;
catalog clone recovery area;
switch clone datafile all;
}
executing Memory Script
Starting backup at 24-MAY-14
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=46 RECID=13 STAMP=848434899
output file name=/opt/oracle/flash_recovery_area/SUQ/archivelog/2014_05_24/o1_mf_1_46_13p945mk_.arc RECID=0 STAMP=0
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:03
Finished backup at 24-MAY-14
searching for all files in the recovery area
List of Files Unknown to the Database
=====================================
File Name: /opt/oracle/flash_recovery_area/SUQ/archivelog/2014_05_24/o1_mf_1_46_13p945mk_.arc
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /opt/oracle/flash_recovery_area/SUQ/archivelog/2014_05_24/o1_mf_1_46_13p945mk_.arc
datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=848434903 file name=/opt/oracle/oradata/suq/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=5 STAMP=848434903 file name=/opt/oracle/oradata/suq/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=848434903 file name=/opt/oracle/oradata/suq/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=7 STAMP=848434903 file name=/opt/oracle/oradata/suq/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=8 STAMP=848434903 file name=/opt/oracle/oradata/suq/test02.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=9 STAMP=848434903 file name=/opt/oracle/oradata/suq/test01.dbf
contents of Memory Script:
{
set until scn 1170031;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 24-MAY-14
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 46 is already on disk as file /opt/oracle/flash_recovery_area/SUQ/archivelog/2014_05_24/o1_mf_1_46_13p945mk_.arc
archived log file name=/opt/oracle/flash_recovery_area/SUQ/archivelog/2014_05_24/o1_mf_1_46_13p945mk_.arc thread=1 sequence=46
media recovery complete, elapsed time: 00:00:01
Finished recover at 24-MAY-14
Oracle instance started
Total System Global Area 1068937216 bytes
Fixed Size 2260088 bytes
Variable Size 620757896 bytes
Database Buffers 440401920 bytes
Redo Buffers 5517312 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''SUQ'' 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 = ''SUQ'' 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 1068937216 bytes
Fixed Size 2260088 bytes
Variable Size 620757896 bytes
Database Buffers 440401920 bytes
Redo Buffers 5517312 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "SUQ" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/opt/oracle/oradata/suq/redo01.log' SIZE 50 M ,
GROUP 2 '/opt/oracle/oradata/suq/redo02.log' SIZE 50 M ,
GROUP 3 '/opt/oracle/oradata/suq/redo03.log' SIZE 50 M
DATAFILE
'/opt/oracle/oradata/suq/system01.dbf'
CHARACTER SET ZHS16GBK
contents of Memory Script:
{
set newname for tempfile 1 to
"/opt/oracle/oradata/suq/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/opt/oracle/oradata/suq/sysaux01.dbf",
"/opt/oracle/oradata/suq/undotbs01.dbf",
"/opt/oracle/oradata/suq/users01.dbf",
"/opt/oracle/oradata/suq/test02.dbf",
"/opt/oracle/oradata/suq/test01.dbf";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /opt/oracle/oradata/suq/temp01.dbf in control file
cataloged datafile copy
datafile copy file name=/opt/oracle/oradata/suq/sysaux01.dbf RECID=1 STAMP=848434914
cataloged datafile copy
datafile copy file name=/opt/oracle/oradata/suq/undotbs01.dbf RECID=2 STAMP=848434914
cataloged datafile copy
datafile copy file name=/opt/oracle/oradata/suq/users01.dbf RECID=3 STAMP=848434914
cataloged datafile copy
datafile copy file name=/opt/oracle/oradata/suq/test02.dbf RECID=4 STAMP=848434914
cataloged datafile copy
datafile copy file name=/opt/oracle/oradata/suq/test01.dbf RECID=5 STAMP=848434914
datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=848434914 file name=/opt/oracle/oradata/suq/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=848434914 file name=/opt/oracle/oradata/suq/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=848434914 file name=/opt/oracle/oradata/suq/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=848434914 file name=/opt/oracle/oradata/suq/test02.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=5 STAMP=848434914 file name=/opt/oracle/oradata/suq/test01.dbf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 24-MAY-14
注意点:
1.如果遇到ORA-01017的错误,报用户名密码错误。那是因为rman连接源端数据库的时候不能使用rman target / 而应该输入密码 rman sys/manager
2.可以使用db_file_name_convert=('','')和log_file_name_convert=('','')来转换数据文件和日志文件。
3.如果使用duplicate target database to suq;语句,默认寻找rman的备份和copy,那么就需要有一个完整的备份,否则报错