天天看點

Duplicating a Database

使用duplicate指令,可以建立一個完全獨立的資料庫拷貝,該指令執行過程中會自動為duplicated 資料庫配置設定一個新的dbid。其具體過程我們以同一台機器内部複制和兩台機器間的複制分别加以讨論

注意:既然是同一台機器内部複制,那就需考慮為duplicated 資料庫的控制檔案、資料檔案、日志檔案尋找新的存儲位置。而兩台機器間的複制如果為了省事,可以嘗試保持和源資料相同的目錄結果,或者通過參數設定指定新的存儲位置。

具體過程以linux平台為例如下:

一 同台機器内部的複制

1 在源資料庫上生成一個pfile

SQL> create pfile from spfile;

File created.

2 拷貝源庫的pfile 為目标庫pfile

[oracle@oracle dbs]$ ls -lt

total 12084

-rw-r--r-- 1 oracle oinstall 920 Aug 24 00:54 initCRM.ora

-rw-r----- 1 oracle oinstall 2560 Aug 24 00:52 spfileCRM.ora

-rw-r----- 1 oracle oinstall 10076160 Aug 18 20:36 snapcf_CRM.f

-rw-r----- 1 oracle oinstall 1089536 Aug 14 00:04 02oh7u0i_1_1

-rw-r----- 1 oracle oinstall 1163264 Aug 14 00:04 01oh7u06_1_1

-rw-r----- 1 oracle oinstall 24 Aug 20 2012 lkCRM

-rw-rw---- 1 oracle oinstall 1544 Aug 20 2012 hc_CRM.dat

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

[oracle@oracle dbs]$ cp initCRM.ora initCRMTEST.ora

3 更改initCRMTEST.ora 相關參數

源庫資料檔案和日志檔案的位置如下:

SQL> select name from v$datafile;

NAME

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

/oracle/CRM2/system01.dbf

/oracle/CRM2/sysaux01.dbf

/oracle/CRM2/zx.dbf

/oracle/CRM2/users01.dbf

/oracle/CRM2/pos.dbf

/oracle/CRM2/erp.dbf

/oracle/CRM2/user01.dbf

/oracle/CRM2/undotbs03.dbf

SQL> select group#,member from v$logfile;

GROUP# MEMBER

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

4 /oracle/CRM2/redo02.dbf

3 /oracle/CRM2/redo03.log

2 /oracle/CRM2/redo02.log

1 /oracle/CRM2/redo01.log

現打算讓目标庫的資料檔案和日志檔案位于/oracle/CRM/下,是以增加下面兩個參數

*.db_file_name_convert=('CRM2','CRM')

*.log_file_name_convert=('CRM2','CRM')

更改前:

CRM.__db_cache_size=268435456

CRM.__java_pool_size=16777216

CRM.__large_pool_size=16777216

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

CRM.__pga_aggregate_target=503316480

CRM.__sga_target=754974720

CRM.__shared_io_pool_size=0

CRM.__shared_pool_size=402653184

CRM.__streams_pool_size=33554432

*.audit_file_dest='/oracle/app/admin/CRM/adump'

*.audit_trail='db'

*.compatible='11.2.0.0.0'

*.control_files='/oracle/CRM2/control01.ctl','/oracle/CRM2/control02.ctl'#Restore Controlfile

*.db_block_size=8192

*.db_cache_size=218103808

*.db_domain=''

*.db_name='CRM'

*.diagnostic_dest='/oracle/app'

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

*.log_archive_dest_1='LOCATION=/oracle/archive'

*.log_archive_dest_2=''

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

*.memory_target=1258291200

*.open_cursors=300

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.undo_retention=1200

*.undo_tablespace='UNDOTBS3'

更改後:

CRMTEST.__db_cache_size=268435456

CRMTEST.__java_pool_size=16777216

CRMTEST.__large_pool_size=16777216

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

CRMTEST.__pga_aggregate_target=503316480

CRMTEST.__sga_target=754974720

CRMTEST.__shared_io_pool_size=0

CRMTEST.__shared_pool_size=402653184

CRMTEST.__streams_pool_size=33554432

*.audit_file_dest='/oracle/app/admin/CRMTEST/adump'

*.control_files='/oracle/CRM/control01.ctl','/oracle/CRM/control02.ctl'#Restore Controlfile

*.db_name='CRMTEST'

