RMAN duplicate database

shuyingxi發表於2013-03-31

1. 為輔助資料庫建立目錄結構

mkdir /u01/app/oracle/oradata/dupdb

mkdir /u01/app/oracle/admin/dupdb

mkdir /u01/app/oracle/admin/dupdb/adump

mkdir /u01/app/oracle/flash_recovery_area/dupdb

 

2. ORCL資料庫生成pfile引數檔案,並進行復制、修改建立出輔助資料庫的引數檔案

source db(orcl)生成pfile

SQL> create pfile from spfile;

File created.

 

複製pfile並做相應修改:

[oracle@ora10g oracle]$ cd $ORACLE_HOME/dbs

[oracle@ora10g dbs]$ cp initorcl.ora initdupdb.ora

修改initdupdb.ora內容:

vi initdupdb.ora

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

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

*.db_name='dupdb'

*.db_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/dupdb'        

*.log_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/dupdb'   

 

3. 啟動輔助資料庫例項startup nomount duplicate db dupdb

[oracle@ora10g dbs]$  export ORACLE_SID=dupdb

[oracle@ora10g dupdb]$  sqlplus "/ as sysdba"

SQL>  startup force nomount pfile=/u01/app/oracle/product/11.2.0/db_1/dbs/initdupdb.ora

ORACLE instance started.

Total System Global Area  313860096 bytes

Fixed Size                  1336232 bytes

Variable Size             205524056 bytes

Database Buffers          100663296 bytes

Redo Buffers                6336512 bytes

 

4. 為輔助資料庫建立口令檔案

[oracle@ora10g dbs]$  export ORACLE_SID=dupdb

[oracle@ora10g dbs]$  orapwd file=/u01/app/oracle/product/11.2.0/db_1/dbs/orapwdupdb password=oracjle entries=5 force=y

 

5. 編輯tnsnames.ora檔案,增加下列服務連線別名

[oracle@ora10g admin]$ vi $ORACLE_HOME/network/admin/tnsnames.ora

ORCL =

  (DESCRIPTION =

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

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = ORCL)

    )

  )

DUPDB =

  (DESCRIPTION =

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

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = DUPDB)

    )

  )

 

6. 編輯監聽器配置檔案listener.ora, 啟動監聽器

[oracle@ora10g ~]$ vi $ORACLE_HOME/network/admin/listener.ora

LISTENER =

  (DESCRIPTION =

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

  )

 

SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (SID_NAME = orcl)

      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)

    )

    (SID_DESC =

      (SID_NAME = dupdb)

      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)

    )

  )

 

[oracle@ora10g ~]$ lsnrctl start

 

7. 備份還原資料庫orcl

[oracle@ora10g admin]$ export ORACLE_SID=orcl

[oracle@ora10g admin]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Fri Mar 29 12:56:24 2013

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

connected to target database: ORCL (DBID=1321883643)

RMAN>  backup database plus archivelog;

8. 開始RMAN duplicate複製

[oracle@ora10g oradup]$  rman target sys/oracle@orcl auxiliary sys/oracle@dupdb

Recovery Manager: Release 11.2.0.1.0 - Production on Sun Mar 31 06:43:08 2013

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

connected to target database: ORCL (DBID=1321883643)

connected to auxiliary database: DUPDB (not mounted)

 

RMAN> DUPLICATE TARGET DATABASE TO dupdb;

Starting Duplicate Db at 31-MAR-13

using target database control file instead of recovery catalog

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=18 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     313860096 bytes

 

Fixed Size                     1336232 bytes

Variable Size                255855704 bytes

Database Buffers              50331648 bytes

Redo Buffers                   6336512 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 =

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

 

Oracle instance shut down

 

Oracle instance started

 

Total System Global Area     313860096 bytes

 

Fixed Size                     1336232 bytes

Variable Size                255855704 bytes

Database Buffers              50331648 bytes

Redo Buffers                   6336512 bytes

 

Starting restore at 31-MAR-13

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=19 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 /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2013_03_31/o1_mf_s_811492968_8ogtm8cb_.bkp

channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2013_03_31/o1_mf_s_811492968_8ogtm8cb_.bkp

tag=TAG20130331T064248

channel ORA_AUX_DISK_1: restored backup piece 1

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

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

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

Finished restore at 31-MAR-13

 

database mounted

 

contents of Memory Script.:

