将ASM备份还原为非ASM并从RAC还原为单个实例

发布于:2021-01-26 11:21:24

0

121

0

ASM RAC ASM备份 RAC还原

场景:

1) 我们希望在测试非RAC环境中恢复在两节点RAC环境上运行的生产数据库

2) 我们要还原驻留在非ASM文件系统中的ASM磁盘组上的备份。

注意:

生产数据库orcl有两个名为orcl1和orcl2的实例。数据库将在测试环境中还原为名为orcl的单实例数据库。

生产数据库文件和FRA位于ASM磁盘+数据上,目标服务器上要还原文件的文件系统位置为/u01/app/oracle/oradata/orcl。FRA将是文件系统位置/u01/app/oracle/ flash_recovery_area。

在这种情况下,数据库文件将是OMF。通过使用一个不同的SET NEWNAME命令,如果我们不想将文件还原为OMF,我们可以。为了更易于管理,我不希望使用OMF,但在这个示例中显示了OMF。

这些是数据库、控制文件和archivelog备份的备份部分,它们位于ASM磁盘组+数据中的源服务器上。

+DATA/orcl/backupset/2013_02_18/nnndf0_tag20130218t093350_0.345.807701631
+DATA/orcl/backupset/2013_02_18/ncnnf0_tag20130218t093811_0.337.807701893
+DATA/orcl/backupset/2013_02_18/annnf0_tag20130218t093927_0.325.807701967

在源服务器上,我们在本地文件系统上创建一个目录,在那里我们将从ASM磁盘组中复制这些文件。我们还可以NFS挂载一个远程文件系统,该系统有足够的磁盘空间,以防备份块太大而本地文件系统上没有足够的空间。

由于它是11gR2网格基础设施,我们作为拥有GI软件的网格用户连接,并使用asmcmd cp命令将文件从ASM复制到文件系统。

[oracle@kens-racnode1 backup]$ su - grid
Password:
[grid@kens-racnode1 ~]$ . oraenv
ORACLE_SID = [grid] ? +ASM1
The Oracle base has been set to /u01/app/grid

grid@kens-racnode1 ~]$ asmcmd
ASMCMD> cd DATA
ASMCMD> cd ORCL
ASMCMD> cd BACKUPSET
ASMCMD> ls
2013_02_18/
ASMCMD> cd *
ASMCMD> cp nnndf0_tag20130218t093350_0.345.807701631 /u02/app/backup
copying +DATA/ORCL/BACKUPSET/2013_02_18/nnndf0_tag20130218t093350_0.345.807701631 -> /u02/app/backup/nnndf0_tag20130218t093350_0.345.807701631
ASMCMD> cp ncnnf0_tag20130218t093811_0.337.807701893  /u02/app/backup
copying +DATA/ORCL/BACKUPSET/2013_02_18/ncnnf0_tag20130218t093811_0.337.807701893 -> /u02/app/backup/ncnnf0_tag20130218t093811_0.337.807701893
ASMCMD> cp annnf0_tag20130218t093927_0.325.807701967 /u02/app/backup
copying +DATA/ORCL/BACKUPSET/2013_02_18/annnf0_tag20130218t093927_0.325.807701967 -> /u02/app/backup/annnf0_tag20130218t093927_0.325.807701967

现在将这些文件从源服务器上的文件系统scp到目标服务器上的文件系统。

复制密码文件并初始ora从源服务器到目标服务器的一个RAC实例,并进行所需的更改,因为我们将把目标服务器上的数据库作为非RAC单实例数据库打开。

例如,这就是初始ora对于单实例数据库orcl。

orcl.__db_cache_size=603979776
orcl.__java_pool_size=50331648
orcl.__large_pool_size=16777216
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=603979776
orcl.__sga_target=1157627904
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=469762048
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='DB'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/oradata/orcl/control02.ctl'
*.db_block_size=8192
*.db_file_name_convert='+DATA/orcl/onlinelog/','/u01/app/oracle/oradata/orcl/'
*.db_create_online_log_dest_1=’ /u01/app/oracle/oradata/'
*.db_domain='mydb.domain'
*.db_name='orcl'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=4G
*.diagnostic_dest='/u01/app/oracle'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=1761607680
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
orcl.undo_tablespace='UNDOTBS1'

