Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1061312
  • 博文数量: 239
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 3618
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-12 13:17
文章分类

全部博文(239)

文章存档

2021年(1)

2016年(1)

2015年(30)

2014年(91)

2013年(116)

分类: LINUX

2014-07-13 01:38:52

实验环境
操作系统:RHEL6.4
库名:orcl
ORACLE_BASE=/u01/oracle
ORACLE_HOME=$ORACLE_BASE/product

假设要恢复的库名:test01
步骤如下:
(1)构建辅助数据库目录结构
(2)修改init.ora 初始话文件
(3)创建辅助实例口令文件
(4)RMAN 备份源库
(5)配置监听
(6)启动辅助库至nomount 状态
(7)RMAN duplicate复制实例
(8)创建spfile

1.创建oracle data目录
[oracle@oracle11g ~]$ cd /u01/oracle/oradata/ 
[oracle@oracle11g oradata]$ mkdir test01
[oracle@oracle11g oradata]$ pwd
/u01/oracle/oradata
[oracle@oracle11g oradata]$ ls
hbhe  orcl  test01

2.创建其他目录
[oracle@oracle11g oradata]$ pwd
/u01/oracle/oradata
[oracle@oracle11g oradata]$ cd ../admin/
[oracle@oracle11g admin]$ pwd
/u01/oracle/admin
[oracle@oracle11g admin]$ mkdir test01
[oracle@oracle11g admin]$ ls
hbhe  orcl  test
[oracle@oracle11g admin]$ cd orcl/
[oracle@oracle11g orcl]$ ls
adump  dpdump  pfile
[oracle@oracle11g orcl]$ cd ../test01/
[oracle@oracle11g test]$ mkdir adump dpdump pfile
[oracle@oracle11g test]$ ls      
adump  dpdump  pfile

3.修改init.ora初始化文件
生成源库的pfile 文件,默认生成位置在$ORACLE_HOME/dbs目录下,本环境在/u01/oracle/product/dbs下
[root@oracle11g ~]# su - oracle
[oracle@oracle11g ~]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.3.0 Production on Sat Jul 12 20:58:32 2014
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size    2228784 bytes
Variable Size 1140854224 bytes
Database Buffers  452984832 bytes
Redo Buffers    7344128 bytes
Database mounted.
Database opened.
通过spfile文件创建pfile文件,修改pfile文件,然后再通过pfile文件生成spfile文件。
SQL> create pfile from spfile;
File created.
[oracle@oracle11g dbs]$ cd /u01/oracle/product/dbs/
[oracle@oracle11g dbs]$ ls
hc_hbhe.dat  init.ora      lkHBHE  orapwhbhe  snapcf_orcl.f   spfileorcl.ora
hc_orcl.dat  initorcl.ora  lkORCL  orapworcl  spfilehbhe.ora
[oracle@oracle11g dbs]$ cp initorcl.ora inittest01.ora
[oracle@oracle11g dbs]$ ls

hc_hbhe.dat  initorcl.ora  lkORCL     snapcf_orcl.f
hc_orcl.dat  inittest01.ora  orapwhbhe  spfilehbhe.ora
init.ora     lkHBHE        orapworcl  spfileorcl.ora
修改inittest.ora里面的内容,将orcl改成test,修改后的文件如下:
[oracle@oracle11g dbs]$ cat inittest01.ora 
[oracle@oracle11g dbs]$ cat inittest01.ora 
test01.__db_cache_size=452984832
test01.__java_pool_size=16777216
test01.__large_pool_size=16777216
test01.__oracle_base='/u01/oracle'#ORACLE_BASE set from environment
test01.__pga_aggregate_target=654311424
test01.__sga_target=956301312
test01.__shared_io_pool_size=0
test01.__shared_pool_size=436207616
test01.__streams_pool_size=16777216
*.audit_file_dest='/u01/oracle/admin/test01/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_file_record_keep_time=14
*.control_files='/u01/oracle/oradata/test01/control01.ctl','/u01/oracle/fast_recovery_area/test01/control02.ctl'
*.db_block_size=8192
*.db_cache_size=16777216
*.db_domain=''
*.db_name='test01'
*.db_recovery_file_dest='/u01/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4322230272
*.diagnostic_dest='/u01/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=test01XDB)'
test01.log_archive_dest_1='location=/u01/oracle/test01_arch'
*.memory_target=1603272704
*.O7_DICTIONARY_ACCESSIBILITY=TRUE
*.open_cursors=300
*.processes=500
*.remote_login_passwordfile='EXCLUSIVE'
*.sessions=555
*.undo_tablespace='UNDOTBS1'
db_file_name_convert = ('/u01/oracle/oradata/orcl','/u01/oracle/oradata/test01')
log_file_name_convert = ('/u01/oracle/oradata/orcl','/u01/oracle/oradata/test01')
后面两个是后来新加的,用来转换redo log位置。

