RMAN数据库复制实战
基于厌烦了EXPDP和IMPDP,我开始尝试使用RMAN的复制功能了,下面是我记录的全过程。
最核心的步骤如下是
1: Create an Oracle Password File for the Auxiliary Instance 为辅助实例准备一个密码文件。
2: Ensure Oracle Net Connectivity to the Auxiliary Instance 配置TNS,Listener等等服务
3: Create an Initialization Parameter File for the Auxiliary Instance为辅助实例建一个初始化的PFILE
4: nomount辅助实例
5: Mount or Open the Target Database ,mount或者OPEN复制源库
6: 配置catalog数据库,并且把源库注册到catalog管理库上,并且通过catalog库的RMAN来备份源库:backup full database ;备份好后,用scp命令复制到辅助实例的机器上。
7:开始复制命令DUPLICATE TARGET DATABASE TO SGPMDB nofilenamecheck;
以下是详细的步骤:
计划把172.19.201.240上的SGPMDB复制到172.19.4.1服务器,目录结构相同
1. 在4.1上创建密码文件 ,用oracle 用户,命令是
orapwd FILE=/app/oracle/base/product/10.2.0/db_1/dbs/orapwdsgpmdb PASSWORD=oracle ENTRIES=30
2. 我在172.19.4.1上和172.19.201.240上配置的TNS如下:
SGPMDBDU1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = 172.19.4.1)
(PORT = 1521)
)
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = SGPMDBDU1)
)
)
SGPMDB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.19.201.240)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = SGPMDB)
)
)
3,我的PFILE内容如下:
###########################################
#database Identification
###########################################
DB_NAME=SGPMDB
CONTROL_FILES=(/app/oracle/base/oradata/SGPMDB/control01.ctl,
/app/oracle/base/oradata/SGPMDB/control02.ctl,
/app/oracle/base/oradata/SGPMDB/control03.ctl)
###########################################
# Cache and I/O
###########################################
db_block_size=8192
# note that the following two initialization parameters have equivalents
# on the DUPLICATE command itself
DB_FILE_NAME_CONVERT=(/app/oracle/base/oradata/SGPMDB,/app/oracle/base/oradata/SGPMDB)
LOG_FILE_NAME_CONVERT=(/app/oracle/base/oradata/SGPMDB/redo,/app/oracle/base/oradata/SGPMDB/redo)
compatible=10.2.0.4.0
shared_pool_size=500M
存放的路径是:/app/oracle/base/admin/SGPMDB/pfile/
4.nomount复制实例
export ORACLE_SID=SGPMDB #这里设置的ORACLE_SID和源库是一样的
sqlplus /nolog
connect sys/oracle@SGPMDBDU as sysdba
startup force nomount
5.省略,打开源库太简单了,如果这个不会,那说明你太弱了。
6. 创建dbrman数据库,即catalog恢复目录
用DBCA建好数据库后,在SQL下执行
create tablespace catalog_tbs
DATAFILE '/app/oracle/base/oradata/dbrman/catalog_tbs.dbf' SIZE 1000M REUSE
AUTOEXTEND ON NEXT 200M EXTENT MANAGEMENT LOCAL ;
CREATE USER rman IDENTIFIED BY rman DEFAULT TABLESPACE catalog_tbs;
GRANT connect,resource,recovery_catalog_owner TO rman;
使用RMAN连接的恢复目录
rman catalog=rman/rman
在RMAN 提示符下执行create catalog命令
create catalog tablespace catalog_tbs;
在恢复目录中注册数据库
export ORACLE_SID=SGPMDB
rman target=sys/sys_240_sgpmdb catalog=rman/rman@DBRMAN
使用恢复目录注册数据库
RMAN>register database;
6.在172.19.4.1服务器上,用RMAN分别连接三个库
RMAN> connect target sys/sys_240_sgpmdb@SGPMDB
connected to target database: SGPMDB (DBID=3784337228)
RMAN> connect auxiliary sys/oracle
connected to auxiliary database: SGPMDB (nomount)
RMAN> connect catalog rman/rman@DBRMAN
connected to recovery catalog database
备份全库的命令:
RMAN> backup full database
7.开始复制:
RMAN> DUPLICATE TARGET DATABASE TO SGPMDB nofilenamecheck;
一切OK !
注意:还有更简单的方法,可以不需要catalog数据库,直接把备份集保存在控制文件里面,scp控制文件到辅助实例的服务器,同样可以复制。
李世侠,网名caibird2005 , initdba , 战神
MySQL DBA经验6年;
Oracle DBA经验10年;
精通MySQL HA架构,复制,备份,恢复,SQL优化;
熟悉SHELL编程、Python编程、SQL&PL/SQL编程;
MySQL OCP课程讲师;
ORACLE官方认证OCM证书;
BLOG: http://www.cnblogs.com/caibird2005
http://www.initdba.cn
Wechat: caibird2005
TEL :+86-186-5881-5300 +86-180-7290-8651