rman的duplicate复制数据库

duplicate
最近公司准备迁移数据库,迁移的办法有很多,由于考虑到生产系统的安全性和停机时间等其他因素,选择的方案有很多,这里我们谈一下rman的duplicate:
11g的rman duplicate 相比10g先进了很多,10G需要在rman备份的基础上进行复制,使用 RMAN duplicate 创建一个数据完全相同但DBID不同的数据库。而11g的RMAN duplicate ,可以通过Active database duplicate和Backup-based duplicate两种方法实现。这里的测试使用的是Active database duplicate,因为Active database duplicate 功能强大,不需要先把目标数据库进行rman备份,只要目标数据库处于归档模式下即可直接通过网络对数据库进行copy,且copy完成后自动open数据库。这对于大数据特别是T级别的数据库来说优点非常明显,复制前不需要进行备份,减少了备份和传送备份的时间,同时节省备份空间。


步骤和说明:
实验环境
source端:
centos6.5
ip:192.168.6.151
oracle_sid=pu

oracle版本11g

hostname  oracle



target端:
centos6.5
ip:192.168.6.152
oracle_sid=pu

oracle版本11g

hostname  target


需要注意的是我这里的db_name是一致的,数据库目录也是一致


1、安装source端的数据库软件以及建库(详细步骤这里不在介绍可以参考:我的博客http://blog.csdn.net/freedompuge/article/details/45028961)

查看source数据库的数据文件

[oracle@target admin]$ sqlplus / as sysdba


SQL*Plus: Release 11.2.0.3.0 Production on Mon May 9 16:01:30 2016


Copyright (c) 1982, 2011, Oracle.  All rights reserved.




Connected to:
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


SQL> select name from v$datafile;


NAME
--------------------------------------------------------------------------------
/u01/oracle/oradata/pu/system01.dbf
/u01/oracle/oradata/pu/sysaux01.dbf
/u01/oracle/oradata/pu/undotbs01.dbf
/u01/oracle/oradata/pu/users01.dbf
/u01/salary.dbf
/u01/11g/ggs.dbf
/u01/ogg01.dbf


7 rows selected.


2、安装target端数据库软件,但不建库(详细步骤这里不在介绍可以参考:我的博客http://blog.csdn.net/freedompuge/article/details/45028961)


3、创建密码文件
可以手工创建orapwd file='$ORACLE_HOME/dbs/orapwpu'  password=oracle entries=5 force=y;
最好是直接source端的密码文件scp $ORACLE_HOME/dbs/orapwpu  [email protected]:/u01/11g/dbs/


4、创建参数文件init.ora

这里也可以直接拷贝

source端

SQL> create pfile='/u01/init.ora' from spfile;
scp /u01/init.ora  [email protected]:/u01
[oracle@oracle dbs]$ cat /u01/init.ora
pu.__db_cache_size=33554432
pu.__java_pool_size=12582912
pu.__large_pool_size=4194304
pu.__oracle_base='/u01/oracle'#ORACLE_BASE set from environment
pu.__pga_aggregate_target=176160768
pu.__sga_target=239075328
pu.__shared_io_pool_size=0
pu.__shared_pool_size=171966464
pu.__streams_pool_size=4194304
*.audit_file_dest='/u01/oracle/admin/pu/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/oracle/oradata/pu/control01.ctl','/u01/oracle/fast_recovery_area/pu/control02.ctl'#Restore Controlfile
*.db_block_size=8192
*.db_domain=''
*.db_name='pu'
*.db_recovery_file_dest='/u01/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=8589934592
*.diagnostic_dest='/u01/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=puXDB)'
*.memory_target=414187520
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'




5、创建参数文件中的目录路径,并授予权限
最简单的防范  chown oralce.oinstall /u01 -R
[oracle@target dbs]$ cat init.ora | grep /
pu.__oracle_base='/u01/oracle'#ORACLE_BASE set from environment
*.audit_file_dest='/u01/oracle/admin/pu/adump'
*.control_files='/u01/oracle/oradata/pu/control01.ctl','/u01/oracle/fast_recovery_area/pu/control02.ctl'#Restore Controlfile
*.db_recovery_file_dest='/u01/oracle/fast_recovery_area'
*.diagnostic_dest='/u01/oracle'
创建以上目录
[oracle@target dbs]$ mkdir -p /u01/oracle/admin/pu/adump^C
[oracle@target dbs]$ mkdir -p /u01/oracle/admin/pu/adump
[oracle@target dbs]$ mkdir -p /u01/oracle/oradata/pu/
[oracle@target dbs]$ mkdir -p /u01/oracle/fast_recovery_area/pu/
[oracle@target dbs]$ mkdir -p /u01/oracle/fast_recovery_area



6、启动到nomount,并网络互通
[oracle@target ~]$ sqlplus / as sysdba


SQL*Plus: Release 11.2.0.3.0 Production on Mon May 9 13:57:59 2016


Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to an idle instance.


SQL> startup nomount pfile='/u01/11g/dbs/init.ora';
ORACLE instance started.


Total System Global Area  413372416 bytes
Fixed Size                  2228904 bytes
Variable Size             369102168 bytes
Database Buffers           37748736 bytes
Redo Buffers                4292608 bytes


关闭iptables和selinux
开启监听,tnsping能互相ping通
静态监听listener.ora
source端:


SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (ORACLE_HOME = /u01/11g)
      (SID_NAME = pu)
    )
  )


LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = oracle)(PORT = 1521))
    )
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )


ADR_BASE_LISTENER = /u01/oracle


target端:


SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (ORACLE_HOME = /u01/11g)
      (SID_NAME = pu)
    )
  )


LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = target)(PORT = 1521))
    )
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )


ADR_BASE_LISTENER = /u01/oracle


tnsname.ora(两端一致)
sss =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.6.151)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = pu)
#      (UR=A)
    )
  )


target =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.6.152)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = pu)
#      (UR=A)
    )
  )
测试tnsping sss 和tnsping target


7、开始执行duplicate
rman target sys/oracle@sss auxiliary sys/oracle@target


duplicate target database to pu(这个指定的是db_name,我两端的db_name相同,这点需要注意) from active database nofilenamecheck(由于我两边的数据库目录和sid都相同,所以需要加这个参数不检查文件,否则会报错);              
由于我使用的软件屏幕显示有问题,所以只截取了最后完成的一段输出日志
contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script


database opened
Finished Duplicate Db at 09-MAY-16


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


8、验证
查询target端的数据文件
[oracle@target admin]$ sqlplus / as sysdba


SQL*Plus: Release 11.2.0.3.0 Production on Mon May 9 15:32:08 2016


Copyright (c) 1982, 2011, Oracle.  All rights reserved.




Connected to:
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


SQL> select open_mode from v$database;


OPEN_MODE
--------------------
READ WRITE


SQL>
直接是打开状态
SQL> select name from v$datafile;


NAME
-------------------------------------------------------------------------------
/u01/oracle/oradata/pu/system01.dbf
/u01/oracle/oradata/pu/sysaux01.dbf
/u01/oracle/oradata/pu/undotbs01.dbf
/u01/oracle/oradata/pu/users01.dbf
/u01/salary.dbf
/u01/11g/ggs.dbf
/u01/ogg01.dbf


7 rows selected.


SQL>
生成了7个数据文件

你可能感兴趣的:(oracle)