4.创建test01实例的口令文件。
[oracle@oracle11g dbs]$ cd /u01/oracle/product/bin/
[oracle@oracle11g bin]$ orapwd file=$ORACLE_HOME/dbs/orapwtest01 password=wwwwww
[oracle@oracle11g bin]$ cd $ORACLE_HOME/dbs        
[oracle@oracle11g dbs]$ pwd
/u01/oracle/product/dbs
[oracle@oracle11g dbs]$ ls
hc_hbhe.dat  initorcl.ora  lkORCL     orapwtest01       spfileorcl.ora
hc_orcl.dat  inittest01.ora  orapwhbhe  snapcf_orcl.f
init.ora     lkHBHE        orapworcl  spfilehbhe.ora
windows下oracle默认的位置是$ORACLE_HOME/database目录,文件名格式是pwdSID.ora。 
linux下oracle默认的位置是$ORACLE_HOME/dbs目录,文件名格式是orapwSID。 
创建完后,数据库需要重启动,新的口令文件才能生效。 

5.备份数据源
[oracle@oracle11g dbs]$ mkdir -p /u02/backup/
[oracle@oracle11g backup]$ rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on Sun Jul 13 00:11:43 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database: ORCL (DBID=1373722558)
RMAN> RUN { 
allocate channel c1 type disk;
allocate channel c2 type disk;
BACKUP FORMAT '/u02/backup/orcl_%U_%T' skip inaccessible filesperset 5  DATABASE TAG orcl_hot_db_bk; 
sql 'alter system archive log current';
BACKUP FORMAT '/u02/backup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL DELETE INPUT; 
backup current controlfile tag='bak_ctlfile' format='/u02/backup/ctl_file_%U_%T';
backup spfile tag='spfile' format='/u02/backup/ORCL_spfile_%U_%T';
release channel c2;
release channel c1;
}

using target database control file instead of recovery catalog
allocated channel: c1
channel c1: SID=206 device type=DISK
allocated channel: c2
channel c2: SID=399 device type=DISK
Starting backup at 13-JUL-14
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00006 name=/u01/oradata/icms.dbf
input datafile file number=00005 name=/u01/oracle/oradata/orcl/example01.dbf
input datafile file number=00007 name=/u01/oracle/oradata/orcl/rmancatalog.dbf
input datafile file number=00003 name=/u01/oracle/oradata/orcl/undotbs01.dbf
channel c1: starting piece 1 at 13-JUL-14
channel c2: starting full datafile backup set
channel c2: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/oracle/oradata/orcl/system01.dbf
input datafile file number=00002 name=/u01/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00004 name=/u01/oracle/oradata/orcl/users01.dbf
channel c2: starting piece 1 at 13-JUL-14
channel c1: finished piece 1 at 13-JUL-14
piece handle=/u02/backup/orcl_0qpd8dvf_1_1_20140713 tag=ORCL_HOT_DB_BK comment=NONE
channel c1: backup set complete, elapsed time: 00:00:55
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including current control file in backup set
channel c1: starting piece 1 at 13-JUL-14
channel c1: finished piece 1 at 13-JUL-14
piece handle=/u02/backup/orcl_0spd8e17_1_1_20140713 tag=ORCL_HOT_DB_BK comment=NONE
channel c1: backup set complete, elapsed time: 00:00:04
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel c1: starting piece 1 at 13-JUL-14
channel c1: finished piece 1 at 13-JUL-14
piece handle=/u02/backup/orcl_0tpd8e1i_1_1_20140713 tag=ORCL_HOT_DB_BK comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
channel c2: finished piece 1 at 13-JUL-14
piece handle=/u02/backup/orcl_0rpd8dvg_1_1_20140713 tag=ORCL_HOT_DB_BK comment=NONE
channel c2: backup set complete, elapsed time: 00:02:42
Finished backup at 13-JUL-14
sql statement: alter system archive log current
Starting backup at 13-JUL-14
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=54 RECID=23 STAMP=852768917
channel c1: starting piece 1 at 13-JUL-14
channel c2: starting archived log backup set
channel c2: specifying archived log(s) in backup set
input archived log thread=1 sequence=55 RECID=24 STAMP=852768917
channel c2: starting piece 1 at 13-JUL-14
channel c1: finished piece 1 at 13-JUL-14
piece handle=/u02/backup/arch_0upd8e4l_1_1_20140713 tag=TAG20140713T001517 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:02
channel c1: deleting archived log(s)
archived log file name=/u01/oracle/orcl_arch/1_54_845941826.dbf RECID=23 STAMP=852768917
channel c2: finished piece 1 at 13-JUL-14
piece handle=/u02/backup/arch_0vpd8e4l_1_1_20140713 tag=TAG20140713T001517 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:02
channel c2: deleting archived log(s)
archived log file name=/u01/oracle/orcl_arch/1_55_845941826.dbf RECID=24 STAMP=852768917
Finished backup at 13-JUL-14
Starting backup at 13-JUL-14
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including current control file in backup set
channel c1: starting piece 1 at 13-JUL-14
channel c1: finished piece 1 at 13-JUL-14
piece handle=/u02/backup/ctl_file_10pd8e4n_1_1_20140713 tag=BAK_CTLFILE comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 13-JUL-14
Starting backup at 13-JUL-14
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel c1: starting piece 1 at 13-JUL-14
channel c1: finished piece 1 at 13-JUL-14
piece handle=/u02/backup/ORCL_spfile_11pd8e4q_1_1_20140713 tag=SPFILE comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 13-JUL-14
released channel: c2
released channel: c1

