RMAN duplicate from active database
在Oracle 11G有二种方法实现duplicate:
1、Active database duplication
2、Backup-based duplication
Active database duplication 通过网络,直接复制目标库到辅助库,然后创建辅助库。这种方法不需要先用RMAN 备份数据库,然后将备份文件发送到auxiliary端。这种方式解决了备份空间占用、网络传送占用带宽和时间等问题,对于大库的迁移很有用。
目标:192.168.0.10
辅助:192.168.0.11
前提:目标库开启归档
一、创建辅助数据库目录结构
$ mkdir -p /u01/app/oracle/oradata/orcl
$ mkdir -p /u01/app/oracle/admin/orcl/{a,dp}dump
$ mkdir -p /u01/app/oracle/fast_recovery_area/ORCL
二、在辅助数据库创建pfile
2.1 生成源库的pfile 文件:
SQL> create pfile from spfile;
2.2用scp 命令将pfile 文件传到辅助库
$ scp /u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora oracle@192.168.0.11:/u01/app/oracle/product/11.2.0/db_1/dbs
在这里没有做修改,因为异机复制实例名相同,存储位置也相同
三、在辅助实例创建口令文件
对于Active Database Duplication要确保目标库和辅助库的SYSDBA 密码一样。我们采用复制口令文件的方式:
$ scp /u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl oracle@192.168.0.11:/u01/app/oracle/product/11.2.0/db_1/dbs/
在辅助库使用orapwd file=$ORACLE_HOME/dbs/orapworcl password=oracle创建口令文件,可能报如下错误:
ORA-17629: Cannot connect to the remote database server
ORA-17627: ORA-01017: invalid username/password; logon denied
ORA-17629: Cannot connect to the remote database server
四、添加,配置监听
4.1在辅助库的Listener.ora 文件中,添加如下内容
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.11)(PORT = 1521))
)
4.2修改源库的tnsnames.ora 文件,添加如下内容:
DUPLICATE =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.11)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
$ lsnrctl stop
$ lsnrctl start
$ tnsping DUPLICATE
五、启动辅助库到nomount状态
$ export ORACLE_SID=orcl
$ sqlplus / as sysdba
SQL> startup nomount pfile=?/dbs/initorcl.ora
SQL> create spfile from pfile;
六、RMAN 连接到目标实例和辅助实例,运行duplicate 命令复制数据库(源)
$ export ORACLE_SID=orcl
$ rman target / auxiliary sys/oracle@DUPLICATE
RMAN> duplicate target database to orcl from active database nofilenamecheck;
注意:如果target 和 Auxiliary库的目录结构相同,记得加上nofilenamecheck参数,不然会报错误,如果目录不同,在pfile里加2个参数进行转换:db_file_name_convert、log_file_name_convert。
七、修改辅助库的pfile,在创建spfile
SQL> conn / as sysdba;
SQL> create spfile from pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora';