分类: Oracle
2009-04-28 12:05:05
Doc ID: RMAN: Creating a Duplicate Database
目的
这个文章的目的是介绍RMAN duplicate database
1.0 介绍
duplicate database 命令是从oracle 815开始的,他允许我们从target数据库上,创建一个数据库
他创建的数据库DBID是和target库是不同的。
2.0 预备条件
1. target数据库必须是有效的
2. target数据库必须是mount或open
3. NLS_LANG NLS_DATE_FORMAT 环境变量要设置好
3.0 步骤
下面是一个create duplicate database的例子,duplicate db也在同一主机上.target db=ht ,duplicate db=ht_dup
2. rman target auxiliary
前期先用rman对数据库和归档做备份
backup database plus archivelog delete input;;
RMAN>[oracle@abcdef test_dup]$ rman target auxiliary
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Apr 16 15:37:46 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: TEST (DBID=1982451557)
connected to auxiliary database: TEST_DUP (not mounted)
RMAN> run {
SET NEWNAME for datafile 1 to '/home/oracle/oradata/test_dup/SYSTEM01.DBF';
SET NEWNAME for datafile 2 to '/home/oracle/oradata/test_dup/UNDOTBS01.DBF';
SET NEWNAME for datafile 3 to '/home/oracle/oradata/test_dup/SYSAUX01.DBF';
SET NEWNAME for datafile 4 to '/home/oracle/oradata/test_dup/USERS01.DBF';
SET NEWNAME for tempfile 1 to '/home/oracle/oradata/test_dup/TEMP01.DBF';
duplicate target database to test_dup
pfile='/home/oracle/product/10.2.0.3/dbs/inittest_dup.ora'
logfile
'/home/oracle/oradata/test_dup/redo1.log' size 10m,
'/home/oracle/oradata/test_dup/redo2.log' size 10m,
'/home/oracle/oradata/test_dup/redo3.log' size 10m;
}2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13>
executing command: SET NEWNAME
using target database control file instead of recovery catalog
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting Duplicate Db at 16-APR-09
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=541 devtype=DISK
contents of Memory Script:
{
set until scn 243401;
set newname for datafile 1 to
"/home/oracle/oradata/test_dup/SYSTEM01.DBF";
set newname for datafile 2 to
"/home/oracle/oradata/test_dup/UNDOTBS01.DBF";
set newname for datafile 3 to
"/home/oracle/oradata/test_dup/SYSAUX01.DBF";
set newname for datafile 4 to
"/home/oracle/oradata/test_dup/USERS01.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
Starting restore at 16-APR-09
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 /home/oracle/oradata/test_dup/SYSTEM01.DBF
restoring datafile 00002 to /home/oracle/oradata/test_dup/UNDOTBS01.DBF
restoring datafile 00003 to /home/oracle/oradata/test_dup/SYSAUX01.DBF
restoring datafile 00004 to /home/oracle/oradata/test_dup/USERS01.DBF
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/product/10.2.0.3/dbs/0akckf70_1_1
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/home/oracle/product/10.2.0.3/dbs/0akckf70_1_1 tag=TAG20090416T150815
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:46
Finished restore at 16-APR-09
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "TEST_DUP" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/home/oracle/oradata/test_dup/redo1.log' SIZE 10 M ,
GROUP 2 '/home/oracle/oradata/test_dup/redo2.log' SIZE 10 M ,
GROUP 3 '/home/oracle/oradata/test_dup/redo3.log' SIZE 10 M
DATAFILE
'/home/oracle/oradata/test_dup/SYSTEM01.DBF'
CHARACTER SET ZHS16GBK
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=684344343 filename=/home/oracle/oradata/test_dup/UNDOTBS01.DBF
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=684344343 filename=/home/oracle/oradata/test_dup/SYSAUX01.DBF
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=684344343 filename=/home/oracle/oradata/test_dup/USERS01.DBF
contents of Memory Script:
{
set until scn 243401;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 16-APR-09
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=541 devtype=DISK
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=29
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/product/10.2.0.3/dbs/0ckckf96_1_1
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/home/oracle/product/10.2.0.3/dbs/0ckckf96_1_1 tag=TAG20090416T150925
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
archive log filename=/home/oracle/product/10.2.0.3/dbs/arch1_29_684305125.dbf thread=1 sequence=29
channel clone_default: deleting archive log(s)
archive log filename=/home/oracle/product/10.2.0.3/dbs/arch1_29_684305125.dbf recid=1 stamp=684344349
media recovery complete, elapsed time: 00:00:02
Finished recover at 16-APR-09
contents of Memory Script:
{
shutdown clone;
startup clone nomount pfile= '/home/oracle/product/10.2.0.3/dbs/inittest_dup.ora';
}
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 1218316 bytes
Variable Size 79694068 bytes
Database Buffers 83886080 bytes
Redo Buffers 2973696 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "TEST_DUP" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/home/oracle/oradata/test_dup/redo1.log' SIZE 10 M ,
GROUP 2 '/home/oracle/oradata/test_dup/redo2.log' SIZE 10 M ,
GROUP 3 '/home/oracle/oradata/test_dup/redo3.log' SIZE 10 M
DATAFILE
'/home/oracle/oradata/test_dup/SYSTEM01.DBF'
CHARACTER SET ZHS16GBK
contents of Memory Script:
{
set newname for tempfile 1 to
"/home/oracle/oradata/test_dup/TEMP01.DBF";
switch clone tempfile all;
catalog clone datafilecopy "/home/oracle/oradata/test_dup/UNDOTBS01.DBF";
catalog clone datafilecopy "/home/oracle/oradata/test_dup/SYSAUX01.DBF";
catalog clone datafilecopy "/home/oracle/oradata/test_dup/USERS01.DBF";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed temporary file 1 to /home/oracle/oradata/test_dup/TEMP01.DBF in control file
cataloged datafile copy
datafile copy filename=/home/oracle/oradata/test_dup/UNDOTBS01.DBF recid=1 stamp=684344368
cataloged datafile copy
datafile copy filename=/home/oracle/oradata/test_dup/SYSAUX01.DBF recid=2 stamp=684344369
cataloged datafile copy
datafile copy filename=/home/oracle/oradata/test_dup/USERS01.DBF recid=3 stamp=684344369
datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=684344368 filename=/home/oracle/oradata/test_dup/UNDOTBS01.DBF
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=684344369 filename=/home/oracle/oradata/test_dup/SYSAUX01.DBF
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=684344369 filename=/home/oracle/oradata/test_dup/USERS01.DBF
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 16-APR-09
经过查询验证,数据库确实已经打开.
SQL> select open_mode,name from v$database;
OPEN_MODE NAME
---------- ---------
READ WRITE TEST_DUP