*.log_archive_dest_1='LOCATION=/oracle/archivedest'

4 生成目标資料庫的spfile

[oracle@oracle dbs]$ export ORACLE_SID=CRMTEST

[oracle@oracle dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Sat Aug 24 01:12:02 2013

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

Connected to an idle instance.

SQL> startup nomount

ORACLE instance started.

Total System Global Area 1252663296 bytes

Fixed Size 2226072 bytes

Variable Size 973080680 bytes

Database Buffers 268435456 bytes

Redo Buffers 8921088 bytes

SQL> create spfile from pfile;

5 為目标資料庫建立密碼檔案

orapwd file="$ORACLE_HOME/dbs/orapw$ORACLE_SID" password=DHHZDHHZ

6 建立監聽和服務名

[oracle@oracle admin]$ cat tnsnames.ora

# tnsnames.ora Network Configuration File: /oracle/app/db1/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

CRMTEST =

(DESCRIPTION =

(ADDRESS_LIST =

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

)

(CONNECT_DATA =

(SERVICE_NAME = CRMTEST)

[oracle@oracle admin]$ cat listener.ora

# listener.ora Network Configuration File: /oracle/app/db1/network/admin/listener.ora

SID_LIST_CRMTEST =

(SID_LIST =

(SID_DESC =

(GLOBAL_DBNAME = CRMTEST)

(ORACLE_HOME = /oracle/app/db1)

(SID_NAME = CRMTEST)

ADR_BASE_CRMTEST = /oracle/app

7 備份源資料庫

[oracle@oracle admin]$ export ORACLE_SID=CRM

[oracle@oracle admin]$ rman target / auxiliary sys/DHHZDHHZ@crmtest

Recovery Manager: Release 11.2.0.2.0 - Production on Sat Aug 24 01:42:09 2013

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

connected to target database: CRM (DBID=3599153036)

connected to auxiliary database: CRMTEST (not mounted)

RMAN> backup database plus archivelog ;

Starting backup at 24-AUG-13

current log archived

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=198 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=18 RECID=18 STAMP=793650148

input archived log thread=1 sequence=19 RECID=19 STAMP=793747749

input archived log thread=1 sequence=20 RECID=20 STAMP=793748109

input archived log thread=1 sequence=21 RECID=21 STAMP=793748692

input archived log thread=1 sequence=22 RECID=22 STAMP=793749134

input archived log thread=1 sequence=23 RECID=23 STAMP=797025034

input archived log thread=1 sequence=24 RECID=24 STAMP=823376059

input archived log thread=1 sequence=25 RECID=38 STAMP=823810820

input archived log thread=1 sequence=26 RECID=39 STAMP=823810823

input archived log thread=1 sequence=27 RECID=40 STAMP=823810824

input archived log thread=1 sequence=28 RECID=41 STAMP=823810824

channel ORA_DISK_1: starting piece 1 at 24-AUG-13

channel ORA_DISK_1: finished piece 1 at 24-AUG-13

piece handle=/backup/0foi2fh2_1_1 tag=TAG20130824T014257 comment=NONE

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

input archived log thread=1 sequence=1 RECID=42 STAMP=823811506

input archived log thread=1 sequence=2 RECID=43 STAMP=823811507

input archived log thread=1 sequence=3 RECID=44 STAMP=823811508

input archived log thread=1 sequence=4 RECID=45 STAMP=823811510

input archived log thread=1 sequence=5 RECID=46 STAMP=823811511

input archived log thread=1 sequence=6 RECID=47 STAMP=823811512

input archived log thread=1 sequence=7 RECID=48 STAMP=823811513

input archived log thread=1 sequence=8 RECID=49 STAMP=824149793

input archived log thread=1 sequence=9 RECID=50 STAMP=824239486

input archived log thread=1 sequence=10 RECID=51 STAMP=824259130

input archived log thread=1 sequence=11 RECID=52 STAMP=824262175

piece handle=/backup/0goi2fha_1_1 tag=TAG20130824T014257 comment=NONE

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

Finished backup at 24-AUG-13

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=00004 name=/oracle/CRM2/users01.dbf

input datafile file number=00001 name=/oracle/CRM2/system01.dbf

input datafile file number=00002 name=/oracle/CRM2/sysaux01.dbf

input datafile file number=00005 name=/oracle/CRM2/pos.dbf

input datafile file number=00006 name=/oracle/CRM2/erp.dbf

input datafile file number=00008 name=/oracle/CRM2/undotbs03.dbf

input datafile file number=00003 name=/oracle/CRM2/zx.dbf

input datafile file number=00007 name=/oracle/CRM2/user01.dbf

piece handle=/backup/0hoi2fhj_1_1 tag=TAG20130824T014315 comment=NONE

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

input archived log thread=1 sequence=12 RECID=53 STAMP=824262391

piece handle=/backup/0ioi2fno_1_1 tag=TAG20130824T014632 comment=NONE

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

Starting Control File and SPFILE Autobackup at 24-AUG-13

piece handle=/backup/c-3599153036-20130824-00 comment=NONE

Finished Control File and SPFILE Autobackup at 24-AUG-13

8 複制源資料庫

RMAN> duplicate target database to CRMTEST;

Starting Duplicate Db at 24-AUG-13

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=129 device type=DISK

contents of Memory Script:

{

sql clone "create spfile from memory";

}

executing Memory Script

sql statement: create spfile from memory

shutdown clone immediate;

startup clone nomount;

Oracle instance shut down

connected to auxiliary database (not started)

Oracle instance started

Variable Size 989857896 bytes

Database Buffers 251658240 bytes

sql clone "alter system set db_name =

''CRM'' comment=

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

sql clone "alter system set db_unique_name =

''CRMTEST'' comment=

startup clone force nomount

restore clone primary controlfile;

alter clone database mount;

sql statement: alter system set db_name = ''CRM'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set db_unique_name = ''CRMTEST'' comment= ''Modified by RMAN duplicate'' scope=spfile

Starting restore at 24-AUG-13

channel ORA_AUX_DISK_1: SID=5 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 /backup/c-3599153036-20130824-00

channel ORA_AUX_DISK_1: piece handle=/backup/c-3599153036-20130824-00 tag=TAG20130824T014634

channel ORA_AUX_DISK_1: restored backup piece 1

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

output file name=/oracle/CRM/control01.ctl

output file name=/oracle/CRM/control02.ctl

Finished restore at 24-AUG-13

database mounted

set until scn 2865034;

set newname for datafile 1 to

"/oracle/CRM/system01.dbf";

set newname for datafile 2 to

"/oracle/CRM/sysaux01.dbf";

set newname for datafile 3 to

"/oracle/CRM/zx.dbf";

set newname for datafile 4 to

"/oracle/CRM/users01.dbf";

set newname for datafile 5 to

"/oracle/CRM/pos.dbf";

set newname for datafile 6 to

"/oracle/CRM/erp.dbf";

set newname for datafile 7 to

"/oracle/CRM/user01.dbf";

set newname for datafile 8 to

"/oracle/CRM/undotbs03.dbf";

restore

clone database

;

executing command: SET until clause

executing command: SET NEWNAME

using channel ORA_AUX_DISK_1

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

channel ORA_AUX_DISK_1: restoring datafile 00001 to /oracle/CRM/system01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00002 to /oracle/CRM/sysaux01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00003 to /oracle/CRM/zx.dbf

channel ORA_AUX_DISK_1: restoring datafile 00004 to /oracle/CRM/users01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00005 to /oracle/CRM/pos.dbf

channel ORA_AUX_DISK_1: restoring datafile 00006 to /oracle/CRM/erp.dbf

channel ORA_AUX_DISK_1: restoring datafile 00007 to /oracle/CRM/user01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00008 to /oracle/CRM/undotbs03.dbf

channel ORA_AUX_DISK_1: reading from backup piece /backup/0hoi2fhj_1_1

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

switch clone datafile all;

datafile 1 switched to datafile copy

input datafile copy RECID=9 STAMP=824262833 file name=/oracle/CRM/system01.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=10 STAMP=824262833 file name=/oracle/CRM/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=11 STAMP=824262833 file name=/oracle/CRM/zx.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=12 STAMP=824262833 file name=/oracle/CRM/users01.dbf

datafile 5 switched to datafile copy

input datafile copy RECID=13 STAMP=824262833 file name=/oracle/CRM/pos.dbf

datafile 6 switched to datafile copy

input datafile copy RECID=14 STAMP=824262833 file name=/oracle/CRM/erp.dbf

datafile 7 switched to datafile copy

input datafile copy RECID=15 STAMP=824262833 file name=/oracle/CRM/user01.dbf

datafile 8 switched to datafile copy

input datafile copy RECID=16 STAMP=824262834 file name=/oracle/CRM/undotbs03.dbf

recover

delete archivelog

Starting recover at 24-AUG-13

starting media recovery

archived log for thread 1 with sequence 12 is already on disk as file /oracle/archive/1_12_823810820.dbf

archived log file name=/oracle/archive/1_12_823810820.dbf thread=1 sequence=12

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

Finished recover at 24-AUG-13

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

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

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

sql statement: alter system reset db_unique_name scope=spfile

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

MAXLOGFILES 16

MAXLOGMEMBERS 3

MAXDATAFILES 100

MAXINSTANCES 8

MAXLOGHISTORY 292

LOGFILE

GROUP 1 ( '/oracle/CRM/redo01.log' ) SIZE 200 M REUSE,

GROUP 2 ( '/oracle/CRM/redo02.log' ) SIZE 200 M REUSE,

GROUP 3 ( '/oracle/CRM/redo03.log' ) SIZE 200 M REUSE,

GROUP 4 ( '/oracle/CRM/redo02.dbf' ) SIZE 200 M REUSE

DATAFILE

'/oracle/CRM/system01.dbf'

CHARACTER SET ZHS16GBK

catalog clone datafilecopy "/oracle/CRM/sysaux01.dbf",

"/oracle/CRM/zx.dbf",

"/oracle/CRM/users01.dbf",

"/oracle/CRM/pos.dbf",

"/oracle/CRM/erp.dbf",

"/oracle/CRM/user01.dbf",

cataloged datafile copy

datafile copy file name=/oracle/CRM/sysaux01.dbf RECID=1 STAMP=824262915

datafile copy file name=/oracle/CRM/zx.dbf RECID=2 STAMP=824262915

datafile copy file name=/oracle/CRM/users01.dbf RECID=3 STAMP=824262916

datafile copy file name=/oracle/CRM/pos.dbf RECID=4 STAMP=824262916

datafile copy file name=/oracle/CRM/erp.dbf RECID=5 STAMP=824262916

datafile copy file name=/oracle/CRM/user01.dbf RECID=6 STAMP=824262916

datafile copy file name=/oracle/CRM/undotbs03.dbf RECID=7 STAMP=824262916

input datafile copy RECID=1 STAMP=824262915 file name=/oracle/CRM/sysaux01.dbf

input datafile copy RECID=2 STAMP=824262915 file name=/oracle/CRM/zx.dbf

input datafile copy RECID=3 STAMP=824262916 file name=/oracle/CRM/users01.dbf

input datafile copy RECID=4 STAMP=824262916 file name=/oracle/CRM/pos.dbf

input datafile copy RECID=5 STAMP=824262916 file name=/oracle/CRM/erp.dbf

input datafile copy RECID=6 STAMP=824262916 file name=/oracle/CRM/user01.dbf

input datafile copy RECID=7 STAMP=824262916 file name=/oracle/CRM/undotbs03.dbf

Alter clone database open resetlogs;

database opened

Finished Duplicate Db at 24-AUG-13

RMAN>

------------------------同台機器内複制資料庫完---------------------------------

二 兩台機器間的複制

1 在源庫生成pfile檔案

SQL> host;

[oracle@zx ~]$ ls -lt /oracle/app/db1/dbs

total 12100

-rw-r--r-- 1 oracle oinstall 920 Aug 24 21:31 initCRM.ora

-rw-r----- 1 oracle oinstall 2560 Aug 24 20:18 spfileCRM.ora

-rw-r----- 1 oracle oinstall 10076160 Aug 24 01:46 snapcf_CRM.f

-rw-r----- 1 oracle oinstall 1536 Aug 24 01:31 orapwCRMTEST

-rw-r--r-- 1 oracle oinstall 1043 Aug 24 01:21 initCRMTEST.ora

-rw-r----- 1 oracle oinstall 24 Aug 24 01:18 lkCRMTEST

-rw-rw---- 1 oracle oinstall 1544 Aug 24 01:12 hc_CRMTEST.dat

2 在源庫上修改生成的spfile

注意由于源庫和目标oracle具有相同的目錄結構是以對參數檔案不做任何修改保持原樣

不過在複制語句中要加入nofilenamecheck參數防止複制操作在還原前檢查檔案名是否相同

如下為參數檔案内容:

[oracle@zx ~]$ cat $ORACLE_HOME/dbs/initCRM.ora

*.audit_file_dest='/oracle/app/admin/CRM/adump' 注意:該參數目錄需在目标資料庫上建立 mkdir -p /oracle/app/admin/CRM/adump

注意:如果需要更改資料檔案和日志檔案的路徑則需加入下兩個參數進行調整

*.db_file_name_convert=()

*.log_file_name_convert=()

3 在源資料庫伺服器上備份資料庫

RMAN> backup database plus archivelog;

channel ORA_DISK_1: SID=13 device type=DISK

piece handle=/backup/0koi4s2k_1_1 tag=TAG20130824T232923 comment=NONE

input archived log thread=1 sequence=13 RECID=54 STAMP=824329097

input archived log thread=1 sequence=14 RECID=55 STAMP=824340560

piece handle=/backup/0loi4s2s_1_1 tag=TAG20130824T232923 comment=NONE

piece handle=/backup/0moi4s34_1_1 tag=TAG20130824T232939 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:03:35

input archived log thread=1 sequence=15 RECID=56 STAMP=824340796

piece handle=/backup/0noi4s9t_1_1 tag=TAG20130824T233316 comment=NONE

piece handle=/backup/c-3599153036-20130824-01 comment=NONE

Finished Control File and SPFILE Autobackup at 24-AUG-1

4 拷貝源庫參數檔案到目标資料庫dbs目錄下

在源庫上拷貝參數檔案到目标資料庫dbs目錄下

[root@zx ~]# scp /oracle/app/db1/dbs/initCRM.ora [email protected]:/oracle/app/db1/dbs/

[email protected]'s password:

initCRM.ora 100% 920 0.9KB/s 00:00

[root@zx ~]#

在目标資料庫伺服器上更改該參數檔案屬主

[root@oracle dbs]# ls -lt

total 12

-rw-r--r-- 1 root root 920 Aug 24 23:40 initCRM.ora

-rw-r----- 1 oracle oinstall 1536 Aug 24 23:25 orapwCRM

-rw-rw---- 1 oracle oinstall 1544 Aug 24 20:02 hc_CRM.dat

[root@oracle dbs]# chown oracle:oinstall initCRM.ora

-rw-r--r-- 1 oracle oinstall 920 Aug 24 23:40 initCRM.ora

在目标庫上生成spfile檔案

[oracle@dest ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Sun Aug 25 00:17:58 2013

SQL> startup nomount;

5 拷貝源庫備份到目标庫同目錄下

要拷貝的檔案為:

piece handle=/backup/0koi4s2k_1_1

piece handle=/backup/0loi4s2s_1_1

piece handle=/backup/0moi4s34_1_1

piece handle=/backup/0noi4s9t_1_1

piece handle=/backup/c-3599153036-20130824-01

在源伺服器上拷貝過程如下:

-rw-r----- 1 oracle oinstall 20393472 Aug 28 2012 05njqj9f_1_1

[root@zx backup]# scp ./c-3599153036-20130824-01 [email protected]:/backup/

c-3599153036-20130824-01 100% 9920KB 9.7MB/s 00:01

[root@zx backup]# scp ./0noi4s9t_1_1 [email protected]:/backup/

0noi4s9t_1_1 100% 8192 8.0KB/s 00:00

[root@zx backup]# scp ./0moi4s34_1_1 [email protected]:/backup/

0moi4s34_1_1 100% 2152MB 7.7MB/s 04:41

[root@zx backup]# scp ./0loi4s2s_1_1 [email protected]:/backup/

0loi4s2s_1_1 100% 33MB 11.0MB/s 00:03

[root@zx backup]# scp ./0koi4s2k_1_1 [email protected]:/backup/

0koi4s2k_1_1 100% 39MB 7.7MB/s 00:05

在目标資料庫所在的伺服器上更改檔案屬主

[root@oracle backup]# ls -lt

total 9482452

-rw-r----- 1 root root 40567808 Aug 24 23:53 0koi4s2k_1_1

-rw-r----- 1 root root 34523136 Aug 24 23:52 0loi4s2s_1_1

-rw-r----- 1 root root 2256723968 Aug 24 23:51 0moi4s34_1_1

-rw-r----- 1 root root 8192 Aug 24 23:46 0noi4s9t_1_1

-rw-r----- 1 root root 10158080 Aug 24 23:45 c-3599153036-20130824-01

[root@oracle backup]# chown oracle:oinstall c-3599153036-20130824-01

[root@oracle backup]# chown oracle:oinstall 0noi4s9t_1_1

[root@oracle backup]# chown oracle:oinstall 0moi4s34_1_1

[root@oracle backup]# chown oracle:oinstall 0loi4s2s_1_1

[root@oracle backup]# chown oracle:oinstall 0koi4s2k_1_1

-rw-r----- 1 oracle oinstall 40567808 Aug 24 23:53 0koi4s2k_1_1

-rw-r----- 1 oracle oinstall 34523136 Aug 24 23:52 0loi4s2s_1_1

-rw-r----- 1 oracle oinstall 2256723968 Aug 24 23:51 0moi4s34_1_1

-rw-r----- 1 oracle oinstall 8192 Aug 24 23:46 0noi4s9t_1_1

-rw-r----- 1 oracle oinstall 10158080 Aug 24 23:45 c-3599153036-20130824-01

6 在目标資料庫伺服器上建立密碼檔案

7 在目标資料庫上建立監聽并啟動

[root@dest admin]# cat listener.ora

CRM =

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

SID_LIST_CRM =

(GLOBAL_DBNAME = CRM)

(SID_NAME = CRM)

ADR_BASE_CRM = /oracle/app

啟動監聽

LSNRCTL> start crm

Starting /oracle/app/db1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.2.0 - Production

System parameter file is /oracle/app/db1/network/admin/listener.ora

Log messages written to /oracle/app/diag/tnslsnr/dest/crm/alert/log.xml

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.5.10)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.5.10)(PORT=1521)))

STATUS of the LISTENER

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

Alias crm

Version TNSLSNR for Linux: Version 11.2.0.2.0 - Production

Start Date 25-AUG-2013 00:34:23

Uptime 0 days 0 hr. 0 min. 1 sec

Trace Level off

Security ON: Local OS Authentication

SNMP OFF

Listener Parameter File /oracle/app/db1/network/admin/listener.ora

Listener Log File /oracle/app/diag/tnslsnr/dest/crm/alert/log.xml

Listening Endpoints Summary...

(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.5.10)(PORT=1521)))

