昨天晚上,群里雨哥说,他有个异机备份恢复测试要做,但是备份的原库和目标端的数据文件目录都不一样,需要一个一个set name修改脚本,但是数据文件+日志文件有几百个,改起来很麻烦。
于是我想起来做dg的时候,在备库通过duplicate+conver参数,实现了文件自动重命名的操作,但是讨论并且测试了一下,在要恢复的库上创建参数文件时写了convert参数,用rman restore的时候,convert不会生效,还得手动改set name才行。
查阅了相关的官方文档、MOS里,也确实是说了,下convert只能用duplicate时候才生效。
经过王也大哥提点,发现共有以下两种方法可以实现:
方法1:
Perform Backup Based RMAN DUPLICATE Without Connecting To Target Database For Both Disk & Tape Backups (Doc ID 1375864.1)
方法2
RMAN: SET NEWNAME Command Using SQL (Doc ID 549972.1)
参照以上方法,进行了一下测试实验,并进行一下比对。
如果只是想要通过原库搭建1个测试库,也可以通过网络duplicate,之前也有小伙伴写过用duplicate来搭建测试库的过程。
链接 :北方的猫-11gr2 rman duplicate数据库单机到RAC
原库环境:
ORACLE 11.2.0.4 RAC
ORACLE LINUX 6.9操作系统
数据文件路径+DATA
恢复机环境
ORACLE 11.2.0.4 单机
ORACLE LINUX 6.9操作系统
数据文件路径/u01/app/oracle/oradata/orcl
原库数据文件位置
原库TEMP文件位置
原库日志文件位置
使用oracle创建下备份目录
mkdir -p /u01/rman
在RAC1节点登录rman进行备份,脚本如下
RMAN> run
{
allocate channel c1 type disk format '/u01/rman/%I-%Y%M%D-%U';
backup as compressed backupset incremental level 0 tag 'duplicate' check logical database plus archivelog;
release channel c1 ;
}2> 3> 4> 5> 6>
using target database control file instead of recovery catalog
allocated channel: c1
channel c1: SID=143 instance=orcl1 device type=DISK
Starting backup at 07-DEC-23
current log archived
channel c1: starting compressed archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=132 RECID=373 STAMP=1154953173
input archived log thread=2 sequence=99 RECID=374 STAMP=1154953175
input archived log thread=2 sequence=100 RECID=375 STAMP=1154953176
input archived log thread=1 sequence=133 RECID=376 STAMP=1154953180
input archived log thread=1 sequence=134 RECID=379 STAMP=1154953243
input archived log thread=2 sequence=101 RECID=377 STAMP=1154953230
input archived log thread=2 sequence=102 RECID=378 STAMP=1154953239
input archived log thread=2 sequence=103 RECID=382 STAMP=1154953380
input archived log thread=1 sequence=135 RECID=380 STAMP=1154953303
input archived log thread=1 sequence=136 RECID=381 STAMP=1154953374
input archived log thread=1 sequence=137 RECID=383 STAMP=1154953398
input archived log thread=2 sequence=104 RECID=385 STAMP=1154980087
input archived log thread=1 sequence=138 RECID=384 STAMP=1154980086
channel c1: starting piece 1 at 07-DEC-23
channel c1: finished piece 1 at 07-DEC-23
piece handle=/u01/rman/1613952925-20231207-152df67p_1_1 tag=DUPLICATE comment=NONE
channel c1: backup set complete, elapsed time: 00:00:07
Finished backup at 07-DEC-23
Starting backup at 07-DEC-23
channel c1: starting compressed incremental level 0 datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=+DATA/orcl/datafile/system01.dbf
input datafile file number=00002 name=+DATA/orcl/datafile/sysaux.257.1086172033
input datafile file number=00006 name=+DATA/orcl/datafile/prod.273.1086172629
input datafile file number=00003 name=+DATA/orcl/datafile/undotbs1.258.1086172033
input datafile file number=00005 name=+DATA/orcl/datafile/undotbs2.267.1086172237
input datafile file number=00007 name=+DATA/primary/datafile/users.297.1147790221
input datafile file number=00008 name=+DATA/primary/datafile/users.331.1147792495
input datafile file number=00009 name=+DATA/primary/datafile/users.335.1147792667
input datafile file number=00010 name=+DATA/primary/datafile/users.338.1147793229
input datafile file number=00011 name=+DATA/primary/datafile/users.339.1147793259
input datafile file number=00004 name=+DATA/orcl/datafile/users.259.1086172033
input datafile file number=00012 name=+DATA/primary/datafile/users.353.1147806089
input datafile file number=00013 name=+DATA/primary/datafile/users.378.1147818285
channel c1: starting piece 1 at 07-DEC-23
channel c1: finished piece 1 at 07-DEC-23
piece handle=/u01/rman/1613952925-20231207-162df683_1_1 tag=DUPLICATE comment=NONE
channel c1: backup set complete, elapsed time: 00:01:05
channel c1: starting compressed 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 07-DEC-23
channel c1: finished piece 1 at 07-DEC-23
piece handle=/u01/rman/1613952925-20231207-172df6a5_1_1 tag=DUPLICATE comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-DEC-23
Starting backup at 07-DEC-23
current log archived
channel c1: starting compressed archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=139 RECID=387 STAMP=1154980171
input archived log thread=2 sequence=105 RECID=386 STAMP=1154980170
channel c1: starting piece 1 at 07-DEC-23
channel c1: finished piece 1 at 07-DEC-23
piece handle=/u01/rman/1613952925-20231207-182df6ad_1_1 tag=DUPLICATE comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-DEC-23
released channel: c1
RMAN> list backup;
using target database control file instead of recovery catalog
List of Backup Sets
===================
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
12 14.77M DISK 00:00:05 07-DEC-23
BP Key: 12 Status: AVAILABLE Compressed: YES Tag: DUPLICATE
Piece Name: /u01/rman/1613952925-20231207-152df67p_1_1
List of Archived Logs in backup set 12
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 132 2451556 06-DEC-23 2487184 07-DEC-23
1 133 2487184 07-DEC-23 2487294 07-DEC-23
1 134 2487294 07-DEC-23 2489347 07-DEC-23
1 135 2489347 07-DEC-23 2489589 07-DEC-23
1 136 2489589 07-DEC-23 2489693 07-DEC-23
1 137 2489693 07-DEC-23 2489729 07-DEC-23
1 138 2489729 07-DEC-23 2534599 07-DEC-23
2 99 2451561 06-DEC-23 2487182 07-DEC-23
2 100 2487182 07-DEC-23 2487189 07-DEC-23
2 101 2487686 07-DEC-23 2487691 07-DEC-23
2 102 2487691 07-DEC-23 2488926 07-DEC-23
2 103 2488926 07-DEC-23 2489705 07-DEC-23
2 104 2489705 07-DEC-23 2534605 07-DEC-23
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
13 Incr 0 288.46M DISK 00:00:58 07-DEC-23
BP Key: 13 Status: AVAILABLE Compressed: YES Tag: DUPLICATE
Piece Name: /u01/rman/1613952925-20231207-162df683_1_1
List of Datafiles in backup set 13
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 0 Incr 2534630 07-DEC-23 +DATA/orcl/datafile/system01.dbf
2 0 Incr 2534630 07-DEC-23 +DATA/orcl/datafile/sysaux.257.1086172033
3 0 Incr 2534630 07-DEC-23 +DATA/orcl/datafile/undotbs1.258.1086172033
4 0 Incr 2534630 07-DEC-23 +DATA/orcl/datafile/users.259.1086172033
5 0 Incr 2534630 07-DEC-23 +DATA/orcl/datafile/undotbs2.267.1086172237
6 0 Incr 2534630 07-DEC-23 +DATA/orcl/datafile/prod.273.1086172629
7 0 Incr 2534630 07-DEC-23 +DATA/primary/datafile/users.297.1147790221
8 0 Incr 2534630 07-DEC-23 +DATA/primary/datafile/users.331.1147792495
9 0 Incr 2534630 07-DEC-23 +DATA/primary/datafile/users.335.1147792667
10 0 Incr 2534630 07-DEC-23 +DATA/primary/datafile/users.338.1147793229
11 0 Incr 2534630 07-DEC-23 +DATA/primary/datafile/users.339.1147793259
12 0 Incr 2534630 07-DEC-23 +DATA/primary/datafile/users.353.1147806089
13 0 Incr 2534630 07-DEC-23 +DATA/primary/datafile/users.378.1147818285
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
14 Incr 0 1.08M DISK 00:00:03 07-DEC-23
BP Key: 14 Status: AVAILABLE Compressed: YES Tag: DUPLICATE
Piece Name: /u01/rman/1613952925-20231207-172df6a5_1_1
SPFILE Included: Modification time: 07-DEC-23
SPFILE db_unique_name: PRIMARY
Control File Included: Ckp SCN: 2534707 Ckp time: 07-DEC-23
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
15 86.00K DISK 00:00:00 07-DEC-23
BP Key: 15 Status: AVAILABLE Compressed: YES Tag: DUPLICATE
Piece Name: /u01/rman/1613952925-20231207-182df6ad_1_1
List of Archived Logs in backup set 15
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 139 2534599 07-DEC-23 2534722 07-DEC-23
2 105 2534605 07-DEC-23 2534719 07-DEC-23
RMAN>
登录备份目录查看备份文件
创建备库监听文件,静态监听。
[oracle@oracle admin]$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.99)(PORT = 1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = orcl)
)
)
创建完成后,启动监听
[oracle@oracle orcl]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 09-DEC-2023 17:46:13
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.99)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 07-DEC-2023 20:08:01
Uptime 1 days 21 hr. 38 min. 11 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/oracle/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.99)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
创建参数文件
touch /home/oracle/pfile.ora
输入内容如下:
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/orcl/controlfile/control01.ctl','/u01/app/oracle/oradata/orcl/controlfile/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_file_name_convert='+DATA/primary/datafile','/u01/app/oracle/oradata/orcl/datafile','+DATA/orcl/datafile','/u01/app/oracle/oradata/orcl/datafile','+DATA/orcl/tempfile','/u01/app/oracle/oradata/orcl/tempfile'
*.db_name='orcl'
*.db_recovery_file_dest_size=6005194752
*.db_recovery_file_dest='/u01/app/oracle/fast_recover_area'
*.diagnostic_dest='/u01/app/oracle'
*.log_archive_dest_1='location=/u01/app/oracle/oradata/orcl/archivelog'
*.log_archive_format='%t_%s_%r.dbf'
*.log_file_name_convert='+DATA/orcl/onlinelog','/u01/app/oracle/oradata/orcl/onlinelog','+DATA/primary/onlinelog','/u01/app/oracle/oradata/orcl/onlinelog'
*.memory_target=300m
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='exclusive'
*.service_names='orcl'
*.undo_tablespace='UNDOTBS1'
创建必须的目录
mkdir -p /u01/app/oracle/admin/orcl/adump
mkdir -p /u01/app/oracle/oradata/orcl/controlfile
mkdir -p /u01/app/oracle/oradata/orcl/datafile
mkdir -p /u01/app/oracle/oradata/orcl/tempfile
mkdir -p /u01/app/oracle/oradata/orcl/archivelog
mkdir -p /u01/app/oracle/oradata/orcl/onlinelog
mkdir -p /u01/app/oracle/fast_recover_area
创建SPFILE文件,并启动数据库到nomount模式
进行恢复操作,操作在是RAC1节点进行备份的,备份的最后归档日志SCN号如下
List of Archived Logs in backup set 15
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 139 2534599 07-DEC-23 2534722 07-DEC-23
2 105 2534605 07-DEC-23 2534719 07-DEC-23
从结果上看duplicate 会恢复到最后2节点最后1个归档的next SCN也就是 set until scn 2534719(这里应该是一致性的SCN)
之后自动open resetlogs打开数据库完成恢复。
主要执行恢复的有效命令是:
rman auxiliary /
DUPLICATE DATABASE TO orcl BACKUP LOCATION '/u01/rman/' NOFILENAMECHECK;
以下是输出结果
[oracle@oracle admin]$ rman auxiliary /
Recovery Manager: Release 11.2.0.4.0 - Production on Thu Dec 7 20:09:04 2023
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to auxiliary database: ORCL (not mounted)
RMAN> DUPLICATE DATABASE TO orcl BACKUP LOCATION '/u01/rman/' NOFILENAMECHECK;
Starting Duplicate Db at 07-DEC-23
contents of Memory Script:
{
sql clone "alter system set db_name =
''ORCL'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''ORCL'' comment=
''Modified by RMAN duplicate'' scope=spfile";
shutdown clone immediate;
startup clone force nomount
restore clone primary controlfile from '/u01/rman/1613952925-20231207-172df6a5_1_1';
alter clone database mount;
}
executing Memory Script
sql statement: alter system set db_name = ''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set db_unique_name = ''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area 313159680 bytes
Fixed Size 2252824 bytes
Variable Size 213913576 bytes
Database Buffers 92274688 bytes
Redo Buffers 4718592 bytes
Starting restore at 07-DEC-23
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=63 device type=DISK
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/u01/app/oracle/oradata/orcl/controlfile/control01.ctl
output file name=/u01/app/oracle/oradata/orcl/controlfile/control02.ctl
Finished restore at 07-DEC-23
database mounted
released channel: ORA_AUX_DISK_1
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=63 device type=DISK
contents of Memory Script:
{
set until scn 2534719;
set newname for datafile 1 to
"/u01/app/oracle/oradata/orcl/datafile/system01.dbf";
set newname for datafile 2 to
"/u01/app/oracle/oradata/orcl/datafile/sysaux.257.1086172033";
set newname for datafile 3 to
"/u01/app/oracle/oradata/orcl/datafile/undotbs1.258.1086172033";
set newname for datafile 4 to
"/u01/app/oracle/oradata/orcl/datafile/users.259.1086172033";
set newname for datafile 5 to
"/u01/app/oracle/oradata/orcl/datafile/undotbs2.267.1086172237";
set newname for datafile 6 to
"/u01/app/oracle/oradata/orcl/datafile/prod.273.1086172629";
set newname for datafile 7 to
"/u01/app/oracle/oradata/orcl/datafile/users.297.1147790221";
set newname for datafile 8 to
"/u01/app/oracle/oradata/orcl/datafile/users.331.1147792495";
set newname for datafile 9 to
"/u01/app/oracle/oradata/orcl/datafile/users.335.1147792667";
set newname for datafile 10 to
"/u01/app/oracle/oradata/orcl/datafile/users.338.1147793229";
set newname for datafile 11 to
"/u01/app/oracle/oradata/orcl/datafile/users.339.1147793259";
set newname for datafile 12 to
"/u01/app/oracle/oradata/orcl/datafile/users.353.1147806089";
set newname for datafile 13 to
"/u01/app/oracle/oradata/orcl/datafile/users.378.1147818285";
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
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 07-DEC-23
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/orcl/datafile/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/orcl/datafile/sysaux.257.1086172033
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/orcl/datafile/undotbs1.258.1086172033
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/orcl/datafile/users.259.1086172033
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/orcl/datafile/undotbs2.267.1086172237
channel ORA_AUX_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/orcl/datafile/prod.273.1086172629
channel ORA_AUX_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/orcl/datafile/users.297.1147790221
channel ORA_AUX_DISK_1: restoring datafile 00008 to /u01/app/oracle/oradata/orcl/datafile/users.331.1147792495
channel ORA_AUX_DISK_1: restoring datafile 00009 to /u01/app/oracle/oradata/orcl/datafile/users.335.1147792667
channel ORA_AUX_DISK_1: restoring datafile 00010 to /u01/app/oracle/oradata/orcl/datafile/users.338.1147793229
channel ORA_AUX_DISK_1: restoring datafile 00011 to /u01/app/oracle/oradata/orcl/datafile/users.339.1147793259
channel ORA_AUX_DISK_1: restoring datafile 00012 to /u01/app/oracle/oradata/orcl/datafile/users.353.1147806089
channel ORA_AUX_DISK_1: restoring datafile 00013 to /u01/app/oracle/oradata/orcl/datafile/users.378.1147818285
channel ORA_AUX_DISK_1: reading from backup piece /u01/rman/1613952925-20231207-162df683_1_1
channel ORA_AUX_DISK_1: piece handle=/u01/rman/1613952925-20231207-162df683_1_1 tag=DUPLICATE
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:05
Finished restore at 07-DEC-23
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=14 STAMP=1154981440 file name=/u01/app/oracle/oradata/orcl/datafile/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=15 STAMP=1154981440 file name=/u01/app/oracle/oradata/orcl/datafile/sysaux.257.1086172033
datafile 3 switched to datafile copy
input datafile copy RECID=16 STAMP=1154981440 file name=/u01/app/oracle/oradata/orcl/datafile/undotbs1.258.1086172033
datafile 4 switched to datafile copy
input datafile copy RECID=17 STAMP=1154981440 file name=/u01/app/oracle/oradata/orcl/datafile/users.259.1086172033
datafile 5 switched to datafile copy
input datafile copy RECID=18 STAMP=1154981440 file name=/u01/app/oracle/oradata/orcl/datafile/undotbs2.267.1086172237
datafile 6 switched to datafile copy
input datafile copy RECID=19 STAMP=1154981440 file name=/u01/app/oracle/oradata/orcl/datafile/prod.273.1086172629
datafile 7 switched to datafile copy
input datafile copy RECID=20 STAMP=1154981440 file name=/u01/app/oracle/oradata/orcl/datafile/users.297.1147790221
datafile 8 switched to datafile copy
input datafile copy RECID=21 STAMP=1154981440 file name=/u01/app/oracle/oradata/orcl/datafile/users.331.1147792495
datafile 9 switched to datafile copy
input datafile copy RECID=22 STAMP=1154981440 file name=/u01/app/oracle/oradata/orcl/datafile/users.335.1147792667
datafile 10 switched to datafile copy
input datafile copy RECID=23 STAMP=1154981440 file name=/u01/app/oracle/oradata/orcl/datafile/users.338.1147793229
datafile 11 switched to datafile copy
input datafile copy RECID=24 STAMP=1154981440 file name=/u01/app/oracle/oradata/orcl/datafile/users.339.1147793259
datafile 12 switched to datafile copy
input datafile copy RECID=25 STAMP=1154981440 file name=/u01/app/oracle/oradata/orcl/datafile/users.353.1147806089
datafile 13 switched to datafile copy
input datafile copy RECID=26 STAMP=1154981440 file name=/u01/app/oracle/oradata/orcl/datafile/users.378.1147818285
contents of Memory Script:
{
set until scn 2534719;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 07-DEC-23
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=139
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=2 sequence=105
channel ORA_AUX_DISK_1: reading from backup piece /u01/rman/1613952925-20231207-182df6ad_1_1
channel ORA_AUX_DISK_1: piece handle=/u01/rman/1613952925-20231207-182df6ad_1_1 tag=DUPLICATE
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/oradata/orcl/archivelog/1_139_1086172194.dbf thread=1 sequence=139
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/2_105_1086172194.dbf thread=2 sequence=105
channel clone_default: deleting archived log(s)
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_139_1086172194.dbf RECID=1 STAMP=1154981441
channel clone_default: deleting archived log(s)
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/2_105_1086172194.dbf RECID=2 STAMP=1154981441
media recovery complete, elapsed time: 00:00:00
Finished recover at 07-DEC-23
Oracle instance started
Total System Global Area 313159680 bytes
Fixed Size 2252824 bytes
Variable Size 213913576 bytes
Database Buffers 92274688 bytes
Redo Buffers 4718592 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''ORCL'' 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
sql statement: alter system set db_name = ''ORCL'' 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 313159680 bytes
Fixed Size 2252824 bytes
Variable Size 213913576 bytes
Database Buffers 92274688 bytes
Redo Buffers 4718592 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORCL" RESETLOGS ARCHIVELOG
MAXLOGFILES 192
MAXLOGMEMBERS 3
MAXDATAFILES 1024
MAXINSTANCES 32
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/u01/app/oracle/oradata/orcl/onlinelog/group_1.262.1086172195', '/u01/app/oracle/oradata/orcl/onlinelog/group_1.263.1086172197' ) SIZE 50 M REUSE,
GROUP 2 ( '/u01/app/oracle/oradata/orcl/onlinelog/group_2.264.1086172199', '/u01/app/oracle/oradata/orcl/onlinelog/group_2.265.1086172203' ) SIZE 50 M REUSE
DATAFILE
'/u01/app/oracle/oradata/orcl/datafile/system01.dbf'
CHARACTER SET WE8MSWIN1252
sql statement: ALTER DATABASE ADD LOGFILE
INSTANCE 'i2'
GROUP 3 ( '/u01/app/oracle/oradata/orcl/onlinelog/group_3.268.1086172281', '/u01/app/oracle/oradata/orcl/onlinelog/group_3.269.1086172283' ) SIZE 50 M REUSE,
GROUP 4 ( '/u01/app/oracle/oradata/orcl/onlinelog/group_4.270.1086172287', '/u01/app/oracle/oradata/orcl/onlinelog/group_4.271.1086172289' ) SIZE 50 M REUSE
contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/app/oracle/oradata/orcl/tempfile/temp.266.1086172211";
switch clone tempfile all;
catalog clone datafilecopy "/u01/app/oracle/oradata/orcl/datafile/sysaux.257.1086172033",
"/u01/app/oracle/oradata/orcl/datafile/undotbs1.258.1086172033",
"/u01/app/oracle/oradata/orcl/datafile/users.259.1086172033",
"/u01/app/oracle/oradata/orcl/datafile/undotbs2.267.1086172237",
"/u01/app/oracle/oradata/orcl/datafile/prod.273.1086172629",
"/u01/app/oracle/oradata/orcl/datafile/users.297.1147790221",
"/u01/app/oracle/oradata/orcl/datafile/users.331.1147792495",
"/u01/app/oracle/oradata/orcl/datafile/users.335.1147792667",
"/u01/app/oracle/oradata/orcl/datafile/users.338.1147793229",
"/u01/app/oracle/oradata/orcl/datafile/users.339.1147793259",
"/u01/app/oracle/oradata/orcl/datafile/users.353.1147806089",
"/u01/app/oracle/oradata/orcl/datafile/users.378.1147818285";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/orcl/tempfile/temp.266.1086172211 in control file
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/datafile/sysaux.257.1086172033 RECID=1 STAMP=1154981457
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/datafile/undotbs1.258.1086172033 RECID=2 STAMP=1154981457
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/datafile/users.259.1086172033 RECID=3 STAMP=1154981457
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/datafile/undotbs2.267.1086172237 RECID=4 STAMP=1154981457
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/datafile/prod.273.1086172629 RECID=5 STAMP=1154981457
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/datafile/users.297.1147790221 RECID=6 STAMP=1154981457
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/datafile/users.331.1147792495 RECID=7 STAMP=1154981457
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/datafile/users.335.1147792667 RECID=8 STAMP=1154981457
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/datafile/users.338.1147793229 RECID=9 STAMP=1154981457
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/datafile/users.339.1147793259 RECID=10 STAMP=1154981457
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/datafile/users.353.1147806089 RECID=11 STAMP=1154981457
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/datafile/users.378.1147818285 RECID=12 STAMP=1154981457
datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=1154981457 file name=/u01/app/oracle/oradata/orcl/datafile/sysaux.257.1086172033
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=1154981457 file name=/u01/app/oracle/oradata/orcl/datafile/undotbs1.258.1086172033
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=1154981457 file name=/u01/app/oracle/oradata/orcl/datafile/users.259.1086172033
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=1154981457 file name=/u01/app/oracle/oradata/orcl/datafile/undotbs2.267.1086172237
datafile 6 switched to datafile copy
input datafile copy RECID=5 STAMP=1154981457 file name=/u01/app/oracle/oradata/orcl/datafile/prod.273.1086172629
datafile 7 switched to datafile copy
input datafile copy RECID=6 STAMP=1154981457 file name=/u01/app/oracle/oradata/orcl/datafile/users.297.1147790221
datafile 8 switched to datafile copy
input datafile copy RECID=7 STAMP=1154981457 file name=/u01/app/oracle/oradata/orcl/datafile/users.331.1147792495
datafile 9 switched to datafile copy
input datafile copy RECID=8 STAMP=1154981457 file name=/u01/app/oracle/oradata/orcl/datafile/users.335.1147792667
datafile 10 switched to datafile copy
input datafile copy RECID=9 STAMP=1154981457 file name=/u01/app/oracle/oradata/orcl/datafile/users.338.1147793229
datafile 11 switched to datafile copy
input datafile copy RECID=10 STAMP=1154981457 file name=/u01/app/oracle/oradata/orcl/datafile/users.339.1147793259
datafile 12 switched to datafile copy
input datafile copy RECID=11 STAMP=1154981457 file name=/u01/app/oracle/oradata/orcl/datafile/users.353.1147806089
datafile 13 switched to datafile copy
input datafile copy RECID=12 STAMP=1154981457 file name=/u01/app/oracle/oradata/orcl/datafile/users.378.1147818285
Reenabling controlfile options for auxiliary database
Executing: alter database force logging
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 07-DEC-23
检查文件是否自动转换
standby redolog 没有带过来
大功告成!
在备份节点RAC1上查看一下控制文件在哪个备份片里
去恢复节点,进行恢复控制文件,启动库到mount模式。
run{
restore controlfile from '/u01/rman/1613952925-20231207-172df6a5_1_1';
sql 'alter database mount';
}
执行结果
RMAN> run{
restore controlfile from '/u01/rman/1613952925-20231207-172df6a5_1_1';
sql 'alter database mount';
}2> 3> 4>
Starting restore at 09-DEC-23
using channel ORA_DISK_1
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/orcl/controlfile/control01.ctl
output file name=/u01/app/oracle/oradata/orcl/controlfile/control02.ctl
Finished restore at 09-DEC-23
sql statement: alter database mount
released channel: ORA_DISK_1
下一步恢复数据文件,需要把备份片都注册到控制文件(因为之前的备份完控制文件之后又备份了几个归档,默认控制文件里没有,需要注册一下)。
catalog start with '/u01/rman/';
RMAN> catalog start with '/u01/rman/';
Starting implicit crosscheck backup at 09-DEC-23
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=192 device type=DISK
Crosschecked 2 objects
Finished implicit crosscheck backup at 09-DEC-23
Starting implicit crosscheck copy at 09-DEC-23
using channel ORA_DISK_1
Crosschecked 2 objects
Finished implicit crosscheck copy at 09-DEC-23
searching for all files in the recovery area
cataloging files...
no files cataloged
searching for all files that match the pattern /u01/rman/
List of Files Unknown to the Database
=====================================
File Name: /u01/rman/1613952925-20231207-172df6a5_1_1
File Name: /u01/rman/1613952925-20231207-182df6ad_1_1
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /u01/rman/1613952925-20231207-172df6a5_1_1
File Name: /u01/rman/1613952925-20231207-182df6ad_1_1
执行如下脚本进行恢复
run {
allocate channel c1 device type disk;
set until scn 2534719;
set newname for database to '/u01/app/oracle/oradata/orcl/%b';
restore database;
switch datafile all;
switch tempfile all;
recover database ;
}
显示结果
RMAN> run {
allocate channel c1 device type disk;
set until scn 2534719;
set newname for database to '/u01/app/oracle/oradata/orcl/%b';
restore database;
switch datafile all;
switch tempfile all;
recover database ;
}2> 3> 4> 5> 6> 7> 8> 9>
released channel: ORA_DISK_1
allocated channel: c1
channel c1: SID=192 device type=DISK
executing command: SET until clause
executing command: SET NEWNAME
Starting restore at 09-DEC-23
channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
channel c1: restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system01.dbf
channel c1: restoring datafile 00002 to /u01/app/oracle/oradata/orcl/sysaux.257.1086172033
channel c1: restoring datafile 00003 to /u01/app/oracle/oradata/orcl/undotbs1.258.1086172033
channel c1: restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users.259.1086172033
channel c1: restoring datafile 00005 to /u01/app/oracle/oradata/orcl/undotbs2.267.1086172237
channel c1: restoring datafile 00006 to /u01/app/oracle/oradata/orcl/prod.273.1086172629
channel c1: restoring datafile 00007 to /u01/app/oracle/oradata/orcl/users.297.1147790221
channel c1: restoring datafile 00008 to /u01/app/oracle/oradata/orcl/users.331.1147792495
channel c1: restoring datafile 00009 to /u01/app/oracle/oradata/orcl/users.335.1147792667
channel c1: restoring datafile 00010 to /u01/app/oracle/oradata/orcl/users.338.1147793229
channel c1: restoring datafile 00011 to /u01/app/oracle/oradata/orcl/users.339.1147793259
channel c1: restoring datafile 00012 to /u01/app/oracle/oradata/orcl/users.353.1147806089
channel c1: restoring datafile 00013 to /u01/app/oracle/oradata/orcl/users.378.1147818285
channel c1: reading from backup piece /u01/rman/1613952925-20231207-162df683_1_1
channel c1: piece handle=/u01/rman/1613952925-20231207-162df683_1_1 tag=DUPLICATE
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:01:05
Finished restore at 09-DEC-23
datafile 1 switched to datafile copy
input datafile copy RECID=17 STAMP=1155142216 file name=/u01/app/oracle/oradata/orcl/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=18 STAMP=1155142216 file name=/u01/app/oracle/oradata/orcl/sysaux.257.1086172033
datafile 3 switched to datafile copy
input datafile copy RECID=19 STAMP=1155142216 file name=/u01/app/oracle/oradata/orcl/undotbs1.258.1086172033
datafile 4 switched to datafile copy
input datafile copy RECID=20 STAMP=1155142216 file name=/u01/app/oracle/oradata/orcl/users.259.1086172033
datafile 5 switched to datafile copy
input datafile copy RECID=21 STAMP=1155142216 file name=/u01/app/oracle/oradata/orcl/undotbs2.267.1086172237
datafile 6 switched to datafile copy
input datafile copy RECID=22 STAMP=1155142216 file name=/u01/app/oracle/oradata/orcl/prod.273.1086172629
datafile 7 switched to datafile copy
input datafile copy RECID=23 STAMP=1155142216 file name=/u01/app/oracle/oradata/orcl/users.297.1147790221
datafile 8 switched to datafile copy
input datafile copy RECID=24 STAMP=1155142216 file name=/u01/app/oracle/oradata/orcl/users.331.1147792495
datafile 9 switched to datafile copy
input datafile copy RECID=25 STAMP=1155142217 file name=/u01/app/oracle/oradata/orcl/users.335.1147792667
datafile 10 switched to datafile copy
input datafile copy RECID=26 STAMP=1155142217 file name=/u01/app/oracle/oradata/orcl/users.338.1147793229
datafile 11 switched to datafile copy
input datafile copy RECID=27 STAMP=1155142217 file name=/u01/app/oracle/oradata/orcl/users.339.1147793259
datafile 12 switched to datafile copy
input datafile copy RECID=28 STAMP=1155142217 file name=/u01/app/oracle/oradata/orcl/users.353.1147806089
datafile 13 switched to datafile copy
input datafile copy RECID=29 STAMP=1155142217 file name=/u01/app/oracle/oradata/orcl/users.378.1147818285
renamed tempfile 1 to /u01/app/oracle/oradata/orcl/temp.266.1086172211 in control file
Starting recover at 09-DEC-23
starting media recovery
channel c1: starting archived log restore to default destination
channel c1: restoring archived log
archived log thread=1 sequence=139
channel c1: restoring archived log
archived log thread=2 sequence=105
channel c1: reading from backup piece /u01/rman/1613952925-20231207-182df6ad_1_1
channel c1: piece handle=/u01/rman/1613952925-20231207-182df6ad_1_1 tag=DUPLICATE
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/oradata/orcl/archivelog1_139_1086172194.dbf thread=1 sequence=139
archived log file name=/u01/app/oracle/oradata/orcl/archivelog2_105_1086172194.dbf thread=2 sequence=105
media recovery complete, elapsed time: 00:00:00
Finished recover at 09-DEC-23
released channel: c1
RMAN>
恢复完成之后直接open resetlogs打开数据库
[oracle@oracle orcl]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sat Dec 9 16:51:32 2023
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> alter database open resetlogs;
Database altered.
4.2、恢复后验证
查看数据文件及日志文件(由于没有重命名redolog位置,也没有+DATA目录,redo日志文件会自动在闪回区重建)
SQL> set pagesize 200
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/sysaux.257.1086172033
/u01/app/oracle/oradata/orcl/undotbs1.258.1086172033
/u01/app/oracle/oradata/orcl/users.259.1086172033
/u01/app/oracle/oradata/orcl/undotbs2.267.1086172237
/u01/app/oracle/oradata/orcl/prod.273.1086172629
/u01/app/oracle/oradata/orcl/users.297.1147790221
/u01/app/oracle/oradata/orcl/users.331.1147792495
/u01/app/oracle/oradata/orcl/users.335.1147792667
/u01/app/oracle/oradata/orcl/users.338.1147793229
/u01/app/oracle/oradata/orcl/users.339.1147793259
/u01/app/oracle/oradata/orcl/users.353.1147806089
/u01/app/oracle/oradata/orcl/users.378.1147818285
13 rows selected.
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/fast_recover_area/ORCL/onlinelog/o1_mf_2_lq8bo99h_.log
/u01/app/oracle/fast_recover_area/ORCL/onlinelog/o1_mf_3_lq8bobtw_.log
/u01/app/oracle/fast_recover_area/ORCL/onlinelog/o1_mf_1_lq8bo6q1_.log
/u01/app/oracle/fast_recover_area/ORCL/onlinelog/o1_mf_4_lq8boc7c_.log
/u01/app/oracle/fast_recover_area/ORCL/onlinelog/o1_mf_11_lq8bogz6_.log
/u01/app/oracle/fast_recover_area/ORCL/onlinelog/o1_mf_12_lq8boh9w_.log
/u01/app/oracle/fast_recover_area/ORCL/onlinelog/o1_mf_13_lq8bohxm_.log
/u01/app/oracle/fast_recover_area/ORCL/onlinelog/o1_mf_14_lq8boj6r_.log
/u01/app/oracle/fast_recover_area/ORCL/onlinelog/o1_mf_15_lq8bojg2_.log
/u01/app/oracle/fast_recover_area/ORCL/onlinelog/o1_mf_21_lq8bojol_.log
/u01/app/oracle/fast_recover_area/ORCL/onlinelog/o1_mf_22_lq8bojxk_.log
/u01/app/oracle/fast_recover_area/ORCL/onlinelog/o1_mf_23_lq8bok6d_.log
/u01/app/oracle/fast_recover_area/ORCL/onlinelog/o1_mf_24_lq8bokgh_.log
/u01/app/oracle/fast_recover_area/ORCL/onlinelog/o1_mf_25_lq8bokph_.log
14 rows selected.
SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/temp.266.1086172211
1、两种方法都能完成自动重命名文件的功能;
2、方法1其实只要事先在参数文件里加上convert参数,恢复也只需要1条命令,就能自动修改文件名、恢复到最后的SCN;duplicate不会恢复standby redolog;
3、方法2需要先手动恢复控制文件、再注册备份片、再恢复到批定的SCN,然后再open resetlogs(当然这堆也可以考虑写到1个脚本里);
4、相比来说方法1采用duplicate更省心,一步到位。
需要注意的是使用方法1恢复时
如果指定SCN进行恢复,会提示报错,按SCN恢复需要连target库或是catalog库
RMAN> DUPLICATE DATABASE TO orcl BACKUP LOCATION '/u01/rman/' NOFILENAMECHECK until scn 2534722;
Starting Duplicate Db at 07-DEC-23
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 12/07/2023 20:43:24
RMAN-05501: aborting duplication of target database
RMAN-05542: Only UNTIL TIME can be used with DUPLICATE without TARGET and CATALOG connections
如果指定时间进行恢复,而备份里没这些归档,那么会失败。
DUPLICATE DATABASE TO orcl BACKUP LOCATION '/u01/rman/' NOFILENAMECHECK UNTIL TIME "TO_DATE('07-DEC-2023 20:27:42','DD-MON-YYYYHH24:MI:SS')"
尝试输出如下:
RMAN-03015: error occurred in stored script Memory Script
RMAN-06136: ORACLE error from auxiliary database: ORA-01507: database not mounted
ORA-06512: at "SYS.X$DBMS_RCVMAN", line 13658
ORA-06512: at line 1
RMAN-06617: UNTIL TIME (07-DEC-23) is ahead of last NEXT TIME in archived logs (07-DEC-23)
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 12/07/2023 20:49:26
RMAN-05501: aborting duplication of target database
参考:
Perform Backup Based RMAN DUPLICATE Without Connecting To Target Database For Both Disk & Tape Backups (Doc ID 1375864.1)
ORACLE-BASE - Duplicate a Database Using RMAN in Oracle Database 11g Release 2
How to duplicate database using RMAN backup set - DBACLASS DBACLASS
也欢迎关注我的公众号【徐sir的IT之路】,一起学习!
————————————————————————————
公众号:徐sir的IT之路
CSDN :徐sir(徐慧阳)_数据库记录,系统集成-CSDN博客
墨天轮:徐sir的个人主页 - 墨天轮
PGFANS:PGFans问答社区:全球唯一的PostgreSQL中文技术交流社区
————————————————————————————