{

   set until scn  1005032;

   set newname for datafile  1 to

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

   set newname for datafile  2 to

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

   set newname for datafile  3 to

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

   set newname for datafile  4 to

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

   set newname for datafile  5 to

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

   restore

   clone database

   ;

}

executing Memory Script

 

executing command: SET until clause

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

Starting restore at 31-MAR-13

using channel ORA_AUX_DISK_1

 

channel ORA_AUX_DISK_1: starting datafile backup set restore

channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/dupdb/system01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/dupdb/sysaux01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/dupdb/undotbs01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/dupdb/users01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/dupdb/example01.dbf

channel ORA_AUX_DISK_1: reading from backup piece

/u01/app/oracle/flash_recovery_area/ORCL/backupset/2013_03_31/o1_mf_nnndf_TAG20130331T064111_8ogtj7nb_.bkp

channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2013_03_31/o1_mf_nnndf_TAG20130331T064111_8ogtj7nb_.bkp

tag=TAG20130331T064111

channel ORA_AUX_DISK_1: restored backup piece 1

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

Finished restore at 31-MAR-13

 

contents of Memory Script.:

{

   switch clone datafile all;

}

executing Memory Script

 

datafile 1 switched to datafile copy

input datafile copy RECID=7 STAMP=811497039 file name=/u01/app/oracle/oradata/dupdb/system01.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=8 STAMP=811497039 file name=/u01/app/oracle/oradata/dupdb/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=9 STAMP=811497039 file name=/u01/app/oracle/oradata/dupdb/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=10 STAMP=811497039 file name=/u01/app/oracle/oradata/dupdb/users01.dbf

datafile 5 switched to datafile copy

input datafile copy RECID=11 STAMP=811497039 file name=/u01/app/oracle/oradata/dupdb/example01.dbf

 

contents of Memory Script.:

{

   set until scn  1005032;

   recover

   clone database

    delete archivelog

   ;

}

executing Memory Script

 

executing command: SET until clause

 

Starting recover at 31-MAR-13

using channel ORA_AUX_DISK_1

 

starting media recovery

 

archived log for thread 1 with sequence 26 is already on disk as file /u01/app/oracle/arch/1_26_794102915.dbf

archived log file name=/u01/app/oracle/arch/1_26_794102915.dbf thread=1 sequence=26

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

Finished recover at 31-MAR-13

 

contents of Memory Script.:

{

   shutdown clone immediate;

   startup clone nomount;

   sql clone "alter system set  db_name =

 ''DUPDB'' 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     313860096 bytes

 

Fixed Size                     1336232 bytes

Variable Size                255855704 bytes

Database Buffers              50331648 bytes

Redo Buffers                   6336512 bytes

 

sql statement: alter system set  db_name =  ''DUPDB'' 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     313860096 bytes

 

Fixed Size                     1336232 bytes

Variable Size                255855704 bytes

Database Buffers              50331648 bytes

Redo Buffers                   6336512 bytes

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

  MAXLOGFILES     16

  MAXLOGMEMBERS      3

  MAXDATAFILES      100

  MAXINSTANCES     8

  MAXLOGHISTORY      292

 LOGFILE

  GROUP  1 ( '/u01/app/oracle/oradata/dupdb/redo01.log' ) SIZE 50 M  REUSE,

  GROUP  2 ( '/u01/app/oracle/oradata/dupdb/redo02.log' ) SIZE 50 M  REUSE,

  GROUP  3 ( '/u01/app/oracle/oradata/dupdb/redo03.log' ) SIZE 50 M  REUSE

 DATAFILE

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

 CHARACTER SET WE8MSWIN1252

 

 

contents of Memory Script.:

{

   set newname for tempfile  1 to

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

   switch clone tempfile all;

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

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

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

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

   switch clone datafile all;

}

executing Memory Script

 

executing command: SET NEWNAME

 

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

 

cataloged datafile copy

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

cataloged datafile copy

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

cataloged datafile copy

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

cataloged datafile copy

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

 

datafile 2 switched to datafile copy

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

datafile 3 switched to datafile copy

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

datafile 4 switched to datafile copy

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

datafile 5 switched to datafile copy

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

 

contents of Memory Script.:

{

   Alter clone database open resetlogs;

}

executing Memory Script

 

database opened

Finished Duplicate Db at 31-MAR-13

 

 

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

相關文章