1.使用 RMAN 创建数据库副本
使用 RMAN 的 DUPLICATE 命令可根据目标数据库备份创建数据库副本。
创建数据库副本:
1.创建辅助实例的 Oracle 口令文件。
2.
建立到辅助实例的 Oracle Net 连接。
3.
创建辅助实例的初始化参数文件。
4.在 NOMOUNT 模式下启动辅助实例。
5.
装载或打开目标数据库。
6.确保备份和归档重做日志文件可用。
7.根据需要分配辅助通道。
8.执行 DUPLICATE 命令。
创建辅助实例的初始化参数文件 :
请按如下方式指定参数:
DB_BLOCK_SIZE
指定的值应与为目标数据库设置的值相同。
指定用于控制文件命名的参数:
指定下列参数可控制辅助数据库的文件命名:
CONTROL_FILES
DB_FILE_NAME_CONVERT
LOG_FILE_NAME_CONVERT
在 NOMOUNT 模式下启动实例 :
在 NOMOUNT 模式下启动辅助实例。
根据用来启动实例的文本初始化参数文件创建服务器参数文件 (SPFILE)。
确保备份和归档重做日志文件可用 :
在副本主机上必须能访问所有目标数据库数据文件的备份。
备份可以是完全备份和增量备份的组合。
在副本主机上必须能访问恢复数据库副本所需的归档重做日志文件。
归档重做日志文件可以是:
--介质管理器上的备份
--映像副本
--实际的归档重做日志文件
分配辅助通道 :
使用 RMAN 的 DUPLICATE 命令:
RMAN> RUN
{ALLOCATE AUXILIARY CHANNEL aux1 DEVICE TYPE DISK;
ALLOCATE AUXILIARY CHANNEL aux2 DEVICE TYPE DISK;
…
DUPLICATE TARGET DATABASE to auxdb;
}
当您执行 DUPLICATE 命令时,RMAN 会执行下列操作:
1.创建数据库副本的控制文件
2.
将目标数据文件还原到数据库副本
3.使用所有可用的增量备份和归档重做日志文件执行不完全恢复
4.关闭辅助实例后又重新启动它
5.通过 RESETLOGS 选项打开数据库副本
6.创建联机重做日志文件
7.为数据库副本生成新的唯一 DBID
指定 DUPLICATE 命令的选项
请在执行 DUPLICATE 命令时根据需要指定其它选项。
SKIP READONLY:用于排除只读表空间数据文件。
SKIP TABLESPACE:用于从目标数据库中排除表空间。不能排除 SYSTEM 表空间或包含还原段或回退段的表空间。
OPEN RESTRICTED:用于在数据库打开之后自动启用 RESTRICTED SESSION。
具体实验:
[oracle@ocmu ~]$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Sun Mar 31 15:39:16 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORA11GR2 (DBID=116453860)
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
using target database control file instead of recovery catalog
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;
Starting backup at 31-MAR-13
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
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=8 RECID=1 STAMP=811520735
input archived log thread=1 sequence=9 RECID=2 STAMP=811520750
input archived log thread=1 sequence=10 RECID=3 STAMP=811520772
input archived log thread=1 sequence=11 RECID=4 STAMP=811520783
input archived log thread=1 sequence=12 RECID=5 STAMP=811520796
input archived log thread=1 sequence=13 RECID=6 STAMP=811525192
channel ORA_DISK_1: starting piece 1 at 31-MAR-13
channel ORA_DISK_1: finished piece 1 at 31-MAR-13
piece handle=/u01/app/FRA/ORA11GR2/backupset/2013_03_31/o1_mf_annnn_TAG20130331T153953_8oht29yn_.bkp tag=TAG20130331T153953 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:04
Finished backup at 31-MAR-13
Starting backup at 31-MAR-13
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=/u01/app/oracle/oradata/ORA11GR2/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/ORA11GR2/example01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/ORA11GR2/users01.dbf
channel ORA_DISK_1: starting piece 1 at 31-MAR-13
channel ORA_DISK_1: finished piece 1 at 31-MAR-13
piece handle=/u01/app/FRA/ORA11GR2/backupset/2013_03_31/o1_mf_nnndf_TAG20130331T154059_8oht4jr1_.bkp tag=TAG20130331T154059 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:04:33
Finished backup at 31-MAR-13
Starting backup at 31-MAR-13
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=14 RECID=7 STAMP=811525533
channel ORA_DISK_1: starting piece 1 at 31-MAR-13
channel ORA_DISK_1: finished piece 1 at 31-MAR-13
piece handle=/u01/app/FRA/ORA11GR2/backupset/2013_03_31/o1_mf_annnn_TAG20130331T154533_8ohtdxrl_.bkp tag=TAG20130331T154533 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 31-MAR-13
Starting Control File and SPFILE Autobackup at 31-MAR-13
piece handle=/u01/app/FRA/ORA11GR2/autobackup/2013_03_31/o1_mf_s_811525535_8ohtf2n9_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 31-MAR-13
RMAN>
1) 创建密码文件
[oracle@ocmu ~]$ cd $ORACLE_HOME/dbs
[oracle@ocmu dbs]$ orapwd file= orapwORA11GR2 password=oracle entries=10
[oracle@ocmu dbs]$ ls orapw*
orapwORA11GR2
[oracle@ocmu dbs]$
2) 编辑tnsnames
[oracle@ocmu ~]$ cd $ORACLE_HOME/network/admin
[oracle@ocmu admin]$ vi tnsnames.ora
ORA11GR2 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = ocmu)(PORT = 1521)) ) (CONNECT_DATA = (ORACLE_SID = ORA11GR2) ) ) |
3) 将源库的pfile文件拷贝到目标数据库
[oracle@ocmu ~]$ cd $ORACLE_HOME/dbs
[oracle@ocmu dbs]$
scp 192.168.1.200:/u01/app/oracle/product/11.2.0/db_1/dbs/initORA11GR2.ora .
The authenticity of host '192.168.1.200 (192.168.1.200)' can't be established.
RSA key fingerprint is 35:b3:59:37:e6:a1:3b:34:7d:01:84:ee:5d:9b:48:24.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.200' (RSA) to the list of known hosts.
oracle@192.168.1.200's password:
initORA11GR2.ora 100% 948 0.9KB/s 00:00
[oracle@ocmu dbs]$
[oracle@ocmu ~]$ mkdir -p /u01/app/oracle/oradata/ORA11GR2
[oracle@ocmu ~]$ mkdir -p /u01/app/FRA/ORA11GR2
[oracle@ocmu ~]$ mkdir -p /u01/app/oracle/admin/ORA11GR2/adump
5) 将源库快速恢复区内容拷贝到目标库
[oracle@ocmu ~]$ cd /u01/app/FRA/ORA11GR2
[oracle@ocmu ORA11GR2]$ ls
[oracle@ocmu ORA11GR2]$
scp -r 192.168.1.200:/u01/app/FRA/ORA11GR2/archivelog .
oracle@192.168.1.200's password:
o1_mf_1_12_8ohorqkc_.arc 100% 48MB 24.1MB/s 00:02
o1_mf_1_11_8ohorc4n_.arc 100% 48MB 24.1MB/s 00:02
o1_mf_1_9_8ohoq8dx_.arc 100% 46MB 3.8MB/s 00:12
o1_mf_1_14_8ohtdx3d_.arc 100% 357KB 357.0KB/s 00:00
o1_mf_1_13_8oht26d8_.arc 100% 21MB 21.1MB/s 00:01
o1_mf_1_10_8ohoqxot_.arc 100% 48MB 24.1MB/s 00:02
o1_mf_1_8_8ohops0g_.arc 100% 44MB 3.1MB/s 00:14
[oracle@ocmu ORA11GR2]$
scp -r 192.168.1.200:/u01/app/FRA/ORA11GR2/autobackup .
oracle@192.168.1.200's password:
o1_mf_s_811525535_8ohtf2n9_.bkp 100% 9600KB 9.4MB/s 00:01
[oracle@ocmu ORA11GR2]$
scp -r 192.168.1.200:/u01/app/FRA/ORA11GR2/backupset .
oracle@192.168.1.200's password:
o1_mf_annnn_TAG20130331T153953_8oht29yn_.bkp 100% 256MB 9.8MB/s 00:26
o1_mf_nnndf_TAG20130331T154059_8oht4jr1_.bkp 100% 1142MB 7.7MB/s 02:29
o1_mf_annnn_TAG20130331T154533_8ohtdxrl_.bkp 100% 359KB 358.5KB/s 00:00
[oracle@ocmu ORA11GR2]$
6) 目标库启动到nomount模式
[oracle@ocmu ~]$ export ORACLE_SID=ORA11GR2
[oracle@ocmu ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Sun Mar 31 16:29:42 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 841162752 bytes
Fixed Size 1339768 bytes
Variable Size 532680328 bytes
Database Buffers 301989888 bytes
Redo Buffers 5152768 bytes
SQL>
7) 目标库运行duplicate命令
[oracle@ocmu ~]$ export ORACLE_SID=ORA11GR2
[oracle@ocmu ~]$ rman target sys/oracle@ora11gr2 auxiliary /
Recovery Manager: Release 11.2.0.1.0 - Production on Sun Mar 31 16:48:18 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORA11GR2 (DBID=116453860)
connected to auxiliary database: ORA11GR2 (not mounted)
RMAN> duplicate target database to ORA11GR2 pfile =/u01/app/oracle/product/11.2.0/db_1/dbs/initORA11GR2.ora
logfile
'/u01/app/oracle/oradata/ORA11GR2/redo01.log' size 50m,
'/u01/app/oracle/oradata/ORA11GR2/redo02.log' size 50m,
'/u01/app/oracle/oradata/ORA11GR2/redo03.log' size 50m
NOFILENAMECHECK;
Starting Duplicate Db at 31-MAR-13
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=20 device type=DISK
contents of Memory Script:
{
sql clone "alter system set db_name =
''ORA11GR2'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''ORA11GR2'' 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 = ''ORA11GR2'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set db_unique_name = ''ORA11GR2'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area 841162752 bytes
Fixed Size 1339768 bytes
Variable Size 536874632 bytes
Database Buffers 297795584 bytes
Redo Buffers 5152768 bytes
Starting restore at 31-MAR-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=18 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 /u01/app/FRA/ORA11GR2/autobackup/2013_03_31/o1_mf_s_811525535_8ohtf2n9_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/FRA/ORA11GR2/autobackup/2013_03_31/o1_mf_s_811525535_8ohtf2n9_.bkp tag=TAG20130331T154535
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/u01/app/oracle/oradata/ORA11GR2/control01.ctl
output file name=/u01/app/oracle/oradata/ORA11GR2/control02.ctl
Finished restore at 31-MAR-13
database mounted
contents of Memory Script:
{
set until scn 893076;
set newname for datafile 1 to
"/u01/app/oracle/oradata/ORA11GR2/system01.dbf";
set newname for datafile 2 to
"/u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf";
set newname for datafile 3 to
"/u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf";
set newname for datafile 4 to
"/u01/app/oracle/oradata/ORA11GR2/users01.dbf";
set newname for datafile 5 to
"/u01/app/oracle/oradata/ORA11GR2/example01.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 31-MAR-13
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 /u01/app/oracle/oradata/ORA11GR2/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/ORA11GR2/users01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/ORA11GR2/example01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/FRA/ORA11GR2/backupset/2013_03_31/o1_mf_nnndf_TAG20130331T154059_8oht4jr1_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/FRA/ORA11GR2/backupset/2013_03_31/o1_mf_nnndf_TAG20130331T154059_8oht4jr1_.bkp tag=TAG20130331T154059
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:02:36
Finished restore at 31-MAR-13
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=2 STAMP=811529474 file name=/u01/app/oracle/oradata/ORA11GR2/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=3 STAMP=811529474 file name=/u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=811529474 file name=/u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=811529474 file name=/u01/app/oracle/oradata/ORA11GR2/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=6 STAMP=811529474 file name=/u01/app/oracle/oradata/ORA11GR2/example01.dbf
contents of Memory Script:
{
set until scn 893076;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 31-MAR-13
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 14 is already on disk as file /u01/app/FRA/ORA11GR2/archivelog/2013_03_31/o1_mf_1_14_8ohtdx3d_.arc
archived log file name=/u01/app/FRA/ORA11GR2/archivelog/2013_03_31/o1_mf_1_14_8ohtdx3d_.arc thread=1 sequence=14
media recovery complete, elapsed time: 00:00:04
Finished recover at 31-MAR-13
contents of Memory Script:
{
shutdown clone immediate;
startup clone nomount pfile= '/u01/app/oracle/product/11.2.0/db_1/dbs/initORA11GR2.ora';
}
executing Memory Script
database dismounted
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 841162752 bytes
Fixed Size 1339768 bytes
Variable Size 532680328 bytes
Database Buffers 301989888 bytes
Redo Buffers 5152768 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORA11GR2" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/ORA11GR2/redo01.log' SIZE 50 M ,
GROUP 2 '/u01/app/oracle/oradata/ORA11GR2/redo02.log' SIZE 50 M ,
GROUP 3 '/u01/app/oracle/oradata/ORA11GR2/redo03.log' SIZE 50 M
DATAFILE
'/u01/app/oracle/oradata/ORA11GR2/system01.dbf'
CHARACTER SET AL32UTF8
contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/app/oracle/oradata/ORA11GR2/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf",
"/u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf",
"/u01/app/oracle/oradata/ORA11GR2/users01.dbf",
"/u01/app/oracle/oradata/ORA11GR2/example01.dbf";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/ORA11GR2/temp01.dbf in control file
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf RECID=1 STAMP=811529493
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf RECID=2 STAMP=811529493
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/ORA11GR2/users01.dbf RECID=3 STAMP=811529493
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/ORA11GR2/example01.dbf RECID=4 STAMP=811529493
datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=811529493 file name=/u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=811529493 file name=/u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=811529493 file name=/u01/app/oracle/oradata/ORA11GR2/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=811529493 file name=/u01/app/oracle/oradata/ORA11GR2/example01.dbf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 31-MAR-13
RMAN>
2.使用EM复制数据库