Services Summary...

Service "CRM" has 1 instance(s).

Instance "CRM", status UNKNOWN, has 1 handler(s) for this service...

The command completed successfully

8 在源庫上建立連接配接目标庫的服務名

[root@zx admin]# cat tnsnames.ora

(SERVICE_NAME = CRM)

9 複制資料庫過程

[oracle@zx ~]$ rman target / auxiliary sys/DHHZDHHZ@crm

Recovery Manager: Release 11.2.0.2.0 - Production on Sun Aug 25 00:35:52 2013

connected to auxiliary database: CRM (not mounted)

RMAN> duplicate target database to crm nofilenamecheck;

Starting Duplicate Db at 25-AUG-13

channel ORA_AUX_DISK_1: SID=63 device type=DISK

sql statement: alter system set db_unique_name = ''CRM'' comment= ''Modified by RMAN duplicate'' scope=spfile

Starting restore at 25-AUG-13

channel ORA_AUX_DISK_1: reading from backup piece /backup/c-3599153036-20130824-01

channel ORA_AUX_DISK_1: piece handle=/backup/c-3599153036-20130824-01 tag=TAG20130824T233319

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

output file name=/oracle/CRM2/control01.ctl

output file name=/oracle/CRM2/control02.ctl

Finished restore at 25-AUG-13

