RMAN 同機複製資料庫

murkey發表於2013-12-18

關於RMAN 複製的理論知識,參考我的Blog:

RMAN 複製目標資料庫的理論知識

http://blog.csdn.net/tianlesoftware/archive/2010/07/19/5746812.aspx

實驗平臺: redhat + oracle 10g

源庫的相關資訊:

ORACLE_BASE: /u01/app/oracle

ORACLE_HOME: /u01/app/oracle/product/10.2.0/db_1

ORACLE_SID:ORCL

複製的資料庫例項名假設為: DAVE

步驟如下:

(1)構建輔助資料庫目錄結構

(2)修改init.ora 初始話檔案

(3)建立輔助例項口令檔案

(4)RMAN 備份源庫

(5)配置監聽

(6)啟動輔助庫至nomount 狀態

(7)RMAN duplicate複製例項

(8)建立spfile

一.構建輔助資料庫目錄結構

1.1 Oracle data 目錄

[oracle@db1 oradata]$ ls

orcl

[oracle@db1 oradata]$ pwd

/u01/app/oracle/oradata

[oracle@db1 oradata]$ mkdir DAVE

[oracle@db1 oradata]$ ls

DAVE orcl

1.2 其他目錄

[oracle@db1 admin]$ pwd

/u01/app/oracle/admin

[oracle@db1 admin]$ mkdir DAVE

[oracle@db1 admin]$ ls

DAVE orcl

[oracle@db1 admin]$ cd orcl

[oracle@db1 orcl]$ ls

adump bdump cdump dpdump pfile udump

[oracle@db1 DAVE]$ cd ..

[oracle@db1 admin]$ cd DAVE

[oracle@db1 DAVE]$ mkdir bdump

[oracle@db1 DAVE]$ mkdir cdump

[oracle@db1 DAVE]$ mkdir pfile

[oracle@db1 DAVE]$ mkdir udump

[oracle@db1 DAVE]$ ls

adump bdump cdump dpdump pfile udump

二.修改init.ora初始化檔案

2.1 生成源庫的pfile 檔案,預設生成位置在$ORACLE_HOME/dbs目錄下:

SQL> conn / as sysdba

Connected.

SQL> create pfile from spfile;

File created.

2.2 進入$ORACLE_HOME/dbs目錄,將init 檔案copy並重新命名為initDAVE.ora.這個命名格式必須和例項名相同,不然資料庫不能識別。

[oracle@db1 DAVE]$ cd $ORACLE_HOME/dbs

[oracle@db1 dbs]$ ls

hc_orcl.dat init.ora lkORCL snapcf_orcl.f

initdw.ora initorcl.ora orapworcl spfileorcl.ora

[oracle@db1 dbs]$ cp initorcl.ora initDAVE.ora

[oracle@db1 dbs]$ ls

hc_orcl.dat initdw.ora initorcl.ora orapworcl spfileorcl.ora

initDAVE.ora init.ora lkORCL snapcf_orcl.f

2.3 修改initDAVE.ora 檔案,將orcl 改成DAVE

[oracle@db1 dbs]$ more initDAVE.ora

orcl.__db_cache_size=171966464

orcl.__java_pool_size=4194304

orcl.__large_pool_size=4194304

orcl.__shared_pool_size=58720256

orcl.__streams_pool_size=0

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

*.background_dump_dest='/u01/app/oracle/admin/DAVE/bdump'

*.compatible='10.2.0.1.0'

*.control_file_record_keep_time=14

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

,'/u01/app/oracle/oradata/DAVE/control03.ctl'

*.core_dump_dest='/u01/app/oracle/admin/DAVE/cdump'

*.db_block_size=8192

*.db_domain=''

*.db_file_multiblock_read_count=16

*.db_name='DAVE'

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

*.db_recovery_file_dest_size=2147483648

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

*.job_queue_processes=10

*.log_archive_dest_1='location=/u01/archivelog'

*.open_cursors=300

*.pga_aggregate_target=81788928

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.sga_target=246415360

*.undo_management='AUTO'

*.undo_tablespace='UNDOTBS1'

*.user_dump_dest='/u01/app/oracle/admin/DAVE/udump'

db_file_name_convert = ('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/DAVE')

log_file_name_convert = ('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/DAVE')

其中紅色部分就是修改的部分. Db_file_name_convert和log_file_name_convert兩個引數是我們新增的,用來轉換資料檔案位置和redo log位置。 在複製完成後,可以刪除這2個引數。

三.建立DAVE例項的口令檔案

[oracle@db1 dbs]$ cd $ORACLE_HOME/bin

[oracle@db1 bin]$ orapwd file=$ORACLE_HOME/dbs/orapwDAVE password=admin

[oracle@db1 bin]$ cd $ORACLE_HOME/dbs

[oracle@db1 dbs]$ ls

hc_orcl.dat initdw.ora initorcl.ora orapwDAVE snapcf_orcl.f

initDAVE.ora init.ora lkORCL orapworcl spfileorcl.ora

windows下oracle預設的位置是$ORACLE_HOME/database目錄,檔名格式是pwdSID.ora。