在目标服务器上,设置环境并以NOMOUNT模式启动数据库。

SQL> startup nomount;

ORACLE instance started.

Total System Global Area 1753731072 bytes
Fixed Size                  2229144 bytes
Variable Size            1140853864 bytes
Database Buffers          603979776 bytes
Redo Buffers                6668288 bytes

还原控制文件。

RMAN> restore controlfile from '/u01/app/oracle/backup/ncnnf0_tag20130218t093811_0.337.807701893';

Starting restore at 19-FEB-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=134 device type=DISK

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/control01.ctl
output file name=/u01/app/oracle/oradata/orcl/control02.ctl
Finished restore at 19-FEB-13

装载数据库并对RMAN备份条目进行编目。

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1



RMAN> catalog start with '/u01/app/oracle/backup/';

searching for all files that match the pattern /u01/app/oracle/backup/

List of Files Unknown to the Database
=====================================
File Name: /u01/app/oracle/backup/ncnnf0_tag20130218t093811_0.337.807701893
File Name: /u01/app/oracle/backup/nnndf0_tag20130218t093350_0.345.807701631
File Name: /u01/app/oracle/backup/annnf0_tag20130218t093927_0.325.807701967

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/app/oracle/backup/ncnnf0_tag20130218t093811_0.337.807701893
File Name: /u01/app/oracle/backup/nnndf0_tag20130218t093350_0.345.807701631
File Name: /u01/app/oracle/backup/annnf0_tag20130218t093927_0.325.807701967

这是我们将使用的RMAN脚本:

run {
SET NEWNAME FOR DATABASE   TO  '/u01/app/oracle/oradata/orcl/%b';
SET NEWNAME FOR tempfile  1 TO  '/u01/app/oracle/oradata/orcl/%b';
restore database;
switch datafile all;
switch tempfile all;
}

执行相同的。

RMAN> run {
SET NEWNAME FOR DATABASE   TO  '/u01/app/oracle/oradata/orcl/%b';
SET NEWNAME FOR tempfile  1 TO  '/u01/app/oracle/oradata/orcl/%b';
restore database;
switch datafile all;
switch tempfile all;
}
2> 3> 4> 5> 6> 7>
executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 21-FEB-13
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system.260.787036171
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/orcl/sysaux.261.787036171
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/orcl/undotbs1.273.787036171
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users.266.787036173
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/orcl/example.262.787036303
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/orcl/undotbs2.268.787036459
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/orcl/ggs_data.327.798611507
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/backup/nnndf0_tag20130218t093350_0.345.807701631
channel ORA_DISK_1: piece handle=/u01/app/oracle/backup/nnndf0_tag20130218t093350_0.345.807701631 tag=TAG20130218T093350
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 21-FEB-13

datafile 1 switched to datafile copy
input datafile copy RECID=9 STAMP=807958250 file name=/u01/app/oracle/oradata/orcl/system.260.787036171
datafile 2 switched to datafile copy
input datafile copy RECID=10 STAMP=807958250 file name=/u01/app/oracle/oradata/orcl/sysaux.261.787036171
datafile 3 switched to datafile copy
input datafile copy RECID=11 STAMP=807958250 file name=/u01/app/oracle/oradata/orcl/undotbs1.273.787036171
datafile 4 switched to datafile copy
input datafile copy RECID=12 STAMP=807958250 file name=/u01/app/oracle/oradata/orcl/users.266.787036173
datafile 5 switched to datafile copy
input datafile copy RECID=13 STAMP=807958250 file name=/u01/app/oracle/oradata/orcl/example.262.787036303
datafile 6 switched to datafile copy
input datafile copy RECID=14 STAMP=807958250 file name=/u01/app/oracle/oradata/orcl/undotbs2.268.787036459
datafile 7 switched to datafile copy
input datafile copy RECID=15 STAMP=807958250 file name=/u01/app/oracle/oradata/orcl/ggs_data.327.798611507

