Duplicating a Database Without Recovery Catalog or Target Connection

lhrbest發表於2014-07-20
  1. Duplicating a Database Without Recovery Catalog or Target Connection

    1. duplicate體系結構

搞點英語出來吧,英語不好的哥們就好好翻譯翻譯吧,這段英語是必須看懂的。。。。

You can duplicate a source database to a destination database, which can be on the same or different computers. The database instance associated with the duplicate database is called the auxiliary instance. All duplication techniques require a connection to the auxiliary instance. The diagram shows you the following techniques for database duplication:

  • From an active database, connected to the target and auxiliary instances
  • From backup, connected to the target and auxiliary instances
  • From backup, connected to the auxiliary instance, not connected to the target, but with recovery catalog connection
  • From backup, connected to the auxiliary instance, not connected to the target and the recovery catalog

 

Choosing a technique to duplicate your database—always with connection to the auxiliary instance:

 

 

 

 

簡單點就是 ①基於備份 ,而基於備份又分為3種情況 ②基於活動資料庫

 

  1. 本次實驗簡介

本次實驗就是基於備份,但是不連線到目標資料庫,也不連線到恢復目錄。

When you duplicate a database without a target database connection and without a recovery catalog, RMAN uses a BACKUP LOCATION where all necessary backups and copies reside.

The diagram illustrates backup-based duplication without connections to the target or to the recovery catalog database instance. A disk backup location containing all the backups or copies for duplication must be available to the destination host.

 

 

  1. 本次實驗原理圖

  1. 環境及搭建要求

環境:

  • Destination host :192.168.59.133 sid:orcl database:11gR2

 

 

注意事項說明:

  • 這裡的duplicate database 和 source database 的目錄結構完全一樣
  • 源資料庫和輔助資料庫的幾種不同名稱:source/target database ----&gt>>>>----- (destination host)/duplicate database (auxiliary instance)

 

 

source database環境:

SQL> select * from v$version;

 

BANNER

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

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

PL/SQL Release 11.2.0.1.0 - Production

CORE    11.2.0.1.0    Production

TNS for Linux: Version 11.2.0.1.0 - Production

NLSRTL Version 11.2.0.1.0 - Production

 

  1. 對輔助資料庫的要求

輔助資料庫應該提前安裝好資料庫,配置好環境變數。。。。。

 

輔助資料庫的環境變數配置:

[root@rhel6 ~]# su - oracle

[oracle@rhel6 ~]$ more .bash_profile

# .bash_profile

 

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

    . ~/.bashrc

fi

 

 

# User specific environment and startup programs

 

export PATH=$PATH:/sbin/:$HOME/bin

 

 

# for oracle user

 

unset USERNAME

 

export GLOBAL_DB_UNIQUE_NAME=orcl

export ORACLE_HOSTNAME=192.168.59.133

export ORACLE_UNQNAME=orcl

 

export EDITOR=vi

export ORACLE_SID=orcl

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1

export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib

export PATH=$ORACLE_HOME/bin:$PATH

umask 022

 

#export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"

export SQLPATH=$ORACLE_HOME/sqlplus/admin

 

alias sqlplus='rlwrap sqlplus'

alias rman='rlwrap rman'

alias asmcmd='rlwrap asmcmd'

alias alert_log='tail -200f $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/trace/alert_$ORACLE_SID.log'

alias alert_xml='tail -200f $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/alert/log.xml'

alias alert_listener='tail -200f $ORACLE_BASE/diag/tnslsnr/rhel6/listener/trace/listener.log'

[oracle@rhel6 ~]$

  1. 正式開始

    1. 前期準備

      1. 建表

--登入源資料庫並建立一個新的表

[oracle@rhel6 ~]$ sqlplus lhr/lhr

 

SQL*Plus: Release 11.2.0.1.0 Production on Sun Jul 20 20:54:04 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> create table test_duplicate(id number,text varchar2(20));

 

Table created.

 

SQL> insert into test_duplicate values(1,'a');

 

1 row created.

 

SQL> insert into test_duplicate values(2,'b');

 

1 row created.

 

SQL> commit;

 

Commit complete.

 

SQL>

 

  1. 資料庫歸檔模式