set until scn 2892348;

"/oracle/CRM2/system01.dbf";

"/oracle/CRM2/sysaux01.dbf";

"/oracle/CRM2/zx.dbf";

"/oracle/CRM2/users01.dbf";

"/oracle/CRM2/pos.dbf";

"/oracle/CRM2/erp.dbf";

"/oracle/CRM2/user01.dbf";

"/oracle/CRM2/undotbs03.dbf";

channel ORA_AUX_DISK_1: restoring datafile 00001 to /oracle/CRM2/system01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00002 to /oracle/CRM2/sysaux01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00003 to /oracle/CRM2/zx.dbf

channel ORA_AUX_DISK_1: restoring datafile 00004 to /oracle/CRM2/users01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00005 to /oracle/CRM2/pos.dbf

channel ORA_AUX_DISK_1: restoring datafile 00006 to /oracle/CRM2/erp.dbf

channel ORA_AUX_DISK_1: restoring datafile 00007 to /oracle/CRM2/user01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00008 to /oracle/CRM2/undotbs03.dbf

channel ORA_AUX_DISK_1: reading from backup piece /backup/0moi4s34_1_1

channel ORA_AUX_DISK_1: piece handle=/backup/0moi4s34_1_1 tag=TAG20130824T232939

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:02:15

input datafile copy RECID=1 STAMP=824344808 file name=/oracle/CRM2/system01.dbf

