使用rman复制数据库


原数据库sid orcl  复制新的数据库sid为 nylg


1.创建复制备份数据库的参数文件

在原数据库创建pfile

create pfile from spfile;

然后复制pfile参数文件

[oracle@Nagiostest dbs]$ pwd

/u01/app/oracle/product/11.2/dbs

[oracle@Nagiostest dbs]$ cp initorcl.ora initnylg.ora 

修改orcl数据库名改为nylg

vi initnylg.ora 修改如下:

:%s/orcl/nylg/g


在这里注意,修改参数文件后,在最后行添加两行转换参数,指定新数据文件存放路径

db_file_name_convert = ('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/nylg')

log_file_name_convert = ('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/nylg')




2.创建相对应的目录,启动复制数据库的辅助实例

mkdir -p $ORACLE_BASE/admin/nylg/{a,b,c,u}dump

mkdir -p /u01/app/oracle/oradata/nylg

orapwd file=$ORACLE_HOME/dbs/orapwnylg password=yuanlei force=y

[oracle@Nagiostest ~]$ export ORACLE_SID=nylg


使用pfile启动辅助实例到nomount

startup nomount pfile=?/dbs/initnylg.ora   


如下:

[oracle@Nagiostest ~]$ export ORACLE_SID=nylg

[oracle@Nagiostest ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Wed Aug 13 10:27:25 2014

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

SQL> conn / as sysdba

Connected to an idle instance.

SQL> startup nomount pfile=?/dbs/initnylg.ora

ORACLE instance started.


Total System Global Area  413372416 bytes

Fixed Size    2213896 bytes

Variable Size  314574840 bytes

Database Buffers   92274688 bytes

Redo Buffers    4308992 bytes





3.在新的会话中(ORACLE_SID=orcl)对原数据库做rman全备

export ORACLE_SID=orcl

rman target /


run {

sql 'alter system archive log current';

backup database format='/u01/rmanbak/%d_%s.dbf'

plus archivelog format='/u01/rmanbak/%d_%s.arc';

sql 'alter system archive log current';

}




4.配置复制库监听(就是本机的监听文件),服务名采用静态注册,启动监听,这步很重要

不要有错误


[oracle@Nagiostest admin]$ vim listener.ora 

# listener.ora Network Configuration File: /u01/app/oracle/product/11.2/network/admin/listener.ora

# Generated by Oracle configuration tools.


SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (SID_NAME = PLSExtProc)

      (ORACLE_HOME = /u01/app/oracle/product/11.2)

      (PROGRAM = extproc)

    )

    (SID_DESC =

      (SID_NAME = nylg)

      (ORACLE_HOME = /u01/app/oracle/product/11.2)

      (GLOBAL_DBNAME = NYLG)

    )

  )



ADR_BASE_LISTENER = /u01/app/oracle


[oracle@Nagiostest admin]$ vim tnsnames.ora 

# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.


NYLG =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.210)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = nylg)

    )

  )




lsnrctl start


5.用rman连接到主库实例和辅助实例,运行复制命令


[oracle@Nagiostest dbs]$ rman target /


Recovery Manager: Release 11.2.0.1.0 - Production on Wed Aug 13 11:01:56 2014


Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


connected to target database: ORCL (DBID=1382226447)


RMAN> connect auxiliary sys/yuanlei@nylg


connected to auxiliary database: NYLG (not mounted)


这里如果遇到

RMAN-04006: error from auxiliary database: ORA-01031: insufficient privileges

请检查你的监听配置和口令文件是否正确,一般就这两个原因(我做的时候是把监听sid大写小弄错)


然后继续


RMAN> duplicate target database to nylg;


其它配置没问题话的,这里等一会就完成了


Starting Duplicate Db at 2014/08/13 11:02:38

using target database control file instead of recovery catalog

.

.

.复制过程

.

.

contents of Memory Script:

{

   Alter clone database open resetlogs;

}

executing Memory Script

database opened

Finished Duplicate Db at 2014/08/13 11:07:26



此时新的数据库已经处于open状态了!





[oracle@Nagiostest ~]$ echo $ORACLE_SID

nylg

[oracle@Nagiostest ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Wed Aug 13 11:08:49 2014

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> select status from v$instance;


STATUS

------------

OPEN




OK!