首页 > 代码库 > 使用rman异机复制数据库
使用rman异机复制数据库
源端数据库:192.168.1.210
sid:orcl
hostname:Nagiostest
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/11.2
目标数据库:192.168.1.211
sid:orcl
hostname:OEL6
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
这里是相同实例名的复制,如果实例名不同,需修改参数文件
1.在目标端数据库建立相同的目录结构
mkdir /u01/app/oracle/oradata/orcl -p
mkdir /u01/app/oracle/admin/orcl/{adump,bdump,cdump,dpdump,udump,pfile} -p
2.在源端数据库创建pfile参数文件,并拷贝到目标端数据库
SQL> conn sys/yuanlei@orcl as sysdba;
Connected.
SQL> create pfile from spfile;
File created.
[oracle@Nagiostest dbs]$ pwd
/u01/app/oracle/product/11.2/dbs
[oracle@Nagiostest dbs]$ ls
c-1382226447-20140812-00 c-1382226447-20140818-00 hc_DBUA0.dat hc_orcl.dat initorcl.ora lkORCL orapworcl spfilenylg.ora
c-1382226447-20140813-00 c-1382226447-20140818-01 hc_nylg.dat initnylg.ora lkNYLG orapwnylg snapcf_orcl.f spfileorcl.ora
scp /u01/app/oracle/product/11.2/dbs/initorcl.ora oracle@192.168.1.211:/u01/app/oracle/product/11.2.0/db_1/dbs
3.在目标端数据库确认收到参数文件,这里不用修改,因为我们复制的实例名和存储位置都一样,如果实例名不一样就全部修改新的实例名,存储位置不一样,就参考以下两个参数转化
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‘)
4.在目标端建立新数据库的口令文件
[oracle@OEL6 ~]$ orapwd file=$ORACLE_HOME/dbs/orapworcl password=yuanlei
[oracle@OEL6 dbs]$ ls
hc_DBUA0.dat hc_orcl.dat init.ora initorcl.ora lkORCL orapworcl
5.对远端数据库做rman全备份
[oracle@Nagiostest ~]$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Mon Aug 18 08:11:51 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1382226447)
RMAN>
run{
allocate channel c0 type disk;
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup database filesperset 15 format ‘/u01/rmanbak/L0_%d_%T_Full_s.%s_p.%p_%T.bak‘;
backup format ‘/u01/rmanbak/L0_%d_%T_SPFILE_s.%s_p.%p_%T.bak‘ spfile;
backup format ‘/u01/rmanbak/L0_%d_%T_CTL_s.%s_p.%p_%T.bak‘ current controlfile;
sql ‘alter system archive log current‘;
sql ‘alter system archive log current‘;
sql ‘alter system archive log current‘;
sql ‘alter system archive log current‘;
sql ‘alter system archive log current‘;
backup filesperset 10 format ‘/u01/rmanbak/L1_%d_%T_ARC_s.%s_p.%p_%T.bak‘
(archivelog all delete input);
release channel c0;
release channel c1;
release channel c2;
release channel c3;
}
备份完成后的文件如下:
[oracle@Nagiostest rmanbak]$ ll
total 1172536
-rw-r-----. 1 oracle oinstall 9797632 Aug 18 15:52 L0_ORCL_20140818_CTL_s.14_p.1_20140818.bak
-rw-r-----. 1 oracle oinstall 399548416 Aug 18 15:52 L0_ORCL_20140818_Full_s.10_p.1_20140818.bak
-rw-r-----. 1 oracle oinstall 75857920 Aug 18 15:51 L0_ORCL_20140818_Full_s.11_p.1_20140818.bak
-rw-r-----. 1 oracle oinstall 7151616 Aug 18 15:51 L0_ORCL_20140818_Full_s.12_p.1_20140818.bak
-rw-r-----. 1 oracle oinstall 639926272 Aug 18 15:52 L0_ORCL_20140818_Full_s.9_p.1_20140818.bak
-rw-r-----. 1 oracle oinstall 98304 Aug 18 15:52 L0_ORCL_20140818_SPFILE_s.13_p.1_20140818.bak
-rw-r-----. 1 oracle oinstall 47929344 Aug 18 15:52 L1_ORCL_20140818_ARC_s.16_p.1_20140818.bak
-rw-r-----. 1 oracle oinstall 12697088 Aug 18 15:52 L1_ORCL_20140818_ARC_s.17_p.1_20140818.bak
-rw-r-----. 1 oracle oinstall 5776896 Aug 18 15:52 L1_ORCL_20140818_ARC_s.18_p.1_20140818.bak
-rw-r-----. 1 oracle oinstall 1868288 Aug 18 15:52 L1_ORCL_20140818_ARC_s.19_p.1_20140818.bak
-rw-r-----. 1 oracle oinstall 3072 Aug 18 15:52 L1_ORCL_20140818_ARC_s.20_p.1_20140818.bak
6.配置源端和目标端的监听文件
源端:
[oracle@Nagiostest admin]$ pwd
/u01/app/oracle/product/11.2/network/admin
[oracle@Nagiostest admin]$ cat 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)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = Nagiostest)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
[oracle@Nagiostest admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.210)(PORT = 1521))
(CONNECT_DATA =http://www.mamicode.com/
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
SRCORCL = //这里是为了连接目标端数据库
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.211)(PORT = 1521))
)
(CONNECT_DATA =http://www.mamicode.com/
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
目标端:
[oracle@OEL6 adump]$ cd /u01/app/oracle/product/11.2.0/db_1/network/admin/
[oracle@OEL6 admin]$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/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.0/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = OEL6)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
[oracle@OEL6 admin]$
[oracle@OEL6 admin]$ cat tnsnames.ora
TARORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.210)(PORT = 1521))
)
(CONNECT_DATA =http://www.mamicode.com/
(SERVICE_NAME = orcl)
)
)
ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
(CONNECT_DATA =http://www.mamicode.com/
(SERVICE_NAME = orcl)
)
)
7.将源端数据库的rman全备份拷贝到目标数据库的相同位置(注意目录相同)
这里可以scp或者rsync或者nfs挂载 等、、、
[oracle@OEL6 rmanbak]$ rsync -av oracle@192.168.1.210:/u01/rmanbak/ /u01/rmanbak/
最后传递过来的备份文件如下:
[oracle@OEL6 rmanbak]$ ll
total 1172532
-rw-r-----. 1 oracle oinstall 9797632 Aug 18 15:52 L0_ORCL_20140818_CTL_s.14_p.1_20140818.bak
-rw-r--r--. 1 root root 399548416 Aug 19 00:07 L0_ORCL_20140818_Full_s.10_p.1_20140818.bak
-rw-r--r--. 1 root root 75857920 Aug 19 00:08 L0_ORCL_20140818_Full_s.11_p.1_20140818.bak
-rw-r--r--. 1 root root 7151616 Aug 19 00:08 L0_ORCL_20140818_Full_s.12_p.1_20140818.bak
-rw-r--r--. 1 root root 639926272 Aug 19 00:08 L0_ORCL_20140818_Full_s.9_p.1_20140818.bak
-rw-r--r--. 1 root root 98304 Aug 19 00:08 L0_ORCL_20140818_SPFILE_s.13_p.1_20140818.bak
-rw-r--r--. 1 root root 47929344 Aug 19 00:08 L1_ORCL_20140818_ARC_s.16_p.1_20140818.bak
-rw-r--r--. 1 root root 12697088 Aug 19 00:08 L1_ORCL_20140818_ARC_s.17_p.1_20140818.bak
-rw-r--r--. 1 root root 5776896 Aug 19 00:08 L1_ORCL_20140818_ARC_s.18_p.1_20140818.bak
-rw-r--r--. 1 root root 1868288 Aug 19 00:08 L1_ORCL_20140818_ARC_s.19_p.1_20140818.bak
-rw-r--r--. 1 root root 3072 Aug 19 00:08 L1_ORCL_20140818_ARC_s.20_p.1_20140818.bak
8.目标端数据库使用pfile启动到nomount状态
[oracle@OEL6 rmanbak]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Tue Aug 18 15:27:06 2014
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount pfile=?/dbs/initorcl.ora;
ORACLE instance started.
Total System Global Area 413372416 bytes
Fixed Size 2213896 bytes
Variable Size 331352056 bytes
Database Buffers 75497472 bytes
Redo Buffers 4308992 bytes
SQL>
9.在源端数据库,使用rman连接源端和目标端数据库,开始复制过程
[oracle@Nagiostest admin]$ rman target sys/yuanlei@orcl auxiliary sys/yuanlei@tarorcl
Recovery Manager: Release 11.2.0.1.0 - Production on Mon Aug 18 16:21:54 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1382226447)
connected to auxiliary database: ORCL (not mounted)
RMAN> duplicate target database to ORCL nofilenamecheck
logfile
‘/u01/app/oracle/oradata/orcl/redo01.dbf‘ size 50m,
‘/u01/app/oracle/oradata/orcl/redo02.dbf‘ size 50m,
‘/u01/app/oracle/oradata/orcl/redo03.dbf‘ size 50m;
注意:
Nofilenamecheck 参数:
如果在复制时,数据位置不同时,我们会用参数db_file_name_convert 对文件位置进行转换。
但是在这个复制示例中我们用的是相同的位置。 所以需要加上nofilenamecheck参数。
该参数通知复制操作不必在执行还原操作前确认文件名是不同的。
如果没有指定nofilenamecheck参数,rman会给出如下错误:
logfile 参数:
在完成复制进程并执行最有一条open resetlogs命令时,RMAN 必须为辅助数据库构建全新的日志文件。
如上面命令所示,我们可以在duplicate 命令中指定logfile参数,并指定使用的日志文件的大小,数目和位置。
还可以在pfile里指定log_file_name_convert 参数来进行转换。
Starting Duplicate Db at 2014/08/18 16:25:23
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=20 device type=DISK
.
.
.
.
.
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 2014/08/18 16:27:53
RMAN> quit
此时,目标端的复制的新数据已经open
本文出自 “paopao5541” 博客,请务必保留此出处http://paopao5541.blog.51cto.com/6132973/1541686