RMAN複製資料庫(六)

eric0435發表於2015-03-26

在相同主機上建立複製資料庫
當在與目標資料庫相同主機上建立複製資料庫就與在遠端主機上使用不同目錄結構複製資料庫一樣。可以在目標資料庫的Oracle Home目錄中建立複製資料庫,但資料庫名必須不同於目標資料庫。

1.建立輔助例項的密碼檔案(這裡輔助例項名為aux)

[oracle@oracle11g dbs]$ orapwd file=/u01/app/oracle/product/10.2.0/db/dbs/orapwaux password=oracle entries=10;
[oracle@oracle11g dbs]$ ls -lrt
-rw-r----- 1 oracle oinstall    2560 Mar 24 14:47 orapwdup

2.建立輔助例項網路連線,修改監聽檔案,使用靜態監聽來監聽輔助例項

[oracle@oracle11g dbs]$ vi listener.ora

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
     (SID_NAME = aux)
      (ORACLE_HOME =/u01/app/oracle/product/10.2.0/db)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.11)(PORT = 1521))
    )
  )

給輔助例項增加網路服務名

[oracle@oracle11g dbs]$ vi tnsnames.ora
aux =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME =aux)
      (UR=A)
    )
  )

測試網路連線

[oracle@oracle11g dbs]$ export ORACLE_SID=aux
[oracle@oracle11g dbs]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 14:57:08 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/oracle@dup as sysdba
Connected to an idle instance.

3.建立輔助例項的引數檔案

[oracle@oracle11g dbs]$ vi initdup.ora

db_name=aux
db_unique_name=aux
control_files= /u01/app/oracle/oradata/aux/control01.ctl
db_file_name_convert=('/u01/app/oracle/oradata/test/','/u01/app/oracle/oradata/aux/')
log_file_name_convert=('/u01/app/oracle/oradata/test/','/u01/app/oracle/oradata/aux/')
remote_login_passwordfile=exclusive
compatible = 10.2.0.5.0
db_block_size=8192
sga_target=160M
sga_max_size=160M
pga_aggregate_target=16M



[oracle@oracle11g dbs]$ export ORACLE_SID=aux
[oracle@oracle11g dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 21:13:44 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> create spfile from pfile='/u01/app/oracle/product/10.2.0/db/dbs/initaux.ora';

File created.

4.啟動輔助例項

[oracle@oracle11g dbs]$ export ORACLE_SID=aux
[oracle@oracle11g dbs]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 21:13:44 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


SQL> conn sys/oracle@dup as sysdba
Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272624 bytes
Variable Size              58721488 bytes
Database Buffers          104857600 bytes
Redo Buffers                2920448 bytes

SQL> show parameter spfile

NAME                                 TYPE                   VALUE
------------------------------------ ---------------------- ------------------------------
spfile                               string                 /u01/app/oracle/product/10.2.0
                                                            /db/dbs/spfileaux.ora

斷開連線

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

這裡一定要斷開啟動輔助例項的會話否則在執行復制操作時會出現如下錯誤 :

executing Memory Script

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 03/24/2015 18:28:32
RMAN-03015: error occurred in stored script Memory Script
RMAN-06136: ORACLE error from auxiliary database: ORA-01013: user requested cancel of current operation

配置輔助例項的網路服務名

[oracle@oracle11g admin]$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/10.2.0/db/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

JY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = jy)
    )
  )

TEST =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.2)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = test)
    )
  )




aux =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME =aux)
      (UR=A)
    )
  )

[oracle@oracle11g dbs]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 21:13:44 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/oracle@aux as sysdba
Connected.

5.載入或開啟目標資料庫

[oracle@oracle11g ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 21:13:44 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272600 bytes
Variable Size              92275944 bytes
Database Buffers           71303168 bytes
Redo Buffers                2920448 bytes
Database mounted.
Database opened.

6.確保有需要的備份和歸檔重做日誌,對目標資料庫(被複制的資料庫)進行備份(包含資料檔案和歸檔重做日誌)

[oracle@oracle11g admin]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g admin]$ rman target sys/zzh_2046@test catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Mar 24 15:15:52 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database

RMAN> backup as backupset database plus archivelog delete all input;


Starting backup at 25-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=65 recid=72 stamp=875262973
input archive log thread=1 sequence=66 recid=73 stamp=875266238
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266246_751 tag=TAG20150325T093040 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u02/1_65_870806981.dbf recid=72 stamp=875262973
archive log filename=/u02/1_66_870806981.dbf recid=73 stamp=875266238
Finished backup at 25-MAR-15

Starting backup at 25-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/test/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/test/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/test/tspitr01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/test/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266253_761 tag=TAG20150325T093052 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:46
Finished backup at 25-MAR-15

Starting backup at 25-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=67 recid=74 stamp=875266422
channel ORA_DISK_1: starting piece 1 at 25-MAR-15
channel ORA_DISK_1: finished piece 1 at 25-MAR-15
piece handle=/u02/ora_test875266425_771 tag=TAG20150325T093344 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u02/1_67_870806981.dbf recid=74 stamp=875266422
Finished backup at 25-MAR-15

Starting Control File and SPFILE Autobackup at 25-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_25/o1_mf_s_875266428_bk4441pd_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 25-MAR-15

RMAN> list backup;