input datafile copy RECID=2 STAMP=824344809 file name=/oracle/CRM2/sysaux01.dbf

input datafile copy RECID=3 STAMP=824344809 file name=/oracle/CRM2/zx.dbf

input datafile copy RECID=4 STAMP=824344809 file name=/oracle/CRM2/users01.dbf

input datafile copy RECID=5 STAMP=824344809 file name=/oracle/CRM2/pos.dbf

input datafile copy RECID=6 STAMP=824344809 file name=/oracle/CRM2/erp.dbf

input datafile copy RECID=7 STAMP=824344809 file name=/oracle/CRM2/user01.dbf

input datafile copy RECID=8 STAMP=824344809 file name=/oracle/CRM2/undotbs03.dbf

Starting recover at 25-AUG-13

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=15

channel ORA_AUX_DISK_1: reading from backup piece /backup/0noi4s9t_1_1

channel ORA_AUX_DISK_1: piece handle=/backup/0noi4s9t_1_1 tag=TAG20130824T233316

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

archived log file name=/oracle/archive/1_15_823810820.dbf thread=1 sequence=15

channel clone_default: deleting archived log(s)

archived log file name=/oracle/archive/1_15_823810820.dbf RECID=57 STAMP=824344817

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

Finished recover at 25-AUG-13

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

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