renamed tempfile 1 to /u01/app/oracle/oradata/orcl/temp.263.787036293 in control file

我们现在需要恢复数据库。

这是我们将使用的脚本。

注意我们是如何得到序列号145的

run {
set until sequence 145 thread 1;
recover database;
}

我们需要确定将在SET UNTIL命令中使用的归档日志序列号。RMAN将执行数据库恢复,直到我们需要确定的日志序列号。

运行ARCHIVELOG的RMAN命令列表备份。

请注意每个线程的上一次或最新存档日志备份(因为此备份是从RAC数据库获取的)。

然后在两个存档日志序列号中,确定下一个u SCN号较低的序列号。

这就是我们需要记录的归档日志序列。

记住,我们需要在这个数字上加1,然后在RMAN RECOVER命令的SET UNTIL SEQUENCE子句中使用这个数字。

例如,我们看到对于线程1,最近可用的归档日志备份属于日志序列号144,而对于线程2,最近可用的归档日志备份属于日志序列号139。

比较这两个序列号的下一个u SCN值,我们可以看到对于序列144,下一个u SCN值更低(736746比736760)。

Thrd Seq     Low SCN     Low Time  Next SCN   Next Time

 1    144   736706 28-MAR-12 736746 28-MAR-12

....
.....

 2    139   736740 28-MAR-12 736760 28-MAR-12

RMAN> run {
set until sequence 145 thread 1;
recover database;
}
2> 3> 4>
executing command: SET until clause

Starting recover at 21-FEB-13
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=144
channel ORA_DISK_1: restoring archived log
archived log thread=2 sequence=139
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/backup/annnf0_tag20130218t093927_0.325.807701967
channel ORA_DISK_1: piece handle=/u01/app/oracle/backup/annnf0_tag20130218t093927_0.325.807701967 tag=TAG20130218T093927
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2013_02_21/o1_mf_1_144_8lbwbp3o_.arc thread=1 sequence=144
archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2013_02_21/o1_mf_2_139_8lbwbp4o_.arc thread=2 sequence=139
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2013_02_21/o1_mf_1_144_8lbwbp3o_.arc RECID=270 STAMP=807958744
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2013_02_21/o1_mf_2_139_8lbwbp4o_.arc RECID=269 STAMP=807958742
media recovery complete, elapsed time: 00:00:00
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=2 sequence=140
channel ORA_DISK_1: restoring archived log
archived log thread=2 sequence=141
channel ORA_DISK_1: restoring archived log
archived log thread=2 sequence=142
channel ORA_DISK_1: restoring archived log
archived log thread=2 sequence=143
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/backup/annnf0_tag20130219t103153_0.295.807791515
channel ORA_DISK_1: piece handle=/u01/app/oracle/backup/annnf0_tag20130219t103153_0.295.807791515 tag=TAG20130219T103153
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2013_02_21/o1_mf_2_140_8lbwbt41_.arc RECID=273 STAMP=807958750
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2013_02_21/o1_mf_2_141_8lbwbt1b_.arc RECID=274 STAMP=807958750
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2013_02_21/o1_mf_2_142_8lbwbt66_.arc RECID=272 STAMP=807958747
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2013_02_21/o1_mf_2_143_8lbwbvnc_.arc RECID=271 STAMP=807958747
Finished recover at 21-FEB-13

使用RESETLOGS选项打开数据库。

RMAN> sql 'alter database open resetlogs';

sql statement: alter database open resetlogs

注意联机重做日志文件的位置。我们可以删除并重新创建联机重做日志文件组,如果我们想从当前的OMF格式重命名它们的话。

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/ORCL/onlinelog/o1_mf_2_8lbwd9kq_.log
/u01/app/oracle/oradata/ORCL/onlinelog/o1_mf_3_8lbwdb5n_.log
/u01/app/oracle/oradata/ORCL/onlinelog/o1_mf_1_8lbwd8v5_.log
/u01/app/oracle/oradata/ORCL/onlinelog/o1_mf_4_8lbwdbqr_.log