环境:linux平台+oracle(10.2.0.1) 【不同主机的复制】
实验条件:复制的库所在主机与主库所在主机具有相同的OS平台
复制的库所在主机已安装数据库软件
使用rman做不同主机的复制注意事项:
a.
当使用RMAN方式建立复制库时,必须先使用RMAN备份主库的所有数据文件、控制文件和归档日志。例如:
rman target /
backup database include current controlfile plus archivelog format='d:backup%d_%s.bak';
在RMAN中,建立复制库使用duplicate命令。
b.
缺省情况下,当建立复制库时,会包含主库中的所有数据文件。如果不希望复制库中包含只读表空间的数据文件,则在执行duplicate时指定skip readonly选项;如果要跳过特定表空间,则在执行duplicate时指定skip tablespace选项。当使用RMAN方式建立复制库时,应注意:
skip tablespace时不能指定SYSTEM和UNDO表空间
c.
如果在不同主机上建立复制库,且与主库采用完全相同的目录结构和文件名,则在执行duplicate时指定nofilenamecheck选项;如果要将复制库恢复到过去的时间点,则可以使用set until或duplicate..until命令。
d.
当在不同主机上建立复制库时,必须将RMAN备份集文件复制到目标主机的相同目录下。
主库orcl所在主机db,复制的库aux所在主机主机名为dup
步骤:
1.
使用rman备份主库Target database (orcl)
RMAN> backup database plus archivelog;
此处必须要备份归档日志,不然在duplicate命令执行过程中会报错。
2.
为复制库建立密码文件
[oracle@db ~]$ cd $ORACLE_HOME
[oracle@db db_1]$ cd dbs
[oracle@db dbs]$scp orapworcl dup:/u01/app/oracle/product/10.2.0/db_1/dbs/orapwaux
3.
为复制库建立参数文件
在主库所在主机上操作:
SQL> create pfile from spfile;
[oracle@db dbs]$ scp initorcl.ora dup:/u01/app/oracle/product/10.2.0/db_1/dbs/initaux.ora
Vi initaux.or
aux.__db_cache_size=163577856
aux.__java_pool_size=4194304
aux.__large_pool_size=4194304
aux.__shared_pool_size=88080384
aux.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/aux/adump'
*.background_dump_dest='/u01/app/oracle/admin/aux/bdump'
*.compatible='10.2.0.3.0'
*.control_files='/u01/app/oracle/oradata/aux/control01.ctl','/u01/app/oracle/oradata/aux/control02.ctl','/u01/app/oracle/oradata/aux/control03.ctl'#Restore Controlfile
*.core_dump_dest='/u01/app/oracle/admin/aux/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='aux'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=auxXDB)'
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=81788928
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_max_size=157286400
*.sga_target=262144000
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/aux/udump'
*.UTL_FILE_DIR='/u01/app/oracle/logs'
db_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/aux'
log_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/aux'
4.
在dup上配置监听程序,在db上配置网络服务名
在复制库所在主机dup上配置listener.ora
vi listener.ora
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=orcl)
(ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1)
)
(SID_DESC=
(SID_NAME=aux)
(ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1)
)
)
LISTENER =
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=dup)(PORT=1521))
(ADDRESS=(PROTOCOL=ipc)(KEY=PNPKEY)))
[oracle@dup admin]$ lsnrctl stop
[oracle@dup admin]$ lsnrctl start
在主库所在主机上配置tnsnames.ora
Vi tnsnames.ora
orcl=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = db)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = orcl)
(SERVER = DEDICATED)
)
)
aux=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = db)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = aux)
(SERVER = DEDICATED)
)
)
5.
在dup上建立复制数据库各种相关文件的OS目录,并将db主机上的备份集拷贝至dup主机上。当复制备份集文件到复制库所在主机时,应将备份集文件放到与主数据库备份集相同的OS目录下。
在dup上操作:
[oracle@dup ~]$ cd $ORACLE_BASE
[oracle@ dup oracle]$ ls
admin flash_recovery_area logs oradata oraInventory product
[oracle@dup oracle]$ cd admin
[oracle@dup admin]$ ls
orcl
[oracle@dup admin]$ mkdir aux
[oracle@dup admin]$ cd aux/
[oracle@dup aux]$ mkdir adump bdump cdump udump
[oracle@dup orcl]$ cd ../../oradata/
[oracle@dup oradata]$ ls
orcl
[oracle@dup oradata]$ mkdir aux
此处省略了拷贝备份集的操作命令。
6.
启动实例
[oracle@dup oradata]$ export ORACLE_SID=aux
[oracle@dup oradata]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 - Production on Sat Jul 23 11:25:20 2011
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to an idle instance.
SQL> startup nomount;
SQL>exit;
此处必须exit,不然会影响后续duplicate操作,因为duplicate命令执行过程中有一个shutdown过程,此处不exit会导致后续操作不可进行。
7.
用duplicate命令建立复制库
在db上操作:
[oracle@db ~]$ rman target / auxiliary sys/oracle@aux
RMAN> duplicate target database to aux;
Starting Duplicate Db at 23-JUL-11
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=155 devtype=DISK
contents of Memory Script:
{
set until scn 608014;
set newname for datafile 1 to
"/u01/app/oracle/oradata/aux/system01.dbf";
set newname for datafile 2 to
"/u01/app/oracle/oradata/aux/undotbs01.dbf";
set newname for datafile 3 to
"/u01/app/oracle/oradata/aux/sysaux01.dbf";
set newname for datafile 4 to
"/u01/app/oracle/oradata/aux/users01.dbf";
set newname for datafile 5 to
"/u01/app/oracle/oradata/aux/example01.dbf";
restore
check readonly
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
Starting restore at 23-JUL-11
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/aux/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/aux/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/aux/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/aux/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/aux/example01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2011_07_23/o1_mf_nnndf_TAG20110723T112008_72nhh8wf_.bkp
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2011_07_23/o1_mf_nnndf_TAG20110723T112008_72nhh8wf_.bkp tag=TAG20110723T112008
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:07
Finished restore at 23-JUL-11
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "AUX" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/u01/app/oracle/oradata/aux/redo01.log' ) SIZE 50 M REUSE,
GROUP 2 ( '/u01/app/oracle/oradata/aux/redo02.log' ) SIZE 50 M REUSE,
GROUP 3 ( '/u01/app/oracle/oradata/aux/redo03.log' ) SIZE 50 M REUSE
DATAFILE
'/u01/app/oracle/oradata/aux/system01.dbf'
CHARACTER SET WE8ISO8859P1
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
released channel: ORA_AUX_DISK_1
datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=757250956 filename=/u01/app/oracle/oradata/aux/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=757250956 filename=/u01/app/oracle/oradata/aux/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=757250956 filename=/u01/app/oracle/oradata/aux/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=757250956 filename=/u01/app/oracle/oradata/aux/example01.dbf
contents of Memory Script:
{
set until scn 608014;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 23-JUL-11
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=155 devtype=DISK
starting media recovery
archive log thread 1 sequence 2 is already on disk as file /u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_07_23/o1_mf_1_2_72nhk2v4_.arc
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_07_23/o1_mf_1_2_72nhk2v4_.arc thread=1 sequence=2
media recovery complete, elapsed time: 00:00:04
Finished recover at 23-JUL-11
contents of Memory Script:
{
catalog clone datafilecopy "/u01/app/oracle/oradata/aux/undotbs01.dbf";
catalog clone datafilecopy "/u01/app/oracle/oradata/aux/sysaux01.dbf";
catalog clone datafilecopy "/u01/app/oracle/oradata/aux/users01.dbf";
catalog clone datafilecopy "/u01/app/oracle/oradata/aux/example01.dbf";
switch clone datafile all;
}
executing Memory Script
cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/aux/undotbs01.dbf recid=1 stamp=757251533
cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/aux/sysaux01.dbf recid=2 stamp=757251533
cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/aux/users01.dbf recid=3 stamp=757251533
cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/aux/example01.dbf recid=4 stamp=757251533
datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=757251533 filename=/u01/app/oracle/oradata/aux/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=757251533 filename=/u01/app/oracle/oradata/aux/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=757251533 filename=/u01/app/oracle/oradata/aux/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=757251533 filename=/u01/app/oracle/oradata/aux/example01.dbf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 23-JUL-11
实验总结::在复制库aux上面不能有任何的连接。若有连接则会停止不动。另主库备份需备份归档日志。