GROUP 1 ( '/oracle/CRM2/redo01.log' ) SIZE 200 M REUSE,

GROUP 2 ( '/oracle/CRM2/redo02.log' ) SIZE 200 M REUSE,

GROUP 3 ( '/oracle/CRM2/redo03.log' ) SIZE 200 M REUSE,

GROUP 4 ( '/oracle/CRM2/redo02.dbf' ) SIZE 200 M REUSE

'/oracle/CRM2/system01.dbf'

catalog clone datafilecopy "/oracle/CRM2/sysaux01.dbf",

"/oracle/CRM2/zx.dbf",

"/oracle/CRM2/users01.dbf",

"/oracle/CRM2/pos.dbf",

"/oracle/CRM2/erp.dbf",

"/oracle/CRM2/user01.dbf",

datafile copy file name=/oracle/CRM2/sysaux01.dbf RECID=1 STAMP=824344852

datafile copy file name=/oracle/CRM2/zx.dbf RECID=2 STAMP=824344852

datafile copy file name=/oracle/CRM2/users01.dbf RECID=3 STAMP=824344852

datafile copy file name=/oracle/CRM2/pos.dbf RECID=4 STAMP=824344852

datafile copy file name=/oracle/CRM2/erp.dbf RECID=5 STAMP=824344852

datafile copy file name=/oracle/CRM2/user01.dbf RECID=6 STAMP=824344852

datafile copy file name=/oracle/CRM2/undotbs03.dbf RECID=7 STAMP=824344852

input datafile copy RECID=1 STAMP=824344852 file name=/oracle/CRM2/sysaux01.dbf

input datafile copy RECID=2 STAMP=824344852 file name=/oracle/CRM2/zx.dbf

input datafile copy RECID=3 STAMP=824344852 file name=/oracle/CRM2/users01.dbf

input datafile copy RECID=4 STAMP=824344852 file name=/oracle/CRM2/pos.dbf

input datafile copy RECID=5 STAMP=824344852 file name=/oracle/CRM2/erp.dbf

input datafile copy RECID=6 STAMP=824344852 file name=/oracle/CRM2/user01.dbf

input datafile copy RECID=7 STAMP=824344852 file name=/oracle/CRM2/undotbs03.dbf

Finished Duplicate Db at 25-AUG-13

本文轉自 zhangxuwl 51CTO部落格,原文連結:http://blog.51cto.com/jiujian/1327815,如需轉載請自行聯系原作者