使用rman中的duplicate复制数据库

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用rman中的duplicate复制数据库相关的知识,希望对你有一定的参考价值。

目标库和复制库环境:
OS: Linux Red Hat AS 4
DB Version: 10.2.0.1
 
1.目标库和复制库信息
Rman 中的目标库(target database)指的是被复制的库,复制库(duplicate database)是指复制后生成的新库.这里为了测试方便,复制库和目标库的目录结构设置相同.
 
目标库:
IP:192.168.30.37
SID:oracl
 
复制库:
IP:192.168.30.43
SID:oraclbak
 
2.在复制库上的的操作步骤
执行以下操作的前提是需要安装oracle软件(不创建数据库),需要创建oracle用户.
 
2.1: 创建密码文件(注意linux下密码文件的命名格式是orapw+sid)
[[email protected] dbs]$cd $ORACLE_HOME/dbs
[[email protected] dbs]$orapwd file=orapworaclbak password=oracle entries=10 force=y
 
2.2:创建如下目录
mkdir -p /u01/app/oracle/admin/oracl/adump
mkdir -p /u01/app/oracle/admin/oracl/bdump
mkdir -p /u01/app/oracle/admin/oracl/cdump
mkdir -p /u01/app/oracle/admin/oracl/dpdump
mkdir -p /u01/app/oracle/admin/oracl/pfile
mkdir -p /u01/app/oracle/admin/oracl/udump
mkdir -p /u01/app/oracle/oradata/oracl
mkdir -p /u01/app/oracle/flash_recovery_area
 
2.3:创建spfile文件
将在target上创建的pfile(initoracl.ora,具体创建步骤参考3.1)拷贝到Duplicate,修改参数(*.db_name=‘oraclbak‘),其他跟目标库保持一致,然后创建spfile.
Sql>connect /as sysdba;
Sql>create spfile from pfile=‘/u01/app/oracle/product/10.2.0/db_1/dbs/initoracl.ora‘;
 
2.4:启动数据库到nomount状态
Sql>startup nomount;
2.5:创建监听
[[email protected] dbs]$netca
2.6:配置tnsname
[[email protected] dbs]$netmgr
注意要配置到复制duplicate库的连接和到目标target库的连接.
 
3.在目标库上的的操作步骤
3.1:创建pfile文件
SQL>create pfile=‘/u01/app/oracle/product/10.2.0/db_1/dbs/initoracl.ora‘ from spfile;
3.2:将数据库置于归档模式(若数据库已经在归档模式,该步骤可以省略)
Sql>shutdown immediate;
Sql>startup mount;
Sql>alter database archivelog;
sql>alter system set log_archive_dest_1=‘LOCATION=/u01/app/oracle/duplicate‘ scope=both;
sql>alter database open;
 
3.3:备份数据库(我的库有坏块,指定了maxcorrupt)
$rman target /
Rman>run{
set maxcorrupt for datafile 5 to 20;
allocate channel dup type disk;
backup format ‘/u01/app/oracle/duplicate/df_t%t_s%s_p%p‘ database;
sql ‘alter system archive log current‘;
backup format ‘/u01/app/oracle/duplicate/al_t%t_s%s_p%p‘ archivelog all delete input;
release channel dup;
}
 
3.4:传送文件
将备份好的备份集文件传送到复制库的/app/oracle/duplicate/下.

4.复制数据库
以下操作在复制库duplicate主机上执行.
[[email protected] duplicate]$ rman target sys/[email protected]_oracl --(这里的tar_oracl是在连接到目标库的tnsname)
RMAN>connect auxiliary sys/[email protected]_oracl --(这里的dup_oracl是在连接到复制库的tnsname)
 
RMAN>run{
duplicate target database to oraclbak nofilenamecheck
logfile group 1 (‘/u01/app/oracle/oradata/oracl/redo1_1.log‘,‘/u01/app/oracle/oradata/oracl/redo1_2.log‘) size 512M,
group 2 (‘/u01/app/oracle/oradata/oracl/redo2_1.log‘,‘/u01/app/oracle/oradata/oracl/redo2_2.log‘) size 512M,
group 3 (‘/u01/app/oracle/oradata/oracl/redo3_1.log‘,‘/u01/app/oracle/oradata/oracl/redo3_2.log‘) size 512M;
}
-- 这里使用了nofilenamecheck,是因为复制库和目标库的各文件目录一致.
Starting Duplicate Db at 13-FEB-12
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=156 devtype=DISK

