测试在同一机器不同数据库实例复制数据库
1.环境
Target DB:
IP:10.131.119.114
HOSTNAME:openstack-node1.example.com
ORACLE_SID:orcl11g
Auxiliary DB:
IP:10.131.119.114
HOSTNAME:openstack-node1.example.com
ORACLE_SID:aux
2.创建Auxiliary DB 参数文件
[oracle@openstack-node1 dbs]$ cat initaux.ora
*.audit_file_dest=‘/u2/oracle/admin/aux/adump‘
*.audit_trail=‘db‘
*.compatible=‘11.2.0.0.0‘
*.control_files=‘/u2/oracle/oradata/aux/control01.ctl‘,‘/u2/oracle/fast_recovery_area/aux/control02.ctl‘
*.db_block_size=8192
*.db_domain=‘us.oracle.com‘
*.db_name=‘aux‘
*.db_recovery_file_dest=‘/u2/oracle/fast_recovery_area‘
*.db_recovery_file_dest_size=4227858432
*.diagnostic_dest=‘/u2/oracle‘
*.dispatchers=‘(PROTOCOL=TCP) (SERVICE=auxXDB)‘
*.log_archive_dest_1=‘location=/u2/oracle/arch/aux‘
*.open_cursors=300
*.pga_aggregate_target=104857600
*.processes=150
*.remote_login_passwordfile=‘EXCLUSIVE‘
*.sga_max_size=272629760
*.sga_target=272629760
*.undo_tablespace=‘UNDOTBS1‘
*.db_file_name_convert=(‘orcl11g‘,‘aux‘)
3.创建Auxiliary DB需要的目录
[oracle@openstack-node1 ~]$ mkdir -p /u2/oracle/admin/aux/adump
[oracle@openstack-node1 ~]$ mkdir -p /u2/oracle/oradata/aux
[oracle@openstack-node1 ~]$ mkdir -p /u2/oracle/fast_recovery_area/aux
[oracle@openstack-node1 ~]$ mkdir -p /u2/oracle/arch/aux
4.创建Auxiliary DB密码文件
[oracle@openstack-node1 dbs]$ cp orapworcl11g orapwaux
5.配置监听与TNS
监听:
[oracle@openstack-node1 admin]$ cat listener.ora
# listener.ora Network Configuration File: /u2/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl11g)
(ORACLE_HOME = /u2/oracle/product/11.2.0/dbhome_1)
(SID_NAME = orcl11g)
)
(SID_DESC =
(GLOBAL_DBNAME = aux)
(ORACLE_HOME = /u2/oracle/product/11.2.0/dbhome_1)
(SID_NAME = aux)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.131.119.114)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u2/oracle
TNS:
[oracle@openstack-node1 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u2/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
ORCL11G =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.131.119.114)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl11g)
)
)
aux =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.131.119.114)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = aux)
)
)
6.开始复制操作
[oracle@openstack-node1 ~]$ rman target / ----连接target DB
Recovery Manager: Release 11.2.0.2.0 - Production on Thu Jan 14 11:33:21 2016
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL11G (DBID=1007320894)
RMAN> backup database plus archivelog; ----备份数据库与日志
Starting backup at 14-JAN-16
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=2 RECID=1 STAMP=900437233
input archived log thread=1 sequence=3 RECID=2 STAMP=900482409
input archived log thread=1 sequence=4 RECID=3 STAMP=900541603
input archived log thread=1 sequence=5 RECID=4 STAMP=900597615
input archived log thread=1 sequence=6 RECID=5 STAMP=900655218
input archived log thread=1 sequence=7 RECID=6 STAMP=900684500
input archived log thread=1 sequence=8 RECID=7 STAMP=900734434
input archived log thread=1 sequence=9 RECID=8 STAMP=900770943
input archived log thread=1 sequence=10 RECID=9 STAMP=900813623
input archived log thread=1 sequence=11 RECID=10 STAMP=900885622
input archived log thread=1 sequence=12 RECID=11 STAMP=900950581
input archived log thread=1 sequence=13 RECID=12 STAMP=900982859
input archived log thread=1 sequence=14 RECID=13 STAMP=901058420
input archived log thread=1 sequence=15 RECID=14 STAMP=901101608
input archived log thread=1 sequence=16 RECID=15 STAMP=901102699
input archived log thread=1 sequence=17 RECID=16 STAMP=901102770
input archived log thread=1 sequence=18 RECID=17 STAMP=901107986
channel ORA_DISK_1: starting piece 1 at 14-JAN-16
channel ORA_DISK_1: finished piece 1 at 14-JAN-16
piece handle=/u2/oracle/fast_recovery_area/ORCL11G/backupset/2016_01_14/o1_mf_annnn_TAG20160114T114626_c9g6jlyk_.bkp tag=TAG20160114T114626 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 14-JAN-16
Starting backup at 14-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u2/oracle/oradata/orcl11g/system01.dbf
input datafile file number=00002 name=/u2/oracle/oradata/orcl11g/sysaux01.dbf
input datafile file number=00005 name=/u2/oracle/oradata/orcl11g/tom01.dbf
input datafile file number=00003 name=/u2/oracle/oradata/orcl11g/undotbs01.dbf
input datafile file number=00004 name=/u2/oracle/oradata/orcl11g/users01.dbf
channel ORA_DISK_1: starting piece 1 at 14-JAN-16
channel ORA_DISK_1: finished piece 1 at 14-JAN-16
piece handle=/u2/oracle/fast_recovery_area/ORCL11G/backupset/2016_01_14/o1_mf_nnndf_TAG20160114T114712_c9g6l0l2_.bkp tag=TAG20160114T114712 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
Finished backup at 14-JAN-16
Starting backup at 14-JAN-16
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=19 RECID=18 STAMP=901108107
channel ORA_DISK_1: starting piece 1 at 14-JAN-16
channel ORA_DISK_1: finished piece 1 at 14-JAN-16
piece handle=/u2/oracle/fast_recovery_area/ORCL11G/backupset/2016_01_14/o1_mf_annnn_TAG20160114T114827_c9g6ncw6_.bkp tag=TAG20160114T114827 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 14-JAN-16
Starting Control File and SPFILE Autobackup at 14-JAN-16
piece handle=/u2/oracle/fast_recovery_area/ORCL11G/autobackup/2016_01_14/o1_mf_s_901108109_c9g6nffq_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 14-JAN-16
RMAN> connect auxiliary sys/oracle@aux ----连接auxiliary DB
connected to auxiliary database: AUX (not mounted)
RMAN> duplicate target database to aux ----开始复制
2> pfile=/u2/oracle/product/11.2.0/dbhome_1/dbs/initaux.ora
3> logfile
4> ‘/u2/oracle/oradata/aux/redo01.dbf‘ size 50M,
5> ‘/u2/oracle/oradata/aux/redo02.dbf‘ size 50M,
6> ‘/u2/oracle/oradata/aux/redo03.dbf‘ size 50M;
Starting Duplicate Db at 14-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=125 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 271400960 bytes
Fixed Size 2225672 bytes
Variable Size 109054456 bytes
Database Buffers 155189248 bytes
Redo Buffers 4931584 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
‘‘ORCL11G‘‘ comment=
‘‘Modified by RMAN duplicate‘‘ scope=spfile";
sql clone "alter system set db_unique_name =
‘‘AUX‘‘ comment=
‘‘Modified by RMAN duplicate‘‘ scope=spfile";
shutdown clone immediate;
startup clone force nomount
restore clone primary controlfile;
alter clone database mount;
}
executing Memory Script
sql statement: alter system set db_name = ‘‘ORCL11G‘‘ comment= ‘‘Modified by RMAN duplicate‘‘ scope=spfile
sql statement: alter system set db_unique_name = ‘‘AUX‘‘ comment= ‘‘Modified by RMAN duplicate‘‘ scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area 271400960 bytes
Fixed Size 2225672 bytes
Variable Size 109054456 bytes
Database Buffers 155189248 bytes
Redo Buffers 4931584 bytes
Starting restore at 14-JAN-16
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=133 device type=DISK
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u2/oracle/fast_recovery_area/ORCL11G/autobackup/2016_01_14/o1_mf_s_901108109_c9g6nffq_.bkp
channel ORA_AUX_DISK_1: piece handle=/u2/oracle/fast_recovery_area/ORCL11G/autobackup/2016_01_14/o1_mf_s_901108109_c9g6nffq_.bkp tag=TAG20160114T114828
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u2/oracle/oradata/aux/control01.ctl
output file name=/u2/oracle/fast_recovery_area/aux/control02.ctl
Finished restore at 14-JAN-16
database mounted
contents of Memory Script:
{
set until scn 1404181;
set newname for datafile 1 to
"/u2/oracle/oradata/aux/system01.dbf";
set newname for datafile 2 to
"/u2/oracle/oradata/aux/sysaux01.dbf";
set newname for datafile 3 to
"/u2/oracle/oradata/aux/undotbs01.dbf";
set newname for datafile 4 to
"/u2/oracle/oradata/aux/users01.dbf";
set newname for datafile 5 to
"/u2/oracle/oradata/aux/tom01.dbf";
restore
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 14-JAN-16
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u2/oracle/oradata/aux/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u2/oracle/oradata/aux/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u2/oracle/oradata/aux/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u2/oracle/oradata/aux/users01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u2/oracle/oradata/aux/tom01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u2/oracle/fast_recovery_area/ORCL11G/backupset/2016_01_14/o1_mf_nnndf_TAG20160114T114712_c9g6l0l2_.bkp
channel ORA_AUX_DISK_1: piece handle=/u2/oracle/fast_recovery_area/ORCL11G/backupset/2016_01_14/o1_mf_nnndf_TAG20160114T114712_c9g6l0l2_.bkp tag=TAG20160114T114712
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:15
Finished restore at 14-JAN-16
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=6 STAMP=901108249 file name=/u2/oracle/oradata/aux/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=7 STAMP=901108249 file name=/u2/oracle/oradata/aux/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=8 STAMP=901108249 file name=/u2/oracle/oradata/aux/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=9 STAMP=901108249 file name=/u2/oracle/oradata/aux/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=10 STAMP=901108249 file name=/u2/oracle/oradata/aux/tom01.dbf
contents of Memory Script:
{
set until scn 1404181;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 14-JAN-16
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 19 is already on disk as file /u2/oracle/arch/1_19_900436609.dbf
archived log file name=/u2/oracle/arch/1_19_900436609.dbf thread=1 sequence=19
media recovery complete, elapsed time: 00:00:01
Finished recover at 14-JAN-16
Oracle instance started
Total System Global Area 271400960 bytes
Fixed Size 2225672 bytes
Variable Size 104860152 bytes
Database Buffers 159383552 bytes
Redo Buffers 4931584 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "AUX" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ‘/u2/oracle/oradata/aux/redo01.dbf‘ SIZE 50 M ,
GROUP 2 ‘/u2/oracle/oradata/aux/redo02.dbf‘ SIZE 50 M ,
GROUP 3 ‘/u2/oracle/oradata/aux/redo03.dbf‘ SIZE 50 M
DATAFILE
‘/u2/oracle/oradata/aux/system01.dbf‘
CHARACTER SET WE8MSWIN1252
contents of Memory Script:
{
set newname for tempfile 1 to
"/u2/oracle/oradata/aux/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/u2/oracle/oradata/aux/sysaux01.dbf",
"/u2/oracle/oradata/aux/undotbs01.dbf",
"/u2/oracle/oradata/aux/users01.dbf",
"/u2/oracle/oradata/aux/tom01.dbf";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u2/oracle/oradata/aux/temp01.dbf in control file
cataloged datafile copy
datafile copy file name=/u2/oracle/oradata/aux/sysaux01.dbf RECID=1 STAMP=901108255
cataloged datafile copy
datafile copy file name=/u2/oracle/oradata/aux/undotbs01.dbf RECID=2 STAMP=901108255
cataloged datafile copy
datafile copy file name=/u2/oracle/oradata/aux/users01.dbf RECID=3 STAMP=901108255
cataloged datafile copy
datafile copy file name=/u2/oracle/oradata/aux/tom01.dbf RECID=4 STAMP=901108255
datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=901108255 file name=/u2/oracle/oradata/aux/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=901108255 file name=/u2/oracle/oradata/aux/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=901108255 file name=/u2/oracle/oradata/aux/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=901108255 file name=/u2/oracle/oradata/aux/tom01.dbf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 14-JAN-16
7.检查auxiliary DB
[oracle@openstack-node1 ~]$ export ORACLE_SID=aux
[oracle@openstack-node1 ~]$ echo $ORACLE_SID
aux
[oracle@openstack-node1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Thu Jan 14 14:15:36 2016
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u2/oracle/oradata/aux/system01.dbf
/u2/oracle/oradata/aux/sysaux01.dbf
/u2/oracle/oradata/aux/undotbs01.dbf
/u2/oracle/oradata/aux/users01.dbf
/u2/oracle/oradata/aux/tom01.dbf
SQL> select status from v$instance;
STATUS
------------
OPEN
SQL> show parameter name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert string orcl11g, aux
db_name string aux
db_unique_name string aux
global_names boolean FALSE
instance_name string aux
lock_name_space string
log_file_name_convert string
service_names string aux.us.oracle.com
原文地址:http://4538453.blog.51cto.com/4528453/1734993