讓源資料庫處於歸檔模式:

[oracle@rhel6 ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.1.0 Production on Sun Jul 20 20:57:18 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> archive log list;

Database log mode     Archive Mode

Automatic archival     Enabled

Archive destination     USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence 31

Next log sequence to archive 33

Current log sequence     33

SQL>

  1. 備份資料庫

 

--備份source database並將備份傳送到destination database

[oracle@rhel6 ~]$ rman target /

 

Recovery Manager: Release 11.2.0.1.0 - Production on Sun Jul 20 20:59:18 2014

 

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

 

connected to target database: ORCL (DBID=1379935487)

 

RMAN> backup database include current controlfile plus archivelog delete input;

 

 

Starting backup at 20-JUL-14

current log archived

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=40 device type=DISK

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=5 RECID=1 STAMP=852157306

input archived log thread=1 sequence=6 RECID=2 STAMP=852374702

input archived log thread=1 sequence=7 RECID=3 STAMP=852384088

input archived log thread=1 sequence=8 RECID=4 STAMP=852384132

input archived log thread=1 sequence=9 RECID=5 STAMP=852384155

input archived log thread=1 sequence=10 RECID=6 STAMP=852384188

input archived log thread=1 sequence=11 RECID=7 STAMP=852384214

input archived log thread=1 sequence=12 RECID=8 STAMP=852384270

input archived log thread=1 sequence=13 RECID=9 STAMP=852384372

input archived log thread=1 sequence=14 RECID=10 STAMP=852384413

input archived log thread=1 sequence=15 RECID=11 STAMP=852384454

input archived log thread=1 sequence=16 RECID=12 STAMP=852384496

input archived log thread=1 sequence=17 RECID=13 STAMP=852384541

input archived log thread=1 sequence=18 RECID=14 STAMP=852384629

input archived log thread=1 sequence=19 RECID=15 STAMP=852384675

input archived log thread=1 sequence=20 RECID=16 STAMP=852384764

input archived log thread=1 sequence=21 RECID=17 STAMP=852385529

input archived log thread=1 sequence=22 RECID=18 STAMP=852391136

input archived log thread=1 sequence=23 RECID=19 STAMP=852398713

input archived log thread=1 sequence=24 RECID=20 STAMP=852398768

input archived log thread=1 sequence=25 RECID=21 STAMP=852398817

input archived log thread=1 sequence=26 RECID=22 STAMP=852398883

input archived log thread=1 sequence=27 RECID=23 STAMP=852398933

input archived log thread=1 sequence=28 RECID=24 STAMP=852426016

input archived log thread=1 sequence=29 RECID=25 STAMP=852464305

input archived log thread=1 sequence=30 RECID=26 STAMP=853429674

input archived log thread=1 sequence=31 RECID=27 STAMP=853431462

input archived log thread=1 sequence=32 RECID=28 STAMP=853437035

input archived log thread=1 sequence=33 RECID=29 STAMP=853448427

channel ORA_DISK_1: starting piece 1 at 20-JUL-14

channel ORA_DISK_1: finished piece 1 at 20-JUL-14

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_07_20/o1_mf_annnn_TAG20140720T210027_9wqhcdsw_.bkp tag=TAG20140720T210027 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:01:26

channel ORA_DISK_1: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_05/o1_mf_1_5_9vj2hrk1_.arc RECID=1 STAMP=852157306

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_6_9vppscdl_.arc RECID=2 STAMP=852374702

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_7_9vpzyom3_.arc RECID=3 STAMP=852384088

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_8_9vq0006p_.arc RECID=4 STAMP=852384132

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_9_9vq00or2_.arc RECID=5 STAMP=852384155

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_10_9vq01noz_.arc RECID=6 STAMP=852384188

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_11_9vq02jpc_.arc RECID=7 STAMP=852384214

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_12_9vq049l9_.arc RECID=8 STAMP=852384270

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_13_9vq07lm2_.arc RECID=9 STAMP=852384372

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_14_9vq08t5m_.arc RECID=10 STAMP=852384413

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_15_9vq0b484_.arc RECID=11 STAMP=852384454

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_16_9vq0cgcr_.arc RECID=12 STAMP=852384496

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_17_9vq0dvgv_.arc RECID=13 STAMP=852384541

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_18_9vq0hlld_.arc RECID=14 STAMP=852384629

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_19_9vq0k2n4_.arc RECID=15 STAMP=852384675

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_20_9vq0mssr_.arc RECID=16 STAMP=852384764

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_21_9vq1cn5m_.arc RECID=17 STAMP=852385529

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_22_9vq6v0g7_.arc RECID=18 STAMP=852391136

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_23_9vqg7jyw_.arc RECID=19 STAMP=852398713

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_24_9vqg9c92_.arc RECID=20 STAMP=852398768

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_25_9vqgbt43_.arc RECID=21 STAMP=852398817

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_26_9vqgdv00_.arc RECID=22 STAMP=852398883

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_08/o1_mf_1_27_9vqggh4k_.arc RECID=23 STAMP=852398933

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_09/o1_mf_1_28_9vr8wxfx_.arc RECID=24 STAMP=852426016

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_09/o1_mf_1_29_9vsg9jqw_.arc RECID=25 STAMP=852464305

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_20/o1_mf_1_30_9wpx0zbh_.arc RECID=26 STAMP=853429674

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_20/o1_mf_1_31_9wpys3xn_.arc RECID=27 STAMP=853431462

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_20/o1_mf_1_32_9wq47c1r_.arc RECID=28 STAMP=853437035

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_20/o1_mf_1_33_9wqhcc06_.arc RECID=29 STAMP=853448427

Finished backup at 20-JUL-14

 

Starting backup at 20-JUL-14

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf

input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf

channel ORA_DISK_1: starting piece 1 at 20-JUL-14

channel ORA_DISK_1: finished piece 1 at 20-JUL-14

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_07_20/o1_mf_nnndf_TAG20140720T210155_9wqhg4nj_.bkp tag=TAG20140720T210155 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

including current control file in backup set

including current SPFILE in backup set

channel ORA_DISK_1: starting piece 1 at 20-JUL-14

channel ORA_DISK_1: finished piece 1 at 20-JUL-14

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_07_20/o1_mf_ncsnf_TAG20140720T210155_9wqhjkgq_.bkp tag=TAG20140720T210155 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 20-JUL-14

 

Starting backup at 20-JUL-14

current log archived

using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=34 RECID=30 STAMP=853448595

channel ORA_DISK_1: starting piece 1 at 20-JUL-14

channel ORA_DISK_1: finished piece 1 at 20-JUL-14

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_07_20/o1_mf_annnn_TAG20140720T210315_9wqhjmb6_.bkp tag=TAG20140720T210315 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

channel ORA_DISK_1: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_20/o1_mf_1_34_9wqhjlyf_.arc RECID=30 STAMP=853448595

Finished backup at 20-JUL-14

 

RMAN>

 

這裡記錄備份位置(Backup location),預設在閃回恢復區,後邊恢復的時候需要使用:

/u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_07_20/

 

 

  1. 將備份內容拷貝到destination host

[oracle@rhel6 orcl]$ scp -r /u01/app/oracle/flash_recovery_area/ oracle@192.168.59.133:/u01/app/oracle/

oracle@192.168.59.133's password:

o1_mf_annnn_TAG20140720T210027_9wqhcdsw_.bkp 100% 1055MB 10.6MB/s 01:40

o1_mf_ncsnf_TAG20140720T210155_9wqhjkgq_.bkp 100% 9632KB 3.1MB/s 00:03

o1_mf_nnndf_TAG20140720T210155_9wqhg4nj_.bkp 100% 1018MB 10.7MB/s 01:35

o1_mf_annnn_TAG20140720T210315_9wqhjmb6_.bkp 100% 1266KB 1.2MB/s 00:00

[oracle@rhel6 orcl]$

 

 

  1. 建立pfile 引數檔案

--生成文字初始化引數檔案並傳送到destination host

[oracle@rhel6 orcl]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.1.0 Production on Sun Jul 20 21:32:25 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> create pfile from spfile;

 

File created.

 

SQL> exit

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

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

[oracle@rhel6 orcl]$ cd $ORACLE_HOME/dbs

[oracle@rhel6 dbs]$ ll

total 9592

-rw-rw----. 1 oracle oinstall 1544 Jul 20 15:47 hc_orcl.dat

-rw-rw----. 1 oracle oinstall 1544 Jul 9 11:39 hc_rman.dat

-rw-r--r--. 1 oracle oinstall 2851 May 15 2009 init.ora

-rw-r--r--. 1 oracle oinstall 1015 Jul 20 21:32 initorcl.ora

-rw-r-----. 1 oracle oinstall 24 Jul 5 21:39 lkORCL

-rw-r-----. 1 oracle oinstall 24 Jul 5 21:56 lkRMAN

-rw-r-----. 1 oracle oinstall 1536 Jul 10 16:33 orapworcl

-rw-r-----. 1 oracle oinstall 1536 Jul 9 16:32 orapwrman

-rw-r-----. 1 oracle oinstall 9781248 Jul 20 21:03 snapcf_orcl.f

-rw-r-----. 1 oracle oinstall 3584 Jul 20 15:58 spfileorcl.ora

-rw-r-----. 1 oracle oinstall 2560 Jul 9 16:37 spfilerman.ora

[oracle@rhel6 dbs]$ scp $ORACLE_HOME/dbs/initorcl.ora oracle@192.168.59.133:$ORACLE_HOME/dbs/

oracle@192.168.59.133's password:

initorcl.ora 100% 1015 1.0KB/s 00:00

[oracle@rhel6 dbs]$

 

確保傳遞到目的地:

 

 

 

 

 

 

  1. 建立和source database的資料檔案相關的目錄結構

根據傳遞過來的引數檔案來建立目錄:

[oracle@rhel6 dbs]$ more initorcl.ora

orcl.__db_cache_size=50331648

orcl.__java_pool_size=4194304

orcl.__large_pool_size=4194304

orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment

orcl.__pga_aggregate_target=130023424

orcl.__sga_target=184549376

orcl.__shared_io_pool_size=0

orcl.__shared_pool_size=117440512

orcl.__streams_pool_size=0

*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'

*.audit_trail='db'

*.compatible='11.2.0.0.0'

*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/flash_recovery_area/orcl/control02.ctl'

*.db_block_size=8192

*.db_domain='lhr.com'

*.db_name='orcl'

*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'

*.db_recovery_file_dest_size=4070572032

*.diagnostic_dest='/u01/app/oracle'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'

*.job_queue_processes=1000

*.local_listener='LSNR_ORCL'

*.log_archive_format='%t_%s_%r.dbf'

*.memory_target=314572800

*.open_cursors=300

*.processes=50

*.remote_login_passwordfile='EXCLUSIVE'

*.sessions=60

*.undo_tablespace='UNDOTBS1'

[oracle@rhel6 dbs]$ mkdir -p /u01/app/oracle/oradata/orcl

[oracle@rhel6 dbs]$ mkdir -p /u01/app/oracle/admin/orcl/adump

[oracle@rhel6 dbs]$

 

  1. 建立密碼檔案

 

[oracle@rhel6 dbs]$ orapwd file=?/dbs/orapworcl password=lhr

[oracle@rhel6 dbs]$ ll -h

total 12K

-rw-r--r--. 1 oracle oinstall 2.8K May 15 2009 init.ora

-rw-r--r--. 1 oracle oinstall 13 Jul 20 16:03 initorcl.ora

-rw-r-----. 1 oracle oinstall 1.5K Jul 20 16:09 orapworcl

[oracle@rhel6 dbs]$

 

 

  1. 實施資料庫的複製

--啟動auxiliary instancenomount狀態

 

  1. 啟動Auxiliary 到nomout 狀態

[oracle@rhel6 ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.1.0 Production on Sun Jul 20 16:48:04 2014

 

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

 

Connected to an idle instance.

 

SQL> startup nomount;

ORACLE instance started.

 

Total System Global Area 217157632 bytes

Fixed Size         2211928 bytes

Variable Size         159387560 bytes

Database Buffers     50331648 bytes

Redo Buffers         5226496 bytes

SQL>

 

 

 

 

 

 

  1. 連線到auxiliary instance並複製資料庫

 

 

注意:如果target 和 Auxiliary庫的目錄結構相同,記得加上nofilenamecheck引數,不然會報如下錯誤:

RMAN-05001: auxiliary file name /u01/app/oracle/oradata/orcl/users01.dbf conflicts with a file used by the target database

 

[oracle@rhel6 dbs]$ rman auxiliary /

 

Recovery Manager: Release 11.2.0.1.0 - Production on Sun Jul 20 22:11:21 2014

 

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

 

connected to auxiliary database: ORCL (not mounted)

 

RMAN> duplicate target database to orcl backup location '/u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_07_20' nofilenamecheck;

 

Starting Duplicate Db at 20-JUL-14

 

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 =

''ORCL'' comment=

''Modified by RMAN duplicate'' scope=spfile";

shutdown clone immediate;

startup clone force nomount

restore clone primary controlfile from '/u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_07_20/o1_mf_ncsnf_TAG20140720T210155_9wqhjkgq_.bkp';

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 = ''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfile

 

Oracle instance shut down

 

Oracle instance started

 

Total System Global Area 313159680 bytes

 

Fixed Size 2212936 bytes

Variable Size 260049848 bytes

Database Buffers 46137344 bytes

Redo Buffers 4759552 bytes

 

Starting restore at 20-JUL-14

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=18 device type=DISK

 

channel ORA_AUX_DISK_1: restoring control file

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01

output file name=/u01/app/oracle/oradata/orcl/control01.ctl

output file name=/u01/app/oracle/flash_recovery_area/orcl/control02.ctl

Finished restore at 20-JUL-14

 

database mounted

released channel: ORA_AUX_DISK_1

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=18 device type=DISK

Using previous duplicated file /u01/app/oracle/oradata/orcl/system01.dbf for datafile 1 with checkpoint SCN of 1403286

Using previous duplicated file /u01/app/oracle/oradata/orcl/sysaux01.dbf for datafile 2 with checkpoint SCN of 1403286

Using previous duplicated file /u01/app/oracle/oradata/orcl/undotbs01.dbf for datafile 3 with checkpoint SCN of 1403286

Using previous duplicated file /u01/app/oracle/oradata/orcl/users01.dbf for datafile 4 with checkpoint SCN of 1403286

Using previous duplicated file /u01/app/oracle/oradata/orcl/example01.dbf for datafile 5 with checkpoint SCN of 1403286

 

contents of Memory Script:

{

catalog clone datafilecopy "/u01/app/oracle/oradata/orcl/system01.dbf",

"/u01/app/oracle/oradata/orcl/sysaux01.dbf",

"/u01/app/oracle/oradata/orcl/undotbs01.dbf",

"/u01/app/oracle/oradata/orcl/users01.dbf",

"/u01/app/oracle/oradata/orcl/example01.dbf";

switch clone datafile 1 to datafilecopy

"/u01/app/oracle/oradata/orcl/system01.dbf";

switch clone datafile 2 to datafilecopy

"/u01/app/oracle/oradata/orcl/sysaux01.dbf";

switch clone datafile 3 to datafilecopy

"/u01/app/oracle/oradata/orcl/undotbs01.dbf";

switch clone datafile 4 to datafilecopy

"/u01/app/oracle/oradata/orcl/users01.dbf";

switch clone datafile 5 to datafilecopy

"/u01/app/oracle/oradata/orcl/example01.dbf";

}

executing Memory Script

 

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/orcl/system01.dbf RECID=1 STAMP=853452698

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf RECID=2 STAMP=853452698

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf RECID=3 STAMP=853452698

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/orcl/users01.dbf RECID=4 STAMP=853452698

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/orcl/example01.dbf RECID=5 STAMP=853452698

 

datafile 1 switched to datafile copy

input datafile copy RECID=1 STAMP=853452698 file name=/u01/app/oracle/oradata/orcl/system01.dbf

 

datafile 2 switched to datafile copy

input datafile copy RECID=2 STAMP=853452698 file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

 

datafile 3 switched to datafile copy

input datafile copy RECID=3 STAMP=853452698 file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

 

datafile 4 switched to datafile copy

input datafile copy RECID=4 STAMP=853452698 file name=/u01/app/oracle/oradata/orcl/users01.dbf

 

datafile 5 switched to datafile copy

input datafile copy RECID=5 STAMP=853452698 file name=/u01/app/oracle/oradata/orcl/example01.dbf

 

contents of Memory Script:

{

set until scn 1403324;

recover

clone database

delete archivelog

;

}

executing Memory Script

 

executing command: SET until clause

 

Starting recover at 20-JUL-14

using channel ORA_AUX_DISK_1

 

starting media recovery

 

channel ORA_AUX_DISK_1: starting archived log restore to default destination

channel ORA_AUX_DISK_1: restoring archived log

archived log thread=1 sequence=34

channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_07_20/o1_mf_annnn_TAG20140720T210315_9wqhjmb6_.bkp

channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_07_20/o1_mf_annnn_TAG20140720T210315_9wqhjmb6_.bkp tag=TAG20140720T210315

channel ORA_AUX_DISK_1: restored backup piece 1

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_20/o1_mf_1_34_9wqmjvkt_.arc thread=1 sequence=34

channel clone_default: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_07_20/o1_mf_1_34_9wqmjvkt_.arc RECID=1 STAMP=853452699

media recovery complete, elapsed time: 00:00:00

Finished recover at 20-JUL-14

 

contents of Memory Script:

{

shutdown clone immediate;

startup clone nomount;

sql clone "alter system set db_name =

''ORCL'' comment=

''Reset to original value by RMAN'' scope=spfile";

sql clone "alter system reset db_unique_name scope=spfile";

shutdown clone immediate;

startup clone nomount;

}

executing Memory Script

 

database dismounted

Oracle instance shut down

 

connected to auxiliary database (not started)

Oracle instance started

 

Total System Global Area 313159680 bytes

 

Fixed Size 2212936 bytes

Variable Size 260049848 bytes

Database Buffers 46137344 bytes

Redo Buffers 4759552 bytes

 

sql statement: alter system set db_name = ''ORCL'' comment= ''Reset to original value by RMAN'' scope=spfile

 

sql statement: alter system reset db_unique_name scope=spfile

 

Oracle instance shut down

 

connected to auxiliary database (not started)

Oracle instance started

 

Total System Global Area 313159680 bytes

 

Fixed Size 2212936 bytes

Variable Size 260049848 bytes

Database Buffers 46137344 bytes

Redo Buffers 4759552 bytes

sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORCL" RESETLOGS ARCHIVELOG

MAXLOGFILES 16

MAXLOGMEMBERS 3

MAXDATAFILES 100

MAXINSTANCES 8

MAXLOGHISTORY 292

LOGFILE

GROUP 1 SIZE 50 M ,

GROUP 2 SIZE 50 M ,

GROUP 3 SIZE 50 M

DATAFILE

'/u01/app/oracle/oradata/orcl/system01.dbf'

CHARACTER SET ZHS16GBK

 

 

contents of Memory Script:

{

set newname for tempfile 1 to

"/u01/app/oracle/oradata/orcl/temp01.dbf";

switch clone tempfile all;

catalog clone datafilecopy "/u01/app/oracle/oradata/orcl/sysaux01.dbf",

"/u01/app/oracle/oradata/orcl/undotbs01.dbf",

"/u01/app/oracle/oradata/orcl/users01.dbf",

"/u01/app/oracle/oradata/orcl/example01.dbf";

switch clone datafile all;

switch clone datafile 2 to datafilecopy

"/u01/app/oracle/oradata/orcl/sysaux01.dbf";

switch clone datafile 3 to datafilecopy

"/u01/app/oracle/oradata/orcl/undotbs01.dbf";

switch clone datafile 4 to datafilecopy

"/u01/app/oracle/oradata/orcl/users01.dbf";

switch clone datafile 5 to datafilecopy

"/u01/app/oracle/oradata/orcl/example01.dbf";

}

executing Memory Script

 

executing command: SET NEWNAME

 

renamed tempfile 1 to /u01/app/oracle/oradata/orcl/temp01.dbf in control file

 

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf RECID=1 STAMP=853452713

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf RECID=2 STAMP=853452713

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/orcl/users01.dbf RECID=3 STAMP=853452713

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/orcl/example01.dbf RECID=4 STAMP=853452713

 

 

datafile 2 switched to datafile copy

input datafile copy RECID=1 STAMP=853452713 file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

 

datafile 3 switched to datafile copy

input datafile copy RECID=2 STAMP=853452713 file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

 

datafile 4 switched to datafile copy

input datafile copy RECID=3 STAMP=853452713 file name=/u01/app/oracle/oradata/orcl/users01.dbf

 

datafile 5 switched to datafile copy

input datafile copy RECID=4 STAMP=853452713 file name=/u01/app/oracle/oradata/orcl/example01.dbf

 

contents of Memory Script:

{

Alter clone database open resetlogs;

}

executing Memory Script

 

database opened

Finished Duplicate Db at 20-JUL-14

 

RMAN>

 

  1. 可能的報錯

    1. fra滿了

channel ORA_AUX_DISK_1: starting archived log restore to default destination

channel ORA_AUX_DISK_1: restoring archived log

archived log thread=1 sequence=34

channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_07_20/o1_mf_annnn_TAG20140720T210315_9wqhjmb6_.bkp

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of Duplicate Db command at 07/20/2014 22:03:42

RMAN-03015: error occurred in stored script Memory Script

ORA-19870: error while restoring backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_07_20/o1_mf_annnn_TAG20140720T210315_9wqhjmb6_.bkp

ORA-19809: limit exceeded for recovery files

ORA-19804: cannot reclaim 1294336 bytes disk space from 4070572032 limit

 

RMAN>

 

 

解決辦法:由於fra是直接從目標資料庫copy過來的,可能db_recovery_file_dest_size    設定過小,所以啟動auxiliary庫到nomount狀態,然後把該引數改大一點即可(alter system set db_recovery_file_dest_size=8G;

 

  1. 備份位置

 

RMAN> duplicate target database to orcl spfile backup location '/u01/app/oracle/fast_recovery_area/ORCL' nofilenamecheck;

 

Starting Duplicate Db at 20-JUL-14

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of Duplicate Db command at 07/20/2014 21:52:23

RMAN-05569: SPFILE backup not found in /u01/app/oracle/fast_recovery_area/ORCL

 

解決辦法:將命令中的backup location修改為備份的直接位置:

duplicate target database to orcl backup location '/u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_07_20' nofilenamecheck;

大家可以看到ORCL目錄下仍然有很多其它資料夾的:

 

 

 

  1. 驗證

[oracle@rhel6 2014_07_20]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.1.0 Production on Sun Jul 20 22:13: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 open_mode,name,dbid from v$database;

 

OPEN_MODE     NAME     DBID

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

READ WRITE     ORCL 1381233448

 

SQL> archive log list;

Database log mode     Archive Mode

Automatic archival     Enabled

Archive destination     USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence 1

Next log sequence to archive 1

Current log sequence     1

SQL>

 

SQL> select * from lhr.test_duplicate;

 

    ID TEXT

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

     1 a

     2 b

 

SQL> show parameter spfile

 

NAME                 TYPE     VALUE

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

spfile                 string     /u01/app/oracle/product/11.2.0

                         /dbhome_1/dbs/spfileorcl.ora

SQL>

 

搞定。。。。。。。。。。。。。。。。。

  1. drop database

刪掉資料庫準備做其它實驗:

 

[oracle@rhel6 2014_07_20]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.1.0 Production on Sun Jul 20 22:17:16 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> shutdown abort

ORACLE instance shut down.

SQL> startup mount restrict;

ORACLE instance started.

 

Total System Global Area 217157632 bytes

Fixed Size         2211928 bytes

Variable Size         159387560 bytes

Database Buffers     50331648 bytes

Redo Buffers         5226496 bytes

Database mounted.

SQL> exit

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

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

[oracle@rhel6 orcl]$ rman target /

 

Recovery Manager: Release 11.2.0.1.0 - Production on Sun Jul 20 18:07:32 2014

 

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

 

connected to target database: ORCL (DBID=1381233448, not open)

 

RMAN> drop database;

 

database name is "ORCL" and DBID is 1381233448

 

Do you really want to drop the database (enter YES or NO)? yes

database dropped

 

RMAN>




來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26736162/viewspace-1223253/,如需轉載,請註明出處,否則將追究法律責任。

相關文章