码迷,mamicode.com
首页 > 数据库 > 详细

通过RMAN 异机克隆数据库

时间:2014-10-29 19:33:38      阅读:299      评论:0      收藏:0      [点我收藏+]

标签:oracle   克隆   rman   复制   duplicate   

使用RMAN进行复制时,RMAN会连接目标数据库和辅助实例,如果使用了catalog备份的还会连接恢复目录。RMAN连接了目标数据库才能够访问其控制文件中记录的备份的详细信息,连接辅助实例才能够在辅助实例上分配一个或多个通道进程,9i开始会自动创建通道; 要连接辅助实例就先要启动辅助实例,就需要一个pfile参数文件,由目标数据库creata pfile from spfile得来,由于没有控制文件,所以只能启动到nomount阶段,RMAN会生成到这个辅助实例的sysdba连接。连接了目标库和辅助实例后,就可以使用duplicate命令,复制数据库,复制过程一般分为以下阶段:1,rman确定备份的状态和位置2,rman在辅助实例上分配辅助通道,3,在辅助实例上还原数据文件,4,构建新的控制文件 5,rman还原归档日志,并进行恢复 6,rman重置辅助库的DBID(唯一标识一个数据库),并以open resetlogs打开数据库。


平台准备:
      OracleLinux  +  Oracle 11G
    目标库:
       ORACLE_HOME=/uoracle/app
       ORACLE_BASE=/orabase
       ORACLE_SID= orcl
       IP : 192.168.0.45
    辅助库:
       ORACLE_HOME=/uoracle/app
       ORACLE_BASE=/orabase
       ORACLE_SID=orcl
       IP : 192.168.0.46      

操作步骤(异机和同机复制,步骤基本一样):
       1:运行辅助实例的服务器需要先安装好相应的oracle客户端,且ORACLE_BASE 和ORACLE_HOME目录和目标库相同;
       2:构建辅助数据库目录结构;
       3:创建参数文件,复制过来,并进行相应修改;
       4:创建辅助实例口令文件,orapwd
       5:配置监听及tnsname文件
       6:目标库进行备份,并拷贝到辅助实例服务其上,或同NFS挂载过去;
       7:使用pfile启动辅助实例到nomount,并退出会话;
       8:duplicate命令复制数据库;
       9: 创建spfile

具体实现:
1:安装客户端
 2:构建辅助数据库目录结构(根据参数文件中涉及到的目录来构建辅助库的目录结构)

[oracle@orclA ~]$ echo $ORACLE_BASE
/orabase
[oracle@orclA ~]$ cd /orabase
[oracle@orclA orabase]$ mkdir ./oradata/orcl -p
[oracle@orclA orabase]$mkdir ./fast_recovery_area/orcl -p # 重新构建控制文件,存放控制文件
[oracle@orclA orabase]$ pwd
/orabase
[oracle@orclA orabase]$ mkdir ./admin/orcl -p
[oracle@orclA orabase]$ cd ./admin/orcl/
[oracle@orclA orcl]$ mkdir {a,b,c,d,u}dump
[oracle@orclA orcl]$ mkdir pfile

3:创建参数文件,复制过来,并进行相应修改
  3.1: 目标库上创建pfile,并拷贝到辅助库上 ?/dbs 目录下(必须是$ORACLE_HOME/dbs 目录下,否则识别不到)
           SQL> create pfile=‘/tmp/initorcl.ora‘ from spfile;
           SQL> scp  /tmp/initorcl.ora  192.168.0.46:/oracle/home/dbs 
  3.2: 对参数文件进行相应修改
         由于这里是进行异机复制,目录结构及实例名都一样,所以没有进行修改
  3.3: 使用pfile启动数据库到nomount 状态,进行测试,并创建spfile
                     
SQL> startup pfile=‘/uoracle/app/dbs/initorcl.ora‘>ORACLE instance started.
Total System Global Area 1.0055E+10 bytes
Fixed Size                  2237008 bytes
Variable Size            3154120112 bytes
Database Buffers         6878658560 bytes
Redo Buffers               19767296 bytes
Database mounted.
Database opened.
SQL> create spfile from pfile;
File created.


