透過Oracle的duplicate database to 【newsid】實現資料庫克隆;

zhsumin發表於2007-05-24

環境:

Oracle10.2 RAC 到10.2單機環境執行;

[@more@]

1.準備好相應的目錄結構

$cd /home/oracle/admin
$mkdir test
$cd test
$mkdir adump bdump cdump dpdump pfile udump

2.使用initoraT.ora建立引數檔案inittest.ora
$cd dbs
$cp initoraT.ora inittest.ora

修改inittest2.ora
test.__db_cache_size=8388608
test.__java_pool_size=4194304
test.__large_pool_size=4194304
test.__shared_pool_size=67108864
test.__streams_pool_size=4194304
*.audit_file_dest='/home/oracle/admin/test/adump'
*.background_dump_dest='/home/oracle/admin/test/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/home/oracle/oradata/test/control01.dbf','/home/oracle/oradata/test/control02.dbf'
*.core_dump_dest='/home/oracle/admin/test/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='test'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=testXDB)'
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=16777216
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=167772160
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/home/oracle/admin/test/udump'
*.DB_FILE_NAME_CONVERT=('/home/oracle/oradata/oraT','/home/oracle/oradata/test')
*.LOG_FILE_NAME_CONVERT=('/home/oracle/oradata/oraT','/home/oracle/oradata/test')

3.建立密碼檔案

$orapwd file=orapwtest password=oracle entries=10

4.配置好監聽和tnsnames

5.使用rman備份原庫

先做一次包括archivelog的全備份
run {
allocate channel t1 type disk;
backup current controlfile;
backup full database;
backup archivelog all;
release channel t1;
}

6. 啟動test到nomount狀態;
SQL>startup nomount

7.開始duplicate target database to "test"
先set ORACLE_SID=test /*cloneSID*/
獲得原資料檔案的number方法:
SQL>select 'set new name for datafile '||FILE#||' to '||'"'||trim(name)||'"' FROM v$datafile;

rman>connect target
rman>connect auxiliary sys/oracle

run{
allocate auxiliary channel t1 type disk;
set newname for datafile 1 to '/home/oracle/oradata/test/system01.dbf';
set newname for datafile 2 to '/home/oracle/oradata/test/undotbs1.bdf';
set newname for datafile 3 to '/home/oracle/oradata/test/sysaux01.dbf';
set newname for datafile 4 to '/home/oracle/oradata/test/users01.bdf';
set newname for datafile 5 to '/home/oracle/oradata/test/t1.dbf';
DUPLICATE TARGET DATABASE TO "test"
LOGFILE
GROUP 1 ('/home/oracle/oradata/test/redo01.log') SIZE 5M,
GROUP 2 ('/home/oracle/oradata/test/redo02.log') SIZE 5M,
GROUP 3 ('/home/oracle/oradata/test/redo03.log') SIZE 5M;
}

8.測試,並建立spfile;
刪除pfile檔案中的引數:
*.DB_FILE_NAME_CONVERT=('/home/oracle/oradata/oraT','/home/oracle/oradata/test')
*.LOG_FILE_NAME_CONVERT=('/home/oracle/oradata/oraT','/home/oracle/oradata/test')

SQL> startup
ORACLE instance started.

Total System Global Area 167772160 bytes
Fixed Size 1218316 bytes
Variable Size 62916852 bytes
Database Buffers 100663296 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SQL> show parameter pfile

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /home/oracle/product/10.2/db/d
bs/spfiletest.ora
SQL> show parameter instance;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
active_instance_count integer
cluster_database_instances integer 1
instance_groups string
instance_name string test
instance_number integer 0
instance_type string RDBMS
open_links_per_instance integer 4
parallel_instance_group string
parallel_server_instances integer 1
SQL> show parameter db_name

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_name string test
SQL> show parameter db_do

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_domain string

SQL> show parameter service_names

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string test


[oracle@OTest dbs]$ sqlplus

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Jun 25 01:05:49 2007

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


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

SQL> select instance_name,status from v$instance;

INSTANCE_NAME STATUS
---------------- ------------
test OPEN

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

相關文章