6.修改监听文件
[oracle@oracle11g admin]$ cd /u01/oracle/product/network/admin
[oracle@oracle11g admin]$ vi listener.ora 
添加以下内容:
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u01/oracle/product)
      (PROGRAM = extproc)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = test01)
      (ORACLE_HOME = /u01/oracle/product)
      (SID_NAME = test01)
    )
  )

修改tnsnames.ora文件,添加下列内容
test01 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = oracle11g)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = test01)
    )
  )
~   
7.启动要复制的数据库到nomount状态
[oracle@oracle11g admin]$ export ORACLE_SID=test01
[oracle@oracle11g admin]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.3.0 Production on Sun Jul 13 00:58:40 2014
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> startup nomount pfile=/u01/oracle/product/dbs/inittest01.ora
ORA-00845: MEMORY_TARGET not supported on this system
如果启动过程中报错,参考http://blog.chinaunix.net/uid-25196040-id-4095303.html

SQL> startup nomount pfile=/u01/oracle/product/dbs/inittest.ora
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size    2228784 bytes
Variable Size 1140854224 bytes
Database Buffers  452984832 bytes
Redo Buffers    7344128 bytes


[oracle@oracle11g product]$ export ORACLE_SID=orcl
[oracle@oracle11g product]$ rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on Sun Jul 13 00:35:42 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database: ORCL (DBID=1373722558)
RMAN> connect auxiliary sys/wwwwww@test01;
connected to auxiliary database: TEST (not mounted)
RMAN> duplicate target database to test01;
Starting Duplicate Db at 13-JUL-14
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=197 device type=DISK

contents of Memory Script:
{
   sql clone "create spfile from memory";
}
executing Memory Script


sql statement: create spfile from memory


contents of Memory Script:
{
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script


Oracle instance shut down


connected to auxiliary database (not started)
Oracle instance started


Total System Global Area    1603411968 bytes


Fixed Size                     2228784 bytes
Variable Size               1157631440 bytes
Database Buffers             436207616 bytes
Redo Buffers                   7344128 bytes


contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''ORCL'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name = 
 ''TEST01'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone primary controlfile;
   alter clone database mount;
}
executing Memory Script
sql statement: alter system set  db_name =  ''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set  db_unique_name =  ''TEST01'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area    1603411968 bytes
Fixed Size                     2228784 bytes
Variable Size               1157631440 bytes
Database Buffers             436207616 bytes
Redo Buffers                   7344128 bytes
Starting restore at 13-JUL-14
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=197 device type=DISK
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/ctl_file_10pd8e4n_1_1_20140713
channel ORA_AUX_DISK_1: ORA-19504: failed to create file "/u01/oracle/fast_recovery_area/test01/control02.ctl"
ORA-27040: file create error, unable to create file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 1
ORA-19600: input file is control file  (/u01/oracle/oradata/test01/control01.ctl)
ORA-19601: output file is control file  (/u01/oracle/fast_recovery_area/test01/control02.ctl)


Finished restore at 13-JUL-14


RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 07/13/2014 01:03:19
RMAN-05501: aborting duplication of target database
RMAN-03015: error occurred in stored script Memory Script
RMAN-06136: ORACLE error from auxiliary database: ORA-00205: error in identifying control file, check alert log for more info

报错,查看orcl的alert日志
[oracle@oracle11g adump]$ env | grep ORACLE_SID
ORACLE_SID=orcl
[oracle@oracle11g trace]$ cd /u01/oracle/diag/rdbms/orcl/orcl/trace

未完明天继续。

阅读(3078) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~