linux下oracle預設的位置是$ORACLE_HOME/dbs目錄,檔名格式是orapwSID。

建立完後,資料庫需要重啟動,新的口令檔案才能生效。

關於口令檔案建立,詳細內容參考blog:

Oracle OS認證 口令檔案 密碼丟失處理

http://blog.csdn.net/tianlesoftware/archive/2009/10/20/4698293.aspx

四.RMAN 備份源庫(orcl)

[oracle@db1 u02]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Sun Jul 18 10:57:53 2010

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

connected to target database: ORCL (DBID=1248423599)

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;

}

備份指令碼,具體參考:

Linux 平臺下 RMAN 全備 和 增量備份 shell 指令碼

http://blog.csdn.net/tianlesoftware/archive/2010/07/16/5740630.aspx

五.新增,配置監聽

5.1 修改listener.ora 檔案,新增如下內容

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(SID_NAME = PLSExtProc)

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

(PROGRAM = extproc)

)

(SID_DESC =

(GLOBAL_DBNAME = DAVE)

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

(SID_NAME = DAVE)

)

)

5.2 修改tnsnames.ora 檔案,新增如下內容

DAVE=

(DESCRIPTION =

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

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = DAVE)

)

)

建議使用net manager 工具從介面來修改,這樣不容易出錯

Oracle 資料庫監聽配置

http://blog.csdn.net/tianlesoftware/archive/2009/11/25/4861572.aspx

Oracle Listener 動態註冊 與 靜態註冊

http://blog.csdn.net/tianlesoftware/archive/2010/04/30/5543166.aspx

六.啟動輔助庫到nomount狀態

[oracle@db1 admin]$ export ORACLE_SID=DAVE

[oracle@db1 admin]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Sun Jul 18 11:17:01 2010

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

SQL> conn / as sysdba

Connected to an idle instance.

SQL> startup nomount pfile=?/dbs/initDAVE.ora -- 注意要指定pfile

ORACLE instance started.

Total System Global Area 247463936 bytes

Fixed Size 1218748 bytes

Variable Size 79693636 bytes

Database Buffers 159383552 bytes

Redo Buffers 7168000 bytes

SQL>

七.RMAN 連線到目標例項和輔助例項,執行duplicate 命令複製資料庫

[oracle@db1 u02]$ export ORACLE_SID=orcl

[oracle@db1 u02]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Sun Jul 18 11:41:01 2010

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

connected to target database: ORCL (DBID=1248423599)

RMAN> connect auxiliary sys/admin@DAVE;

connected to auxiliary database: DAVE (not mounted)

RMAN> duplicate target database to DAVE;

Starting Duplicate Db at 18-JUL-10

using target database control file instead of recovery catalog -- 用的是原來的控制檔案

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: sid=155 devtype=DISK

contents of Memory Script:

{

set until scn 697286;

set newname for datafile 1 to "/u01/app/oracle/oradata/DAVE/system01.dbf"; -- 轉換檔案位置

set newname for datafile 2 to "/u01/app/oracle/oradata/DAVE/undotbs01.dbf";

set newname for datafile 3 to "/u01/app/oracle/oradata/DAVE/sysaux01.dbf";

set newname for datafile 4 to "/u01/app/oracle/oradata/DAVE/users01.dbf";

set newname for datafile 5 to "/u01/app/oracle/oradata/DAVE/example01.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

Starting restore at 18-JUL-10

using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore -- 開始restore 資料檔案

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

restoring datafile 00002 to /u01/app/oracle/oradata/DAVE/undotbs01.dbf

restoring datafile 00003 to /u01/app/oracle/oradata/DAVE/sysaux01.dbf

restoring datafile 00005 to /u01/app/oracle/oradata/DAVE/example01.dbf

channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/orcl_39lj3bmt_1_1_20100718

channel ORA_AUX_DISK_1: restored backup piece 1

piece handle=/u02/backup/orcl_39lj3bmt_1_1_20100718 tag=ORCL_HOT_DB_BK

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

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/DAVE/system01.dbf

restoring datafile 00004 to /u01/app/oracle/oradata/DAVE/users01.dbf

channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/orcl_38lj3bmt_1_1_20100718

channel ORA_AUX_DISK_1: restored backup piece 1

piece handle=/u02/backup/orcl_38lj3bmt_1_1_20100718 tag=ORCL_HOT_DB_BK

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

Finished restore at 18-JUL-10

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

-- 建立源庫的控制檔案,然後用這個控制檔案進行恢復

MAXLOGFILES 16

MAXLOGMEMBERS 3

MAXDATAFILES 100

MAXINSTANCES 8

MAXLOGHISTORY 292

LOGFILE

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

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

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

DATAFILE

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

CHARACTER SET WE8ISO8859P1

contents of Memory Script:

{

switch clone datafile all;

}

executing Memory Script

released channel: ORA_AUX_DISK_1

datafile 2 switched to datafile copy

input datafile copy recid=1 stamp=724679047 filename=/u01/app/oracle/oradata/DAVE/undotbs01.dbf

datafile 3 switched to datafile copy

input datafile copy recid=2 stamp=724679047 filename=/u01/app/oracle/oradata/DAVE/sysaux01.dbf

datafile 4 switched to datafile copy

input datafile copy recid=3 stamp=724679047 filename=/u01/app/oracle/oradata/DAVE/users01.dbf

datafile 5 switched to datafile copy

input datafile copy recid=4 stamp=724679047 filename=/u01/app/oracle/oradata/DAVE/example01.dbf

contents of Memory Script:

{

set until scn 697286;

recover

clone database

delete archivelog

;

}

executing Memory Script

executing command: SET until clause

Starting recover at 18-JUL-10 -- 開始recover 恢復資料

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: sid=155 devtype=DISK

starting media recovery

channel ORA_AUX_DISK_1: starting archive log restore to default destination

-- 先將歸檔日誌還原到指定的歸檔目錄: log_archive_dest 引數指定

channel ORA_AUX_DISK_1: restoring archive log

archive log thread=1 sequence=41

channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/arch_3dlj3bro_1_1_20100718

channel ORA_AUX_DISK_1: restored backup piece 1

piece handle=/u02/backup/arch_3dlj3bro_1_1_20100718 tag=TAG20100718T110111

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

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

channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/arch_3clj3bro_1_1_20100718

channel ORA_AUX_DISK_1: restored backup piece 1

piece handle=/u02/backup/arch_3clj3bro_1_1_20100718 tag=TAG20100718T110111

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

archive log filename=/u01/archivelog/1_40_720642866.dbf thread=1 sequence=40

channel clone_default: deleting archive log(s)

archive log filename=/u01/archivelog/1_40_720642866.dbf recid=2 stamp=724679053

archive log filename=/u01/archivelog/1_41_720642866.dbf thread=1 sequence=41

channel clone_default: deleting archive log(s)

archive log filename=/u01/archivelog/1_41_720642866.dbf recid=1 stamp=724679052

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

Finished recover at 18-JUL-10

contents of Memory Script:

{

shutdown clone;

startup clone nomount ;

-- 這裡要注意的一個地方,在這一步的時候,輔助例項不能有任何session開啟,即不能有有任何連線連線到DAVE上,不然它會一直那個session 退出後才能執行

}

executing Memory Script

database dismounted

Oracle instance shut down

connected to auxiliary database (not started)

Oracle instance started

Total System Global Area 247463936 bytes

Fixed Size 1218748 bytes

Variable Size 79693636 bytes

Database Buffers 159383552 bytes

Redo Buffers 7168000 bytes

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

--複製已經完成,建立新的控制檔案(DAVE的控制檔案),可以參考理論知識的連線

MAXLOGFILES 16

MAXLOGMEMBERS 3

MAXDATAFILES 100

MAXINSTANCES 8

MAXLOGHISTORY 292

LOGFILE

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

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

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

DATAFILE

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

CHARACTER SET WE8ISO8859P1

contents of Memory Script:

{

set newname for tempfile 1 to "/u01/app/oracle/oradata/DAVE/temp01.dbf";

switch clone tempfile all;

catalog clone datafilecopy "/u01/app/oracle/oradata/DAVE/undotbs01.dbf";

catalog clone datafilecopy "/u01/app/oracle/oradata/DAVE/sysaux01.dbf";

catalog clone datafilecopy "/u01/app/oracle/oradata/DAVE/users01.dbf";

catalog clone datafilecopy "/u01/app/oracle/oradata/DAVE/example01.dbf";

switch clone datafile all;

}

executing Memory Script

executing command: SET NEWNAME

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

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

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

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

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

datafile 2 switched to datafile copy

input datafile copy recid=1 stamp=724679599 filename=/u01/app/oracle/oradata/DAVE/undotbs01.dbf

datafile 3 switched to datafile copy

input datafile copy recid=2 stamp=724679599 filename=/u01/app/oracle/oradata/DAVE/sysaux01.dbf

datafile 4 switched to datafile copy

input datafile copy recid=3 stamp=724679599 filename=/u01/app/oracle/oradata/DAVE/users01.dbf

datafile 5 switched to datafile copy

input datafile copy recid=4 stamp=724679599 filename=/u01/app/oracle/oradata/DAVE/example01.dbf

contents of Memory Script:

{

Alter clone database open resetlogs;

}

executing Memory Script

database opened

Finished Duplicate Db at 18-JUL-10

八.修改輔助庫的pfile,在建立spfile

8.1刪除下面2句:

db_file_name_convert = ('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/DAVE')

log_file_name_convert = ('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/DAVE')

8.2 建立spfile

[oracle@db1 dbs]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Sun Jul 18 12:11:28 2010

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

SQL> conn sys/admin@DAVE as sysdba;

Connected.

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

File created.

九.如果使用磁帶備份

完成了上面的8步,RMAN的同機複製就已經完成了。 如果要在相同的伺服器上覆制磁帶備份,只需要在最後執行duplicate命令前插入一個額外的步驟即可。 該步驟配置輔助通道,使之與執行備份的通道型別。

9.1 先在源庫上執行show channel命令,檢視通道資訊

9.2 然後在建立相應的configure命令來匹配輔助的通道

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

相關文章