List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
4782    5.72M      DISK        00:00:04     25-MAR-15
        BP Key: 4783   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093040
        Piece Name: /u02/ora_test875266246_751

  List of Archived Logs in backup set 4782
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    65      1009334    24-MAR-15 1038362    25-MAR-15
  1    66      1038362    25-MAR-15 1040219    25-MAR-15

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4794    Full    624.76M    DISK        00:02:40     25-MAR-15
        BP Key: 4797   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093052
        Piece Name: /u02/ora_test875266253_761
  List of Datafiles in backup set 4794
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/system01.dbf
  2       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/undotbs01.dbf
  3       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/sysaux01.dbf
  4       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/users01.dbf
  5       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/example01.dbf
  6       Full 1040242    25-MAR-15 /u01/app/oracle/oradata/test/tspitr01.dbf

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
4811    12.50K     DISK        00:00:01     25-MAR-15
        BP Key: 4818   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093344
        Piece Name: /u02/ora_test875266425_771

  List of Archived Logs in backup set 4811
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    67      1040219    25-MAR-15 1040304    25-MAR-15

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4827    Full    6.89M      DISK        00:00:06     25-MAR-15
        BP Key: 4829   Status: AVAILABLE  Compressed: NO  Tag: TAG20150325T093348
        Piece Name: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_25/o1_mf_s_875266428_bk4441pd_.bkp
  Control File Included: Ckp SCN: 1040326      Ckp time: 25-MAR-15
  SPFILE Included: Modification time: 25-MAR-15

7.執行duplicate命令,如果沒有配置自動通道,那麼至少手動分配一個輔助例項如果是使用PFILE引數檔案啟動輔助例項需要指定pfile引數檔案,且pfile引數檔案必須儲存在執行RMAN執行復制的主機上。這裡輔助例項使用SPFILE引數檔案來啟動,並使用自動通道:

[oracle@oracle11g ~]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g ~]$ rman target sys/zzh_2046@test auxiliary sys/system@aux catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Wed Mar 25 10:49:35 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database
connected to auxiliary database: AUX (not mounted)

RMAN> duplicate target database to aux nofilenamecheck;

Starting Duplicate Db at 2015-03-25 10:50:29
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=38 devtype=DISK

contents of Memory Script:
{
   set until scn  1040304;
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/aux/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/oradata/aux/undotbs01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/aux/sysaux01.dbf";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/aux/users01.dbf";
   set newname for datafile  5 to
 "/u01/app/oracle/oradata/aux/example01.dbf";
   set newname for datafile  6 to
 "/u01/app/oracle/oradata/aux/tspitr01.dbf";
   restore
   check readonly
   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

executing command: SET NEWNAME

Starting restore at 2015-03-25 10:50:30
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/aux/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/aux/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/aux/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/aux/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/aux/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/aux/tspitr01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875266253_761
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875266253_761 tag=TAG20150325T093052
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:56
Finished restore at 2015-03-25 10:52:28
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "AUX" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '/u01/app/oracle/oradata/aux/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '/u01/app/oracle/oradata/aux/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '/u01/app/oracle/oradata/aux/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/aux/system01.dbf'
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875271151 filename=/u01/app/oracle/oradata/aux/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875271151 filename=/u01/app/oracle/oradata/aux/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875271151 filename=/u01/app/oracle/oradata/aux/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875271151 filename=/u01/app/oracle/oradata/aux/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875271151 filename=/u01/app/oracle/oradata/aux/tspitr01.dbf

contents of Memory Script:
{
   set until scn  1040304;
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 2015-03-25 10:52:30
using channel ORA_AUX_DISK_1

starting media recovery

channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=67
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875266425_771
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875266425_771 tag=TAG20150325T093344
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/u01/app/oracle/10.2.0/db/dbs/arch1_67_870806981.dbf thread=1 sequence=67
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/10.2.0/db/dbs/arch1_67_870806981.dbf recid=1 stamp=875271154
media recovery complete, elapsed time: 00:00:03
Finished recover at 2015-03-25 10:52:38

contents of Memory Script:
{
   shutdown clone;
   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     167772160 bytes

Fixed Size                     1272624 bytes
Variable Size                 58721488 bytes
Database Buffers             104857600 bytes
Redo Buffers                   2920448 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "AUX" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '/u01/app/oracle/oradata/aux/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '/u01/app/oracle/oradata/aux/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '/u01/app/oracle/oradata/aux/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/aux/system01.dbf'
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   set newname for tempfile  1 to
 "/u01/app/oracle/oradata/aux/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata/aux/undotbs01.dbf";
   catalog clone datafilecopy  "/u01/app/oracle/oradata/aux/sysaux01.dbf";
   catalog clone datafilecopy  "/u01/app/oracle/oradata/aux/users01.dbf";
   catalog clone datafilecopy  "/u01/app/oracle/oradata/aux/example01.dbf";
   catalog clone datafilecopy  "/u01/app/oracle/oradata/aux/tspitr01.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed temporary file 1 to /u01/app/oracle/oradata/aux/temp01.dbf in control file

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/aux/undotbs01.dbf recid=1 stamp=875271167

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/aux/sysaux01.dbf recid=2 stamp=875271167

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/aux/users01.dbf recid=3 stamp=875271167

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/aux/example01.dbf recid=4 stamp=875271167

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/aux/tspitr01.dbf recid=5 stamp=875271168

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875271167 filename=/u01/app/oracle/oradata/aux/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875271167 filename=/u01/app/oracle/oradata/aux/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875271167 filename=/u01/app/oracle/oradata/aux/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875271167 filename=/u01/app/oracle/oradata/aux/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875271168 filename=/u01/app/oracle/oradata/aux/tspitr01.dbf

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 2015-03-25 10:53:24


[oracle@oracle11g admin]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Mar 25 10:53:30 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select instance_name from v$instance;

INSTANCE_NAME
----------------
aux

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

相關文章