关于RMAN 复制的理论知识,参考我的Blog:
RMAN 复制目标数据库的理论知识
http://www.cndba.cn/Dave/article/1057
实验平台: redhat + oracle 10g
源库的相关信息:
ORACLE_BASE: /u01/app/oracle
ORACLE_HOME: /u01/app/oracle/product/10.2.0/db_1
ORACLE_SID:ORCL
复制的数据库实例名假设为: DAVE
步骤如下:
(1)构建辅助数据库目录结构
(2)修改init.ora 初始话文件
(3)创建辅助实例口令文件
(4)RMAN 备份源库
(5)配置监听
(6)启动辅助库至nomount 状态
(7)RMAN duplicate复制实例
(8)创建spfile
一.构建辅助数据库目录结构
1.1 Oracle data 目录
[oracle@db1 oradata]$ ls
orcl
[oracle@db1 oradata]$ pwd
/u01/app/oracle/oradata
[oracle@db1 oradata]$ mkdir DAVE
[oracle@db1 oradata]$ ls
DAVE orcl
1.2 其他目录
[oracle@db1 admin]$ pwd
/u01/app/oracle/admin
[oracle@db1 admin]$ mkdir DAVE
[oracle@db1 admin]$ ls
DAVE orcl
[oracle@db1 admin]$ cd orcl
[oracle@db1 orcl]$ ls
adump bdump cdump dpdump pfile udump
[oracle@db1 DAVE]$ cd ..
[oracle@db1 admin]$ cd DAVE
[oracle@db1 DAVE]$ mkdir bdump
[oracle@db1 DAVE]$ mkdir cdump
[oracle@db1 DAVE]$ mkdir pfile
[oracle@db1 DAVE]$ mkdir udump
[oracle@db1 DAVE]$ ls
adump bdump cdump dpdump pfile udump
二.修改init.ora初始化文件
2.1 生成源库的pfile 文件,默认生成位置在$ORACLE_HOME/dbs目录下:
SQL> conn / as sysdba
Connected.
SQL> create pfile from spfile;
File created.
2.2 进入$ORACLE_HOME/dbs目录,将init 文件copy并重命名为initDAVE.ora.这个命名格式必须和实例名相同,不然数据库不能识别。
[oracle@db1 DAVE]$ cd $ORACLE_HOME/dbs
[oracle@db1 dbs]$ ls
hc_orcl.dat init.ora lkORCL snapcf_orcl.f
initdw.ora initorcl.ora orapworcl spfileorcl.ora
[oracle@db1 dbs]$ cp initorcl.ora initDAVE.ora
[oracle@db1 dbs]$ ls
hc_orcl.dat initdw.ora initorcl.ora orapworcl spfileorcl.ora
initDAVE.ora init.ora lkORCL snapcf_orcl.f
2.3 修改initDAVE.ora 文件,将orcl 改成DAVE
[oracle@db1 dbs]$ more initDAVE.ora
orcl.__db_cache_size=171966464
orcl.__java_pool_size=4194304
orcl.__large_pool_size=4194304
orcl.__shared_pool_size=58720256
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/DAVE/adump'
*.background_dump_dest='/u01/app/oracle/admin/DAVE/bdump'
*.compatible='10.2.0.1.0'
*.control_file_record_keep_time=14
*.control_files='/u01/app/oracle/oradata/DAVE/control01.ctl','/u01/app/oracle/oradata/DAVE/control02.ctl'
,'/u01/app/oracle/oradata/DAVE/control03.ctl'
*.core_dump_dest='/u01/app/oracle/admin/DAVE/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='DAVE'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.job_queue_processes=10
*.log_archive_dest_1='location=/u01/archivelog'
*.open_cursors=300
*.pga_aggregate_target=81788928
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=246415360
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/DAVE/udump'
db_file_name_convert = ('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/DAVE')
log_file_name_convert = ('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/DAVE')
其中红色部分就是修改的部分. Db_file_name_convert和log_file_name_convert两个参数是我们添加的,用来转换数据文件位置和redo log位置。 在复制完成后,可以删除这2个参数。
三.创建DAVE实例的口令文件
[oracle@db1 dbs]$ cd $ORACLE_HOME/bin
[oracle@db1 bin]$ orapwd file=$ORACLE_HOME/dbs/orapwDAVE password=admin
[oracle@db1 bin]$ cd $ORACLE_HOME/dbs
[oracle@db1 dbs]$ ls
hc_orcl.dat initdw.ora initorcl.ora orapwDAVE snapcf_orcl.f
initDAVE.ora init.ora lkORCL orapworcl spfileorcl.ora
windows下oracle默认的位置是$ORACLE_HOME/database目录,文件名格式是pwdSID.ora。
linux下oracle默认的位置是$ORACLE_HOME/dbs目录,文件名格式是orapwSID。
创建完后,数据库需要重启动,新的口令文件才能生效。
关于口令文件创建,详细内容参考blog:
Oracle OS认证 口令文件 密码丢失处理
http://blog.csdn.net/tianlesoftware/archive/2009/10/20/4698293.aspx
四.RMAN 备份源库(orcl)
[oracle@db1 u02]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Sun Jul 18 10:57:53 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1248423599)
RMAN>RUN {
allocate channel c1 type disk;
allocate channel c2 type disk;
BACKUP FORMAT '/u02/backup/orcl_%U_%T' skip inaccessible filesperset 5 DATABASE TAG orcl_hot_db_bk;
sql 'alter system archive log current';
BACKUP FORMAT '/u02/backup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL DELETE INPUT;
backup current controlfile tag='bak_ctlfile' format='/u02/backup/ctl_file_%U_%T';
backup spfile tag='spfile' format='/u02/backup/ORCL_spfile_%U_%T';
release channel c2;
release channel c1;
}
备份脚本,具体参考:
Linux 平台下 RMAN 全备 和 增量备份 shell 脚本
http://www.cndba.cn/Dave/article/1060
五.添加,配置监听
5.1 修改listener.ora 文件,添加如下内容
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = DAVE)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(SID_NAME = DAVE)
)
)
5.2 修改tnsnames.ora 文件,添加如下内容
DAVE=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = db1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = DAVE)
)
)
建议使用net manager 工具从界面来修改,这样不容易出错
Oracle 数据库监听配置
http://www.cndba.cn/dave/article/1232
Oracle Listener 动态注册 与 静态注册
http://www.cndba.cn/Dave/article/1177
六.启动辅助库到nomount状态
[oracle@db1 admin]$ export ORACLE_SID=DAVE
[oracle@db1 admin]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Jul 18 11:17:01 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup nomount pfile=?/dbs/initDAVE.ora -- 注意要指定pfile
ORACLE instance started.
Total System Global Area 247463936 bytes
Fixed Size 1218748 bytes
Variable Size 79693636 bytes
Database Buffers 159383552 bytes
Redo Buffers 7168000 bytes
SQL>
七.RMAN 连接到目标实例和辅助实例,运行duplicate 命令复制数据库
[oracle@db1 u02]$ export ORACLE_SID=orcl
[oracle@db1 u02]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Sun Jul 18 11:41:01 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1248423599)
RMAN> connect auxiliary sys/admin@DAVE;
connected to auxiliary database: DAVE (not mounted)
RMAN> duplicate target database to DAVE;
Starting Duplicate Db at 18-JUL-10
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 697286;
set newname for datafile 1 to "/u01/app/oracle/oradata/DAVE/system01.dbf"; -- 转换文件位置
set newname for datafile 2 to "/u01/app/oracle/oradata/DAVE/undotbs01.dbf";
set newname for datafile 3 to "/u01/app/oracle/oradata/DAVE/sysaux01.dbf";
set newname for datafile 4 to "/u01/app/oracle/oradata/DAVE/users01.dbf";
set newname for datafile 5 to "/u01/app/oracle/oradata/DAVE/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 18-JUL-10
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backupset restore -- 开始restore 数据文件
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to /u01/app/oracle/oradata/DAVE/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/DAVE/sysaux01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/DAVE/example01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/orcl_39lj3bmt_1_1_20100718
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/backup/orcl_39lj3bmt_1_1_20100718 tag=ORCL_HOT_DB_BK
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:47
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/DAVE/system01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/DAVE/users01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/orcl_38lj3bmt_1_1_20100718
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/backup/orcl_38lj3bmt_1_1_20100718 tag=ORCL_HOT_DB_BK
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 18-JUL-10
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DAVE" RESETLOGS ARCHIVELOG
-- 创建源库的控制文件,然后用这个控制文件进行恢复
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/u01/app/oracle/oradata/DAVE/redo01.log' ) SIZE 50 M REUSE,
GROUP 2 ( '/u01/app/oracle/oradata/DAVE/redo02.log' ) SIZE 50 M REUSE,
GROUP 3 ( '/u01/app/oracle/oradata/DAVE/redo03.log' ) SIZE 50 M REUSE
DATAFILE
'/u01/app/oracle/oradata/DAVE/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=724679047 filename=/u01/app/oracle/oradata/DAVE/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=724679047 filename=/u01/app/oracle/oradata/DAVE/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=724679047 filename=/u01/app/oracle/oradata/DAVE/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=724679047 filename=/u01/app/oracle/oradata/DAVE/example01.dbf
contents of Memory Script:
{
set until scn 697286;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 18-JUL-10 -- 开始recover 恢复数据
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=155 devtype=DISK
starting media recovery
channel ORA_AUX_DISK_1: starting archive log restore to default destination
-- 先将归档日志还原到指定的归档目录: log_archive_dest 参数指定
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=41
channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/arch_3dlj3bro_1_1_20100718
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/backup/arch_3dlj3bro_1_1_20100718 tag=TAG20100718T110111
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
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=40
channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/arch_3clj3bro_1_1_20100718
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/backup/arch_3clj3bro_1_1_20100718 tag=TAG20100718T110111
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archive log filename=/u01/archivelog/1_40_720642866.dbf thread=1 sequence=40
channel clone_default: deleting archive log(s)
archive log filename=/u01/archivelog/1_40_720642866.dbf recid=2 stamp=724679053
archive log filename=/u01/archivelog/1_41_720642866.dbf thread=1 sequence=41
channel clone_default: deleting archive log(s)
archive log filename=/u01/archivelog/1_41_720642866.dbf recid=1 stamp=724679052
media recovery complete, elapsed time: 00:00:04
Finished recover at 18-JUL-10
contents of Memory Script:
{
shutdown clone;
startup clone nomount ;
-- 这里要注意的一个地方,在这一步的时候,辅助实例不能有任何session打开,即不能有有任何连接连接到DAVE上,不然它会一直那个session 退出后才能执行
}
executing Memory Script
database dismounted
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 247463936 bytes
Fixed Size 1218748 bytes
Variable Size 79693636 bytes
Database Buffers 159383552 bytes
Redo Buffers 7168000 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DAVE" RESETLOGS ARCHIVELOG
--复制已经完成,创建新的控制文件(DAVE的控制文件),可以参考理论知识的连接
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/u01/app/oracle/oradata/DAVE/redo01.log' ) SIZE 50 M REUSE,
GROUP 2 ( '/u01/app/oracle/oradata/DAVE/redo02.log' ) SIZE 50 M REUSE,
GROUP 3 ( '/u01/app/oracle/oradata/DAVE/redo03.log' ) SIZE 50 M REUSE
DATAFILE
'/u01/app/oracle/oradata/DAVE/system01.dbf'
CHARACTER SET WE8ISO8859P1
contents of Memory Script:
{
set newname for tempfile 1 to "/u01/app/oracle/oradata/DAVE/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/u01/app/oracle/oradata/DAVE/undotbs01.dbf";
catalog clone datafilecopy "/u01/app/oracle/oradata/DAVE/sysaux01.dbf";
catalog clone datafilecopy "/u01/app/oracle/oradata/DAVE/users01.dbf";
catalog clone datafilecopy "/u01/app/oracle/oradata/DAVE/example01.dbf";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed temporary file 1 to /u01/app/oracle/oradata/DAVE/temp01.dbf in control file
cataloged datafile copy datafile copy filename=/u01/app/oracle/oradata/DAVE/undotbs01.dbf recid=1 stamp=724679599
cataloged datafile copy datafile copy filename=/u01/app/oracle/oradata/DAVE/sysaux01.dbf recid=2 stamp=724679599
cataloged datafile copy datafile copy filename=/u01/app/oracle/oradata/DAVE/users01.dbf recid=3 stamp=724679599
cataloged datafile copy datafile copy filename=/u01/app/oracle/oradata/DAVE/example01.dbf recid=4 stamp=724679599
datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=724679599 filename=/u01/app/oracle/oradata/DAVE/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=724679599 filename=/u01/app/oracle/oradata/DAVE/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=724679599 filename=/u01/app/oracle/oradata/DAVE/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=724679599 filename=/u01/app/oracle/oradata/DAVE/example01.dbf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 18-JUL-10
八.修改辅助库的pfile,在创建spfile
8.1删除下面2句:
db_file_name_convert = ('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/DAVE')
log_file_name_convert = ('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/DAVE')
8.2 创建spfile
[oracle@db1 dbs]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Jul 18 12:11:28 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn sys/admin@DAVE as sysdba;
Connected.
SQL> create spfile from pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initDAVE.ora';
File created.
九.如果使用磁带备份
完成了上面的8步,RMAN的同机复制就已经完成了。 如果要在相同的服务器上复制磁带备份,只需要在最后运行duplicate命令前插入一个额外的步骤即可。 该步骤配置辅助通道,使之与执行备份的通道类型。
9.1 先在源库上执行show channel命令,查看通道信息
9.2 然后在创建相应的configure命令来匹配辅助的通道
------------------------------------------------------------------------------
QQ: 492913789
Email: ahdba@qq.com
Blog: http://www.cndba.cn/dave
网上资源: http://tianlesoftware.download.csdn.net
相关视频:http://blog.csdn.net/tianlesoftware/archive/2009/11/27/4886500.aspx
DBA1 群:62697716(满); DBA2 群:62697977
DBA3 群:63306533; 聊天 群:40132017