contents of Memory Script:
{
   set until scn  1556049;
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/oracl/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/oradata/oracl/undotbs01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/oracl/sysaux01.dbf";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/oracl/users01.dbf";
   set newname for datafile  5 to
 "/u01/app/oracle/oradata/oracl/hxl01.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 13-FEB-12
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/oracl/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/oracl/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/oracl/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/oracl/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/oracl/hxl01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/duplicate/df_t775114282_s89_p1
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/duplicate/df_t775114282_s89_p1 tag=TAG20120213T053120
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:47
Finished restore at 13-FEB-12
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORACL" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( ‘/u01/app/oracle/oradata/oracl/redo1_1.log‘, ‘/u01/app/oracle/oradata/oracl/redo1_2.log‘ ) SIZE 512 M ,
  GROUP  2 ( ‘/u01/app/oracle/oradata/oracl/redo2_1.log‘, ‘/u01/app/oracle/oradata/oracl/redo2_2.log‘ ) SIZE 512 M ,
  GROUP  3 ( ‘/u01/app/oracle/oradata/oracl/redo3_1.log‘, ‘/u01/app/oracle/oradata/oracl/redo3_2.log‘ ) SIZE 512 M
 DATAFILE
  ‘/u01/app/oracle/oradata/oracl/system01.dbf‘
 CHARACTER SET AL32UTF8


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=775102986 filename=/u01/app/oracle/oradata/oracl/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=775102987 filename=/u01/app/oracle/oradata/oracl/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=775102987 filename=/u01/app/oracle/oradata/oracl/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=775102987 filename=/u01/app/oracle/oradata/oracl/hxl01.dbf

contents of Memory Script:
{
   set until scn  1556049;
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 13-FEB-12
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=156 devtype=DISK

starting media recovery

channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=47
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=48
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/duplicate/al_t775114352_s91_p1
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/duplicate/al_t775114352_s91_p1 tag=TAG20120213T053230
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:16
archive log filename=/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_02_13/o1_mf_1_47_7mj0wydg_.arc thread=1 sequence=47
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_02_13/o1_mf_1_47_7mj0wydg_.arc recid=2 stamp=775103016
archive log filename=/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_02_13/o1_mf_1_48_7mj0x0qm_.arc thread=1 sequence=48
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_02_13/o1_mf_1_48_7mj0x0qm_.arc recid=1 stamp=775103009
media recovery complete, elapsed time: 00:00:09
Finished recover at 13-FEB-12

contents of Memory Script:
{
   shutdown clone;
   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     524288000 bytes

Fixed Size                     1220360 bytes
Variable Size                138412280 bytes
Database Buffers             381681664 bytes
Redo Buffers                   2973696 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORACL" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( ‘/u01/app/oracle/oradata/oracl/redo1_1.log‘, ‘/u01/app/oracle/oradata/oracl/redo1_2.log‘ ) SIZE 512 M ,
  GROUP  2 ( ‘/u01/app/oracle/oradata/oracl/redo2_1.log‘, ‘/u01/app/oracle/oradata/oracl/redo2_2.log‘ ) SIZE 512 M ,
  GROUP  3 ( ‘/u01/app/oracle/oradata/oracl/redo3_1.log‘, ‘/u01/app/oracle/oradata/oracl/redo3_2.log‘ ) SIZE 512 M
 DATAFILE
  ‘/u01/app/oracle/oradata/oracl/system01.dbf‘
 CHARACTER SET AL32UTF8


contents of Memory Script:
{
   set newname for tempfile  1 to
 "/u01/app/oracle/oradata/oracl/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata/oracl/undotbs01.dbf";
   catalog clone datafilecopy  "/u01/app/oracle/oradata/oracl/sysaux01.dbf";
   catalog clone datafilecopy  "/u01/app/oracle/oradata/oracl/users01.dbf";
   catalog clone datafilecopy  "/u01/app/oracle/oradata/oracl/hxl01.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed temporary file 1 to /u01/app/oracle/oradata/oracl/temp01.dbf in control file

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/oracl/undotbs01.dbf recid=1 stamp=775103080

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/oracl/sysaux01.dbf recid=2 stamp=775103081

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/oracl/users01.dbf recid=3 stamp=775103083

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/oracl/hxl01.dbf recid=4 stamp=775103084

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=775103080 filename=/u01/app/oracle/oradata/oracl/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=775103081 filename=/u01/app/oracle/oradata/oracl/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=775103083 filename=/u01/app/oracle/oradata/oracl/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=775103084 filename=/u01/app/oracle/oradata/oracl/hxl01.dbf

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 13-FEB-12
 

小插曲:
数据库打开后使用sysdba登陆提示ORA-01031: insufficient privileges,找了半天原因是密码文件命名问题, 之前创建密码文件名为orapwdoraclbak,将其修改为orapworaclbak,问题解决,注意在linux下密码文件的命名格式为orapw+sid.
SQL> connect 
sys/[email protected]_oracl
 as sysdba
ERROR:
ORA-01031: insufficient privileges
 
常见问题:
1.恢复的时候找不到某个归档日志
在复制数据库恢复的过程中找不到具体某个归档日志会报如下错误:
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 02/14/2012 01:01:41
RMAN-03015: error occurred in stored script Memory Script
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of log thread 1 seq 53 lowscn 1597845 found to restore
 
这个时候需要将目标库的该归档日志拷贝过来或是在做复制的时候使用set until指定具体恢复到某个sequence或是scn,如:
 
run{
SET until sequence 52;
duplicate target database to oraclbak nofilenamecheck
logfile group 1 (‘/u01/app/oracle/oradata/oracl/redo1_1.log‘,‘/u01/app/oracle/oradata/oracl/redo1_2.log‘) size 512M,
group 2 (‘/u01/app/oracle/oradata/oracl/redo2_1.log‘,‘/u01/app/oracle/oradata/oracl/redo2_2.log‘) size 512M,
group 3 (‘/u01/app/oracle/oradata/oracl/redo3_1.log‘,‘/u01/app/oracle/oradata/oracl/redo3_2.log‘) size 512M;
}
 
--The End--
转:http://blog.chinaunix.net/uid-77311-id-3066925.html

以上是关于使用rman中的duplicate复制数据库的主要内容,如果未能解决你的问题,请参考以下文章

Oracle11gR2使用RMAN duplicate复制数据库——active database duplicate

Oracle11gR2使用RMAN duplicate复制数据库——Backup-based database duplicate

100天精通Oracle-实战系列(第18天)RMAN Duplicate 异机复制 Oracle 数据库

100天精通Oracle-实战系列(第18天)RMAN Duplicate 异机复制 Oracle 数据库

RMAN高级应用之不同环境下的复制流程

rman duplicate 比較重要的知识点