先前整理了一篇rman备份异机恢复的文档,那篇文档比较偏向复杂型,需要对oracle的整个体系结构有一定的了解才能领悟,类似于oracle的手工建库 ;文章地址:http://ylw6006.blog.51cto.com/470441/659104
其实oracle 10g的rman也提供了类似于DBCA一样的简便工具来实现rman备份的异机恢复,也就是duplicate,下面来介绍下操作步骤:
环境介绍:
源数据库:
IP:192.168.227.20/24
SID: orcl
操作系统版本:rhel5.4 32位
oracle版本:10.2.0.1
辅助数据库:
IP:192.168.227.30/24
SID: orcl
操作系统版本:rhel5.4 32位
oracle版本:10.2.0.1(只安装oracle软件,不建库)
1:准备auxiliary数据库相关目录和文件:
- [oracle@auxiliary ~]$ mkdir -p $ORACLE_BASE/admin/orcl/{adump,bdump,cdump,dpdump,pfile,udump}
- [oracle@auxiliary ~]$ mkdir -p $ORACLE_BASE/flash_recovery_area/
- [oracle@auxiliary ~]$ mkdir -p $ORACLE_BASE/oradata/orcl
- [oracle@auxiliary ~]$ cd $ORACLE_HOME/dbs
- [oracle@auxiliary dbs]$ orapwd file=orapworcl password=123456 entries=5
- [oracle@auxiliary dbs]$ strings orapworcl
- ]\[Z
- ORACLE Remote Password file
- INTERNAL
- 203EBE72907E750E
- 466C75A1248EDE33
2:从源服务器上创建并复制参数文件到辅助数据库:
- SQL> create pfile='/home/oracle/initorcl.ora' from spfile;
- File created.
- SQL> !scp /home/oracle/initorcl.ora [email protected]:/u01/app/oracle/product/10.2.0/db_1/dbs
- [email protected]'s password:
- initorcl.ora 100% 1041 1.0KB/s 00:00
备注:
如果存储位置不同的话,还需要添加以下参数,对数据文件位置进行转换。
db_file_name_convert = ('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/yang')
3:在源服务器端利用备份oracle数据库,将备份好的数据复制到辅助数据库上,位置需要相同,oracle 11g据说可以免掉这步,这在迁移海量数据的时候确实很有优势,越来越智能了,回头也会在11g上测试下
- [oracle@primary ~]$ mkdir -p /home/oracle/backup
- [oracle@primary ~]$ rman target /
- Recovery Manager: Release 10.2.0.1.0 - Production on Sat Oct 8 14:28:23 2011
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- connected to target database: ORCL (DBID=1287906064)
- RMAN> backup incremental level 0
- 2> format '/home/oracle/backup/inr0_%U'
- 3> tag 'inr0_bak20111008' database
- 4> plus archivelog delete all input;
- RMAN> backup current controlfile format '/home/oracle/backup/controlfile20111008' tag 'ctl20111008';
- 备注:据实验结果显示,控制文件可以不备份也能成功!rman自动备份控制文件选项未开启
- [oracle@auxiliary ~]$ mkdir -p /home/oracle/backup
- [oracle@auxiliary backup]$ scp -rvp [email protected]:/home/oracle/backup/* ./
4:在辅助数据库上配置tnsnames串
- [oracle@auxiliary ~]$ cd $ORACLE_HOME/network/admin
- [oracle@auxiliary admin]$ cat tnsnames.ora
- primary =
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.227.20)(PORT = 1521))
- )
- (CONNECT_DATA =
- (SERVICE_NAME = orcl.herostart.com)
- )
- orcl =
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.227.30)(PORT = 1521))
- )
- (CONNECT_DATA =
- (SERVICE_NAME = orcl.herostart.com)
- )
5:启动辅助数据库到nomount状态
- [oracle@auxiliary ~]$ lsnrctl start
- [oracle@auxiliary ~]$ sqlplus /nolog
- SQL*Plus: Release 10.2.0.1.0 - Production on Sat Oct 8 14:54:58 2011
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected to an idle instance.
- SQL> create spfile from pfile;
- File created.
- SQL> startup nomount
- ORACLE instance started.
- Total System Global Area 167772160 bytes
- Fixed Size 1218316 bytes
- Variable Size 62916852 bytes
- Database Buffers 100663296 bytes
- Redo Buffers 2973696 bytes
6:在辅助数据库进行duplicate操作
- [oracle@auxiliary ~]$ rman target sys/123456@primary auxiliary /
- Recovery Manager: Release 10.2.0.1.0 - Production on Sat Oct 8 15:07:21 2011
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- connected to target database: ORCL (DBID=1287906064)
- connected to auxiliary database: ORCL (not mounted)
- RMAN> duplicate target database to orcl nofilenamecheck;
- ……………………………………………………其他输出省略……………………………………………………
- contents of Memory Script:
- {
- Alter clone database open resetlogs;
- }
- executing Memory Script
- database opened
- Finished Duplicate Db at 2011-10-08:15:10:29
7:验证
- [oracle@auxiliary ~]$ sqlplus /nolog
- SQL*Plus: Release 10.2.0.1.0 - Production on Sat Oct 8 15:11:55 2011
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected.
- SQL> select name,dbid,open_mode from v$database;
- NAME DBID OPEN_MODE
- --------- ---------- ----------
- ORCL 1291784142 READ WRITE
8:增量备份的异机恢复
- [oracle@primary ~]$ sqlplus /nolog
- SQL*Plus: Release 10.2.0.1.0 - Production on Sat Oct 8 15:22:17 2011
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected.
- SQL> create table hr.inr1_duplicate as select * from dba_source;
- Table created.
- SQL> commit;
- Commit complete.
- RMAN> backup incremental level 1
- 2> format '/home/oracle/backup/inr1_%U'
- 3> tag 'inr1_20111008'
- 4> database plus archivelog delete all input;
- [oracle@auxiliary ~]$ cd /home/oracle/backup/
- [oracle@auxiliary backup]$ scp -rvp [email protected]:/home/oracle/backup/inr1* ./
- [oracle@auxiliary backup]$ ll -h inr1*
- -rw-r----- 1 oracle oinstall 83K Oct 8 15:29 inr1_0emoji6b_1_1
- -rw-r----- 1 oracle oinstall 60M Oct 8 15:30 inr1_0fmoji6d_1_1
- -rw-r----- 1 oracle oinstall 6.9M Oct 8 15:30 inr1_0gmoji7s_1_1
- -rw-r----- 1 oracle oinstall 7.5K Oct 8 15:30 inr1_0hmoji7u_1_1
- [oracle@auxiliary ~]$ sqlplus /nolog
- SQL*Plus: Release 10.2.0.1.0 - Production on Sat Oct 8 15:34:03 2011
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected.
- SQL> select count(*) from hr.inr1_duplicate;
- select count(*) from hr.inr1_duplicate
- *
- ERROR at line 1:
- ORA-00942: table or view does not exist
- SQL> shutdown immediate
- SQL> startup nomount
- [oracle@auxiliary ~]$ rman target sys/123456@primary auxiliary /
- Recovery Manager: Release 10.2.0.1.0 - Production on Sat Oct 8 15:35:43 2011
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- connected to target database: ORCL (DBID=1287906064)
- connected to auxiliary database: ORCL (not mounted)
- RMAN> duplicate target database to orcl nofilenamecheck;
- [oracle@auxiliary ~]$ sqlplus /nolog
- SQL*Plus: Release 10.2.0.1.0 - Production on Sat Oct 8 15:38:26 2011
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected.
- SQL> select count(*) from hr.inr1_duplicate;
- COUNT(*)
- ----------
- 292428
本文出自 “斩月” 博客,谢绝转载!