taget database | auxiliary database | |
作業系統 | RHEL 5 update 8 X86_64 | RHEL 5 update 8 X86_64 |
主機名 | oraedu | oraedu1 |
IP位址/子網路遮罩 | 192.168.127.11/24 | 192.168.127.12/24 |
/etc/hosts | 127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 192.168.127.11 oraedu 192.168.127.12 oraedu1 | 127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 192.168.127.12 oraedu1 192.168.127.11 oraedu |
~/.bash_porfile | if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin EDITOR=vi export PATH EDITOR ORACLE_BASE=/u01/app/oracle ORACLE_SID=orcl export ORACLE_BASE ORACLE_SID ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1 export ORACLE_HOME PATH=$ORACLE_HOME/bin:$PATH export PATH | if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin EDITOR=vi export PATH EDITOR ORACLE_BASE=/u01/app/oracle ORACLE_SID=orclb export ORACLE_BASE ORACLE_SID ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1 export ORACLE_HOME PATH=$ORACLE_HOME/bin:$PATH export PATH |
安裝oracle軟體的使用者 | oracle | oracle |
Oracle軟體版本 | oracle 10g 10.2.0.1.0 X86_64 | oracle 10g 10.2.0.1.0 X86_64 |
$ORACLE_BASE | /u01/app/oracle/ | /u01/app/oracle/ |
$ORACLE_HOME | /u01/app/oracle/product/10.2.0/db_1/ | /u01/app/oracle/product/10.2.0/db_1/ |
$ORACLE_SID | orcl | orclb |
lisntener.o | SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1) (PROGRAM = extproc) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oraedu)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0)) ) ) | #這裡要用靜态注冊的方式,否則oraedu無法連接配接此偵聽,不用靜态注冊也可以成功(2012-10-31修改) SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_NAME = orclb) (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1) (SID_NAME = orclb) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oraedu1)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0)) ) ) |
tnsnames.ora | EXTPROC_CONNECTION_DATA = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0)) ) (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO) ) ) ORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oraedu)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) ) ORCLB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oraedu1)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orclb) (UR=A) ) ) #一定要在連接配接orclb的服務描述符中加上(UR=A),否則RMAN連接配接orclb不是"not mounted"狀态,而是"not started"狀态,auxiliary database是"not started"狀态執行duplicate是無法成功的。 Note: The (UR=A) clause in tnsnames.ora is intended to work with a dynamically registered handler so the use of SERVICE_NAME versus SID is preferred. (ID 362656.1) | EXTPROC_CONNECTION_DATA = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0)) ) (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO) ) ) ORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oraedu)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) ) ORCLB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oraedu1)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orclb) (UR=A) ) ) |
表格 1
本實驗示範RMAN的DUPLICATE功能,複制targetdatabase到auxiliary database中。target database已經open,并且處于歸檔模式,auxiliary database已安裝Oracle軟體,并未安裝資料庫。我們需要為auxiliary database配置參數檔案,然後啟動執行個體,再利用RMAN的DUPLICATE把target database的資料庫完整備份複制到auxiliary database上,并啟動auxiliary database。實驗目的是為了建立一個和targetdatabase幾乎一緻的資料庫副本,因為auxiliary database隻能與target database的某個時間點相同。
本實驗隻示範異機不同路徑的複制,除此之外還有異機相同路徑複制和本地建立DUPLICATE。
為完成本次實驗需要兩台機器,兩台機器的主機和oracle相關設定見表格1,oraedu是target database,已經安裝oracle資料庫,并且處于open狀态,oraedu1是auxiliary database,已安裝oracle軟體,沒有安裝oracle資料庫,沒有啟動執行個體。以下是實驗步驟,在實驗前要確定已按照表格中的内容做相關設定:
步驟一、建立orclb執行個體的參數檔案
1、oraedu主機的orcl資料庫是用spfile檔案啟動執行個體,我們可以利用spfile建立pfile,并複制pfile到oraedu1主機。
登入oraedu主機:
[[email protected] ~]$ sqlplus / as sysdba
[email protected]>select status from v$instance;
STATUS
------------
OPEN
[email protected]>select dbid,name,log_mode fromv$database;
DBID NAME LOG_MODE
------------------- --------- ---------
1320402727 ORCL ARCHIVELOG
[email protected]>create pfile from spfile;
File created.
[email protected]>exit
[[email protected] ~]$scp $ORACLE_HOME/dbs/initorcl.ora orac[email protected]:/u01/app/oracle/product/10.2.0/db_1/dbs/initorclb.ora
2、修改參數檔案
登入oraedu1主機:
[[email protected] ~]$ vi $ORACLE_HOME/dbs/initorclb.ora
把檔案中所有orcl改成orclb,在檔案尾加添加以下兩行後儲存:
db_file_name_convert=(/u01/app/oracle/oradata/orcl/,/u01/app/oracle/oradata/orclb/)
log_file_name_convert=(/u01/app/oracle/oradata/orcl/,/u01/app/oracle/oradata/orclb/)
這兩行是實作複制之後的資料檔案的位置映射。
建立參數檔案中的相關目錄:
[[email protected] ~]$ mkdir -p/u01/app/oracle/admin/orclb/adump
[[email protected] ~]$ mkdir -p/u01/app/oracle/admin/orclb/bdump
[[email protected] ~]$ mkdir -p/u01/app/oracle/admin/orclb/cdump
[[email protected] ~]$ mkdir -p/u01/app/oracle/admin/orclb/udump
[[email protected] ~] mkdir -p/u01/app/oracle/flash_recovery_area
[[email protected] ~] mkdir -p/u01/app/oracle/oradata/orclb
步驟二、建立orclb資料庫的密碼檔案
[[email protected] ~]orapwd file=$ORACLE_HOME/dbs/orapworclbpassword=oracle entries=20
步驟三、啟動orclb的偵聽,啟動orclb執行個體到no mount狀态。
[[email protected] ~]lsnrctl start
LSNRCTL for Linux: Version 10.2.0.1.0 -Production on 27-OCT-2012 14:12:36
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Starting /u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr:please wait...
TNSLSNR for Linux: Version 10.2.0.1.0 - Production
System parameter file is/u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Log messages written to/u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening on:(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oraedu1)(PORT=1521)))
Listening on:(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oraedu1)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 27-OCT-2012 21:01:40
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oraedu1)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "orclb" has 1 instance(s).
Instance"orclb", status UNKNOWN, has 1 handler(s) for this service...
The command completed successful
[[email protected] ~]sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production onSat Oct 27 14:16:52 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
[email protected]> startup nomount
ORACLE instance started.
Total System Global Area 314572800 bytes
FixedSize 2020480 bytes
VariableSize 109054848 bytes
DatabaseBuffers 201326592 bytes
RedoBuffers 2170880 bytes
[email protected]>select status from v$instance;
STATUS
------------
STARTED
[email protected]>
步驟四、在oraedu主機的orcl資料庫上用RMAN建立資料庫備份集,并複制備份到oraedu1主機上
登入oraedu主機:
[[email protected] ~]$mkdir -p/u01/app/oracle/backup/ --建立備份目錄
[[email protected] ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Sat Oct27 21:10:21 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1320402727)
RMAN>backup fulldatabase format '/u01/app/oracle/backup/full_%u%p%s.rmn' include currentcontrolfile plus archivelog format '/u01/app/oracle/backup/arch_%u%p%s.rmn'; --建立資料庫的完整備份,并備份目前控制檔案和日志檔案。
…………輸出省略
RMAN>list backup; --檢視備份的資料庫檔案、控制檔案和日志檔案。
…………輸出省略
RMAN>exit
[[email protected] ~]$scp -r/u01/app/oracle/backup/ [email protected]:/u01/app/oracle/ --備份集必須複制到auxiliary database相同的位置。
步驟五、連接配接target database和auxiliary database,執行複制語句。
登入oraedu主機:
[oracle@oraedu ~]$rman target sys/[email protected] auxiliarysys/[email protected]
Recovery Manager: Release 10.2.0.1.0 - Production on Sat Oct27 21:28:40 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1320402727)
connected to auxiliary database: ORCLB(not mounted) --如果是(not started)執行複制指令是無法成功的。
RMAN>duplicate targetdatabase to orclb; --執行資料庫複制指令。
Starting Duplicate Db at 27-OCT-12
using target database control file instead of recoverycatalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=155 devtype=DISK
contents of Memory Script:
{
set until scn 1252314;
set newname fordatafile 1 to
"/u01/app/oracle/oradata/orclb/system01.dbf";
set newname fordatafile 2 to
"/u01/app/oracle/oradata/orclb/undotbs01.dbf";
set newname fordatafile 3 to
"/u01/app/oracle/oradata/orclb/sysaux01.dbf";
set newname fordatafile 4 to
"/u01/app/oracle/oradata/orclb/users01.dbf";
set newname fordatafile 5 to
"/u01/app/oracle/oradata/orclb/example01.dbf";
set newname fordatafile 6 to
"/u01/app/oracle/oradata/orclb/statsinfo01.dbf";
set newname fordatafile 7 to
"/u01/app/oracle/oradata/orclb/toms01.dbf";
set newname fordatafile 8 to
"/u01/app/oracle/oradata/orclb/tomss01.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
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 27-OCT-12
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restorefrom backup set
restoring datafile 00001 to/u01/app/oracle/oradata/orclb/system01.dbf
restoring datafile 00002 to/u01/app/oracle/oradata/orclb/undotbs01.dbf
restoring datafile 00003 to/u01/app/oracle/oradata/orclb/sysaux01.dbf
restoring datafile 00004 to/u01/app/oracle/oradata/orclb/users01.dbf
restoring datafile 00005 to/u01/app/oracle/oradata/orclb/example01.dbf
restoring datafile 00006 to/u01/app/oracle/oradata/orclb/statsinfo01.dbf
restoring datafile 00007 to/u01/app/oracle/oradata/orclb/toms01.dbf
restoring datafile 00008 to/u01/app/oracle/oradata/orclb/tomss01.dbf
channel ORA_AUX_DISK_1: reading from backup piece/u01/app/oracle/backup/full_11noqiqh133.rmn
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/backup/full_11noqiqh133.rmntag=TAG20121027T160329
channel ORA_AUX_DISK_1: restore complete, elapsed time:00:01:47
Finished restore at 27-OCT-12
sql statement: CREATE CONTROLFILE REUSE SET DATABASE"ORCLB" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ('/u01/app/oracle/oradata/orclb/redo101.log','/u01/app/oracle/oradata/orclb/redo01.log' ) SIZE 50 M REUSE,
GROUP 2 ('/u01/app/oracle/oradata/orclb/redo202.log','/u01/app/oracle/oradata/orclb/redo02.log' ) SIZE 50 M REUSE,
GROUP 3 ('/u01/app/oracle/oradata/orclb/redo303.log','/u01/app/oracle/oradata/orclb/redo03.log' ) SIZE 50 M REUSE,
GROUP 4 ('/u01/app/oracle/oradata/orclb/redo04.log','/u01/app/oracle/oradata/orclb/redo404.log' ) SIZE 50 M REUSE
DATAFILE
'/u01/app/oracle/oradata/orclb/system01.dbf'
CHARACTER SET AL32UTF8
contents of Memory Script:
{
switch clonedatafile all;
}
executing Memory Script
released channel: ORA_AUX_DISK_1
datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=797790845filename=/u01/app/oracle/oradata/orclb/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=797790845filename=/u01/app/oracle/oradata/orclb/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=797790845filename=/u01/app/oracle/oradata/orclb/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=797790845filename=/u01/app/oracle/oradata/orclb/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=797790845filename=/u01/app/oracle/oradata/orclb/statsinfo01.dbf
datafile 7 switched to datafile copy
input datafile copy recid=6 stamp=797790845filename=/u01/app/oracle/oradata/orclb/toms01.dbf
datafile 8 switched to datafile copy
input datafile copy recid=7 stamp=797790845filename=/u01/app/oracle/oradata/orclb/tomss01.dbf
contents of Memory Script:
{
set until scn 1252314;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 27-OCT-12
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 todefault destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=55
channel ORA_AUX_DISK_1: reading from backup piece/u01/app/oracle/backup/arch_13noqj28135.rmn
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/backup/arch_13noqj28135.rmntag=TAG20121027T160736
channel ORA_AUX_DISK_1: restore complete, elapsed time:00:00:02
archive logfilename=/u01/app/oracle/flash_recovery_area/ORCLB/archivelog/2012_10_27/o1_mf_1_55_88q7404s_.arcthread=1 sequence=55
channel clone_default: deleting archive log(s)
archive logfilename=/u01/app/oracle/flash_recovery_area/ORCLB/archivelog/2012_10_27/o1_mf_1_55_88q7404s_.arcrecid=1 stamp=797790848
media recovery complete, elapsed time: 00:00:03
Finished recover at 27-OCT-12
contents of Memory Script:
{
shutdown clone;
startup clonenomount ;
}
executing Memory Script
database dismounted
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 314572800 bytes
Fixed Size 2020480 bytes
Variable Size 109054848 bytes
Database Buffers 201326592 bytes
Redo Buffers 2170880 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE"ORCLB" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ('/u01/app/oracle/oradata/orclb/redo101.log','/u01/app/oracle/oradata/orclb/redo01.log' ) SIZE 50 M REUSE,
GROUP 2 ('/u01/app/oracle/oradata/orclb/redo202.log','/u01/app/oracle/oradata/orclb/redo02.log' ) SIZE 50 M REUSE,
GROUP 3 ('/u01/app/oracle/oradata/orclb/redo303.log','/u01/app/oracle/oradata/orclb/redo03.log' ) SIZE 50 M REUSE,
GROUP 4 ('/u01/app/oracle/oradata/orclb/redo04.log','/u01/app/oracle/oradata/orclb/redo404.log' ) SIZE 50 M REUSE
DATAFILE
'/u01/app/oracle/oradata/orclb/system01.dbf'
CHARACTER SET AL32UTF8
contents of Memory Script:
{
set newname fortempfile 1 to
"/u01/app/oracle/oradata/orclb/temp01.dbf";
switch clonetempfile all;
catalog clonedatafilecopy "/u01/app/oracle/oradata/orclb/undotbs01.dbf";
catalog clonedatafilecopy "/u01/app/oracle/oradata/orclb/sysaux01.dbf";
catalog clonedatafilecopy "/u01/app/oracle/oradata/orclb/users01.dbf";
catalog clonedatafilecopy "/u01/app/oracle/oradata/orclb/example01.dbf";
catalog clonedatafilecopy "/u01/app/oracle/oradata/orclb/statsinfo01.dbf";
catalog clonedatafilecopy "/u01/app/oracle/oradata/orclb/toms01.dbf";
catalog clonedatafilecopy "/u01/app/oracle/oradata/orclb/tomss01.dbf";
switch clonedatafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed temporary file 1 to/u01/app/oracle/oradata/orclb/temp01.dbf in control file
cataloged datafile copy
datafile copyfilename=/u01/app/oracle/oradata/orclb/undotbs01.dbf recid=1 stamp=797792902
cataloged datafile copy
datafile copyfilename=/u01/app/oracle/oradata/orclb/sysaux01.dbf recid=2 stamp=797792908
cataloged datafile copy
datafile copyfilename=/u01/app/oracle/oradata/orclb/users01.dbf recid=3 stamp=797792909
cataloged datafile copy
datafile copyfilename=/u01/app/oracle/oradata/orclb/example01.dbf recid=4 stamp=797792909
cataloged datafile copy
datafile copyfilename=/u01/app/oracle/oradata/orclb/statsinfo01.dbf recid=5 stamp=797792910
cataloged datafile copy
datafile copyfilename=/u01/app/oracle/oradata/orclb/toms01.dbf recid=6 stamp=797792910
cataloged datafile copy
datafile copyfilename=/u01/app/oracle/oradata/orclb/tomss01.dbf recid=7 stamp=797792910
datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=797792902filename=/u01/app/oracle/oradata/orclb/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=797792908filename=/u01/app/oracle/oradata/orclb/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=797792909filename=/u01/app/oracle/oradata/orclb/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=797792909filename=/u01/app/oracle/oradata/orclb/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=797792910filename=/u01/app/oracle/oradata/orclb/statsinfo01.dbf
datafile 7 switched to datafile copy
input datafile copy recid=6 stamp=797792910filename=/u01/app/oracle/oradata/orclb/toms01.dbf
datafile 8 switched to datafile copy
input datafile copy recid=7 stamp=797792910filename=/u01/app/oracle/oradata/orclb/tomss01.dbf
contents of Memory Script:
{
Alter clone databaseopen resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 27-OCT-12
RMAN> --已完成資料庫的複制
步驟六、連接配接orclb資料庫驗證複制結果
登陸oraedu1主機,用sqlplus連接配接orclb資料庫
[[email protected] ~]$ sqlplus / as sysdba
SQL*Plus:Release 10.2.0.1.0 - Production on Sat Oct 27 21:37:33 2012
Copyright(c) 1982, 2005, Oracle. All rightsreserved.
Connectedto:
OracleDatabase 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
Withthe Partitioning, OLAP and Data Mining options
[email protected]> selectstatus from v$instance;
STATUS
------------
OPEN
[email protected]> selectdbid,name,log_mode from v$database;
DBID NAME LOG_MODE
---------- --------- ------------
2861060852 ORCLB ARCHIVELOG
可以看到資料庫已經啟動,而且是處于歸檔模式,并且DBID=2861060852 和orcl資料庫的DBID=1320402727不一樣。複制完資料庫後要重新配置em,否則無法用em管理資料庫。