target database通过rman备份到NFS中,备份信息注册到catalog database,复制过程仅连接auxiliary database(不需要target database以及catalog database),通过备份文件路径,实现复制。
名词解释:auxiliary database(辅助数据库):将备份复制到的数据库;target database(目标数据库):执行备份,被复制的数据库;catalog database(目录数据库):RMAN目录数据库。
2、测试环境
数据库版本为11.2.0.1,OS版本为RHEL 6.4。
catalog database服务器提供NFS服务,target database服务器以及auxiliary database服务器都以/u01/backup目录名挂载NFS。
2.1 target database服务器配置
网卡信息:
[oracle@rman-database ~]$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:AC:74:E5
inet addr:172.26.181.102 Bcast:172.26.181.255 Mask:255.255.255.0
inet6 addr: fe80::250:56ff:feac:74e5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3931745 errors:0 dropped:0 overruns:0 frame:0
TX packets:7878124 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3869168688 (3.6 GiB) TX bytes:8951385101 (8.3 GiB)
挂载信息:
[oracle@rman-database ~]$ vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Fri Dec 12 16:02:18 2014
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_rmandatabase-lv_root / ext4 defaults 1 1
UUID=6346f79c-8dd9-4775-a974-6c21b7f010d0 /boot ext4 defaults 1 2
/dev/mapper/vg_rmandatabase-lv_home /home ext4 defaults 1 2
/dev/mapper/vg_rmandatabase-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
172.26.181.101:/orabackup /u01/backup nfs defaults 0 0
2.2 catalog database服务器配置
网卡配置:
[root@rman-backup ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:AC:03:44
inet addr:172.26.181.101 Bcast:172.26.181.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4788072 errors:0 dropped:63 overruns:0 frame:0
TX packets:422427 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:23464017822 (21.8 GiB) TX bytes:4543120889 (4.2 GiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1080634 errors:0 dropped:0 overruns:0 frame:0
TX packets:1080634 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:104363771 (99.5 MiB) TX bytes:104363771 (99.5 MiB)
NFS服务配置:
[root@rman-backup ~]# vi /etc/exports
/orabackup 172.26.181.98(rw) 172.26.181.102(rw) 172.26.181.103(rw)
~
2.3 auxiliary database服务器配置
网卡配置:
[root@rman-auxiliary ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:AC:2F:B0
inet addr:172.26.181.103 Bcast:172.26.181.255 Mask:255.255.255.0
inet6 addr: fe80::250:56ff:feac:2fb0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:231 errors:0 dropped:0 overruns:0 frame:0
TX packets:190 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:26110 (25.4 KiB) TX bytes:23798 (23.2 KiB)
挂载配置:
[root@rman-auxiliary ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 9.9G 366M 9.0G 4% /
tmpfs 2.0G 72K 2.0G 1% /dev/shm
/dev/sda1 485M 37M 423M 8% /boot
/dev/sda6 9.9G 152M 9.2G 2% /home
/dev/sda7 4.0G 136M 3.7G 4% /opt
/dev/sda8 4.0G 529M 3.3G 14% /tmp
/dev/sda2 49G 6.5G 40G 14% /u01
/dev/sda9 4.0G 2.9G 880M 78% /usr
/dev/sda10 4.0G 137M 3.7G 4% /usr/local
/dev/sda11 4.0G 312M 3.5G 9% /var
172.26.181.101:/orabackup
148G 12G 129G 9% /u01/backup
3、测试步骤
3.1 备份目标数据库
备份脚本如下:
[oracle@rman-database script]$ more level0.rman
connect target /
connect catalog rman/rman@172.26.181.101:1521/catalog
run{
allocate channel c1 type disk;
backup as backupset incremental level 0 database format '/u01/backup/backups
et/df0_%d_%s_%p_%T' plus archivelog delete all input format '/u01/backup/backups
et/arch_%d_%s_%p_%T';
delete obsolete;
release channel c1;
}
使用RMAN登录目标数据库及目录数据库执行备份:
[oracle@rman-database ~]$ rman target/ catalog rman/rman@172.26.181.101:1521/catalog
Recovery Manager: Release 11.2.0.1.0 - Production on Mon Jan 12 15:41:10 2015
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: TESTDB (DBID=2650650243)
connected to recovery catalog database
登录过程可以看到target database的DBID为2650650243,数据库名为TESTDB。
RMAN> list backup;
specification does not match any backup in the repository
RMAN> @/u01/backup/script/level0.rman
RMAN> connect target *
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-06167: already connected
RMAN> connect catalog *
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-06167: already connected
RMAN> run{
2> allocate channel c1 type disk;
3> backup as backupset incremental level 0 database format '/u01/backup/backupset/df0_%d_%s_%p_%T' plus archivelog delete all input format '/u01/backup/backupset/arch_%d_%s_%p_%T';
4> delete obsolete;
5> release channel c1;
6> }
released channel: ORA_DISK_1
allocated channel: c1
channel c1: SID=198 device type=DISK
Starting backup at 12-JAN-15
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=337 RECID=332 STAMP=868782293
input archived log thread=1 sequence=338 RECID=333 STAMP=868808655
channel c1: starting piece 1 at 12-JAN-15
channel c1: finished piece 1 at 12-JAN-15
piece handle=/u01/backup/backupset/arch_TESTDB_18_1_20150112 tag=TAG20150112T154416 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
channel c1: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2015_01_12/o1_mf_1_337_bc652ol7_.arc RECID=332 STAMP=868782293
archived log file name=/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2015_01_12/o1_mf_1_338_bc6ythh1_.arc RECID=333 STAMP=868808655
Finished backup at 12-JAN-15
Starting backup at 12-JAN-15
channel c1: starting incremental level 0 datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/testdb/users01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/testdb/hglt01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/testdb/dagl01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/testdb/sysaux01.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/testdb/system01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/testdb/undotbs01.dbf
channel c1: starting piece 1 at 12-JAN-15
channel c1: finished piece 1 at 12-JAN-15
piece handle=/u01/backup/backupset/df0_TESTDB_19_1_20150112 tag=TAG20150112T154417 comment=NONE
channel c1: backup set complete, elapsed time: 00:01:05
channel c1: starting incremental level 0 datafile backup set
channel c1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel c1: starting piece 1 at 12-JAN-15
channel c1: finished piece 1 at 12-JAN-15
piece handle=/u01/backup/backupset/df0_TESTDB_20_1_20150112 tag=TAG20150112T154417 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 12-JAN-15
Starting backup at 12-JAN-15
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=339 RECID=334 STAMP=868808725
channel c1: starting piece 1 at 12-JAN-15
channel c1: finished piece 1 at 12-JAN-15
piece handle=/u01/backup/backupset/arch_TESTDB_21_1_20150112 tag=TAG20150112T154525 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
channel c1: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2015_01_12/o1_mf_1_339_bc6ywo47_.arc RECID=334 STAMP=868808725
Finished backup at 12-JAN-15
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Deleting the following obsolete backups and copies:
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set 4183 12-JAN-15
Backup Piece 4186 12-JAN-15 /u01/backup/backupset/arch_TESTDB_18_1_20150112
deleted backup piece
backup piece handle=/u01/backup/backupset/arch_TESTDB_18_1_20150112 RECID=18 STAMP=868808656
Deleted 1 objects
released channel: c1
RMAN> **end-of-file**
由于已经登录所以会报错,这里不用理会。
查看备份:
RMAN> list backup;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4184 Incr 0 3.60G DISK 00:01:03 12-JAN-15
BP Key: 4187 Status: AVAILABLE Compressed: NO Tag: TAG20150112T154417
Piece Name: /u01/backup/backupset/df0_TESTDB_19_1_20150112
List of Datafiles in backup set 4184
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 0 Incr 11735702 12-JAN-15 /u01/app/oracle/oradata/testdb/system01.dbf
2 0 Incr 11735702 12-JAN-15 /u01/app/oracle/oradata/testdb/sysaux01.dbf
3 0 Incr 11735702 12-JAN-15 /u01/app/oracle/oradata/testdb/undotbs01.dbf
4 0 Incr 11735702 12-JAN-15 /u01/app/oracle/oradata/testdb/users01.dbf
5 0 Incr 11735702 12-JAN-15 /u01/app/oracle/oradata/testdb/hglt01.dbf
6 0 Incr 11735702 12-JAN-15 /u01/app/oracle/oradata/testdb/dagl01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4185 Incr 0 9.95M DISK 00:00:01 12-JAN-15
BP Key: 4188 Status: AVAILABLE Compressed: NO Tag: TAG20150112T154417
Piece Name: /u01/backup/backupset/df0_TESTDB_20_1_20150112
SPFILE Included: Modification time: 08-JAN-15
SPFILE db_unique_name: TESTDB
Control File Included: Ckp SCN: 11735771 Ckp time: 12-JAN-15
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
4207 26.00K DISK 00:00:00 12-JAN-15
BP Key: 4210 Status: AVAILABLE Compressed: NO Tag: TAG20150112T154525
Piece Name: /u01/backup/backupset/arch_TESTDB_21_1_20150112
List of Archived Logs in backup set 4207
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 339 11735685 12-JAN-15 11735777 12-JAN-15
可以看到3个backupset,4184包括数据文件备份,4185包括SPFILE和Control File备份,4207包括Archived Log的备份。
3.2 启动辅助实例
为了启动辅助实例到NOMOUNT状态,我们需要手动创建PFILE;为了远程登录,我们需要重建密码文件。
注意此时auxiliary database仅仅安装了database而没有创建实例。
3.2.1 创建PFILE
[oracle@rman-auxiliary dbs]$ pwd
/u01/app/oracle/product/11.2.0/dbhome_1/dbs
[oracle@rman-auxiliary dbs]$ touch initTESTDB.ora
[oracle@rman-auxiliary dbs]$ vi initTESTDB.ora
DB_NAME=TESTDB
~
~
~
然后配置ORACLE_SID环境变量:
[oracle@rman-auxiliary ~]$ pwd
/home/oracle
[oracle@rman-auxiliary ~]$ vi .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_HOME
PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export PATH
ORACLE_SID=TESTDB
export ORACLE_SID
~
~
3.2.2 创建密码文件
这里使用重建密码文件的方法:
[oracle@rman-auxiliary ~]$ orapwd file=$ORACLE_HOME/dbs/orapwtestdb password=oracle
3.2.3 启动辅助实例
[oracle@rman-auxiliary ~]$ echo $ORACLE_SID
TESTDB
[oracle@rman-auxiliary ~]$ echo $ORACLE_HOME
/u01/app/oracle/product/11.2.0/dbhome_1
[oracle@rman-auxiliary ~]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.1.0 Production on Mon Jan 12 16:14:00 2015
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 217157632 bytes
Fixed Size 2211928 bytes
Variable Size 159387560 bytes
Database Buffers 50331648 bytes
Redo Buffers 5226496 bytes
SQL>
3.2.4 创建数据文件存放路径
这个测试中使用NOFILENAMECHECK进行复制,及目标端和辅助端数据文件路径相同,为了RMAN能够在辅助端创建数据文件,需要先在辅助端创建文件夹:
[oracle@rman-auxiliary oracle]$ pwd
/u01/app/oracle
[oracle@rman-auxiliary oracle]$ mkdir oradata
[oracle@rman-auxiliary oracle]$ cd oradata
[oracle@rman-auxiliary oradata]$ mkdir testdb
[oracle@rman-auxiliary oradata]$ pwd
/u01/app/oracle/oradata
[oracle@rman-auxiliary oradata]$ cd testdb
[oracle@rman-auxiliary testdb]$ pwd
/u01/app/oracle/oradata/testdb
3.3 复制数据库
在auxiliary database端使用rman连接auxiliary实例:
[oracle@rman-auxiliary ~]$ rman target/
Recovery Manager: Release 11.2.0.1.0 - Production on Mon Jan 12 16:16:51 2015
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: TESTDB (not mounted)
RMAN>
执行下面的语句:
RMAN> DUPLICATE DATABASE TO 'TESTDB' BACKUP LOCATION '/u01/backup/backupset'
2> NOFILENAMECHECK;
Starting Duplicate Db at 12-JAN-15
contents of Memory Script:
{
sql clone "alter system set db_name =
''TESTDB'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''TESTDB'' comment=
''Modified by RMAN duplicate'' scope=spfile";
shutdown clone immediate;
startup clone force nomount
restore clone primary controlfile from '/u01/backup/backupset/df0_TESTDB_20_1_20150112';
alter clone database mount;
}
executing Memory Script
sql statement: alter system set db_name = ''TESTDB'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set db_unique_name = ''TESTDB'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area 217157632 bytes
Fixed Size 2211928 bytes
Variable Size 159387560 bytes
Database Buffers 50331648 bytes
Redo Buffers 5226496 bytes
Starting restore at 12-JAN-15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=130 device type=DISK
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/cntrlTESTDB.dbf
Finished restore at 12-JAN-15
database mounted
released channel: ORA_AUX_DISK_1
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=130 device type=DISK
contents of Memory Script:
{
set until scn 11735777;
set newname for datafile 1 to
"/u01/app/oracle/oradata/testdb/system01.dbf";
set newname for datafile 2 to
"/u01/app/oracle/oradata/testdb/sysaux01.dbf";
set newname for datafile 3 to
"/u01/app/oracle/oradata/testdb/undotbs01.dbf";
set newname for datafile 4 to
"/u01/app/oracle/oradata/testdb/users01.dbf";
set newname for datafile 5 to
"/u01/app/oracle/oradata/testdb/hglt01.dbf";
set newname for datafile 6 to
"/u01/app/oracle/oradata/testdb/dagl01.dbf";
restore
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
Starting restore at 12-JAN-15
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/testdb/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/testdb/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/testdb/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/testdb/users01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/testdb/hglt01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/testdb/dagl01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/backup/backupset/df0_TESTDB_19_1_20150112
channel ORA_AUX_DISK_1: piece handle=/u01/backup/backupset/df0_TESTDB_19_1_20150112 tag=TAG20150112T154417
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 12-JAN-15
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=868811308 file name=/u01/app/oracle/oradata/testdb/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=868811308 file name=/u01/app/oracle/oradata/testdb/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=868811308 file name=/u01/app/oracle/oradata/testdb/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=868811308 file name=/u01/app/oracle/oradata/testdb/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=5 STAMP=868811308 file name=/u01/app/oracle/oradata/testdb/hglt01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=6 STAMP=868811308 file name=/u01/app/oracle/oradata/testdb/dagl01.dbf
contents of Memory Script:
{
set until scn 11735777;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 12-JAN-15
using channel ORA_AUX_DISK_1
starting media recovery
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=339
channel ORA_AUX_DISK_1: reading from backup piece /u01/backup/backupset/arch_TESTDB_21_1_20150112
channel ORA_AUX_DISK_1: piece handle=/u01/backup/backupset/arch_TESTDB_21_1_20150112 tag=TAG20150112T154525
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_339_867322117.dbf thread=1 sequence=339
channel clone_default: deleting archived log(s)
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_339_867322117.dbf RECID=1 STAMP=868811309
media recovery complete, elapsed time: 00:00:01
Finished recover at 12-JAN-15
contents of Memory Script:
{
shutdown clone immediate;
startup clone nomount;
sql clone "alter system set db_name =
''TESTDB'' comment=
''Reset to original value by RMAN'' scope=spfile";
sql clone "alter system reset db_unique_name scope=spfile";
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script
database dismounted
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 217157632 bytes
Fixed Size 2211928 bytes
Variable Size 159387560 bytes
Database Buffers 50331648 bytes
Redo Buffers 5226496 bytes
sql statement: alter system set db_name = ''TESTDB'' comment= ''Reset to original value by RMAN'' scope=spfile
sql statement: alter system reset db_unique_name scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 217157632 bytes
Fixed Size 2211928 bytes
Variable Size 159387560 bytes
Database Buffers 50331648 bytes
Redo Buffers 5226496 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "TESTDB" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/u01/app/oracle/oradata/testdb/redo01.log' ) SIZE 50 M REUSE,
GROUP 2 ( '/u01/app/oracle/oradata/testdb/redo02.log' ) SIZE 50 M REUSE,
GROUP 3 ( '/u01/app/oracle/oradata/testdb/redo03.log' ) SIZE 50 M REUSE
DATAFILE
'/u01/app/oracle/oradata/testdb/system01.dbf'
CHARACTER SET ZHS16GBK
contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/app/oracle/oradata/testdb/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/u01/app/oracle/oradata/testdb/sysaux01.dbf",
"/u01/app/oracle/oradata/testdb/undotbs01.dbf",
"/u01/app/oracle/oradata/testdb/users01.dbf",
"/u01/app/oracle/oradata/testdb/hglt01.dbf",
"/u01/app/oracle/oradata/testdb/dagl01.dbf";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/testdb/temp01.dbf in control file
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/testdb/sysaux01.dbf RECID=1 STAMP=868811326
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/testdb/undotbs01.dbf RECID=2 STAMP=868811326
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/testdb/users01.dbf RECID=3 STAMP=868811326
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/testdb/hglt01.dbf RECID=4 STAMP=868811326
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/testdb/dagl01.dbf RECID=5 STAMP=868811326
datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=868811326 file name=/u01/app/oracle/oradata/testdb/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=868811326 file name=/u01/app/oracle/oradata/testdb/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=868811326 file name=/u01/app/oracle/oradata/testdb/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=868811326 file name=/u01/app/oracle/oradata/testdb/hglt01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=5 STAMP=868811326 file name=/u01/app/oracle/oradata/testdb/dagl01.dbf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 12-JAN-15
可以看到复制结束后,数据库已打开。
4、验证数据库
[oracle@rman-auxiliary ~]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.1.0 Production on Mon Jan 12 16:30:52 2015
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select status from v$instance;
STATUS
------------
OPEN
SQL> select dbid from v$database;
DBID
----------
2652139453
SQL> show parameter control_file
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time integer 7
control_files string /u01/app/oracle/product/11.2.0
/dbhome_1/dbs/cntrlTESTDB.dbf
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /u01/app/oracle/product/11.2.0
/dbhome_1/dbs/spfileTESTDB.ora
SQL> desc v$logfile;
Name Null? Type
----------------------------------------- -------- ----------------------------
GROUP# NUMBER
STATUS VARCHAR2(7)
TYPE VARCHAR2(7)
MEMBER VARCHAR2(513)
IS_RECOVERY_DEST_FILE VARCHAR2(3)
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/testdb/redo03.log
/u01/app/oracle/oradata/testdb/redo02.log
/u01/app/oracle/oradata/testdb/redo01.log
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence 1
Next log sequence to archive 1
Current log sequence 1
可以看出,参数文件SPFILE、控制文件、联机日志文件、归档目录都已经变成了新的目录。另外RMAN为辅助数据库生成了新的DBID。
最后不能忘记创建监听。
5、总结
这次复制测试中,仅仅使用到了RMAN备份存在的目录(模拟了RMAN备份信息丢失并且目标数据库完全故障),另外在DUPLICATE语句中指定了目标数据库的数据库名(如果同名数据库备份存在,则还需指定DBID,意味着复制前必须知道目标数据库的DBID)。