4:为辅助实例创建口令文件,密码与源库一致
[oracle@orclA bin]$ pwd
/uoracle/app/bin
[oracle@orclA bin]$ orapwd file=$ORACLE_HOME/dbs/orapworcl password=admin123;
[oracle@orclA bin]$ 
[oracle@orclA bin]$ ls /uoracle/app/dbs/orapworcl 
/uoracle/app/dbs/orapworcl



5:配置监听及tnsname文件

源库上:
[root@bzdb ~]# cat /uoracle/app/network/admin/listener.ora 
# listener.ora Network Configuration File: /uoracle/app/network/admin/listener.ora
# Generated by Oracle configuration tools.


orcl =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.45)(PORT = 1521))
    )
  )


ADR_BASE_LISTENER = /orabase


[root@bzdb ~]# cat /uoracle/app/network/admin/tnsnames.ora 
# tnsnames.ora Network Configuration File: /uoracle/app/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.


ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.0.45)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )


AUXORCL =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.46)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )      


辅助库上:
TARGETORCL =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.45)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )
ORCL =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.78)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )


6:目标库进行备份,并拷贝到辅助实例服务其上,或同NFS挂载过去;  
RMAN> RUN {
2>  allocate channel c1 type disk;
3> allocate channel c2 type disk;
4> backup database format ‘/backup/orcl_%U_%T‘ skip inaccessible filesperset 5 tag orcl_bak;
5> sql ‘alter system archive log current‘;
6> backup archivelog all delete input  format ‘/backup/arch_%U_%T‘  skip inaccessible filesperset 5;
7> backup current controlfile format ‘/backup/ctl_%U_%T‘  tag=‘ctl_BAK‘;
8> backup  spfile format ‘/backup/orcl_spfile_%U_%T‘ tag=‘spfile‘;
9> release channel c2;
10> release channel c1;
11> }

注: 因为这里使用的是nocatalog备份方式,备份信息会写入到控制文件中,所以,控制文件要单独备份

目标库上:
                     
[root@bzdb ~]# cat /etc/exports 
/backup  192.168.0.78(rw,async)
[root@bzdb ~]# /etc/init.d/nfs start
Starting NFS services: [  OK  ]
Starting NFS mountd: [  OK  ]
Stopping RPC idmapd: [  OK  ]
Starting RPC idmapd: [  OK  ]
Starting NFS daemon: [  OK  ]

辅助库上:
# 建立与目标库上相同的目录
mkdir   /backup
chown oracle.oinstall   /backup  -R
chmod 775   /backup
showmount -e 192.168.0.45
mount -t nfs 192.168.0.45:/backup   /bakup



7:使用pfile启动辅助实例到nomount,并退出会话;
SQL> startup nomount pfile=‘/uoracle/app/dbs/initorcl.ora‘
ORACLE instance started.
Total System Global Area 1.0055E+10 bytes
Fixed Size                  2237008 bytes
Variable Size            3154120112 bytes
Database Buffers         6878658560 bytes
Redo Buffers               19767296 bytes
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options



8:duplicate命令复制数据库;
目标库上:
[oracle@bzdb ~]$ rman target sys/admin123@orcl auxiliary sys/admin123@auxorcl;
Recovery Manager: Release 10.2.0.1.0 - Production on Sun Jul 18 20:41:19 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: ORCL (DBID=1248423599)
connected to auxiliary database: ORCL (not mounted)
RMAN> duplicate target database to ORCL nofilenamecheck
logfile
‘/orabase/oradata/orcl/redo01.log‘ size 100M,
‘/orabase/oradata/orcl/redo02.log‘ size 100M,
‘/orabase/oradata/orcl/redo03.log‘ size 100M;



9:创建spfile,并重新启动
create spfile from pfile;
shutdown immeidate;
startup

验证数据库是否复制成功


本文出自 “dbguy” 博客,请务必保留此出处http://dbguy.blog.51cto.com/8921728/1569359

通过RMAN 异机克隆数据库

标签:oracle   克隆   rman   复制   duplicate   

原文地址:http://dbguy.blog.51cto.com/8921728/1569359

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!