千家信息网

如何使用RMAN对CDB执行按时间点恢复

发表于:2025-01-20 作者:千家信息网编辑
千家信息网最后更新 2025年01月20日,这篇文章给大家分享的是有关如何使用RMAN对CDB执行按时间点恢复的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。使用RMAN对CDB和PDB执行按时间点恢复RMAN能够对C
千家信息网最后更新 2025年01月20日如何使用RMAN对CDB执行按时间点恢复

这篇文章给大家分享的是有关如何使用RMAN对CDB执行按时间点恢复的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

使用RMAN对CDB和PDB执行按时间点恢复
RMAN能够对CDB与PDB执行按时间点恢复操作。但是PDB只能使用RMAN来执行按时间点恢复。如是没有使用恢复目录数据库,建议启用自动控制文件备份。否则当对PDB执行按时间点恢复时,当RMAN需要增加与删除undo数据文件时不能有效的执行。

PDB按时间点恢复与快速恢复区
当对PDB执行数据库按时间点恢复时,对于这个PDB所有的数据文件都将被执行恢复操作。然而,为了将PDB恢复到指定的时间点,RMAN在恢复目标时间点也是需要有UNDO表空间存在的。因为undo表空间是被所有PDB所共享的,它不能被恢复。RMAN会将root中的undo,system与sysaux表空间还原到辅助实例中,然后使用undo信息来将pdb恢复到指定的时间点。如果配置了快速恢复区,Oracle将会使用它作为辅助实例的存储目录。如果快速恢复区没有被配置,那么必须使用auxiliary destination子句来指定辅助实例数据库文件的存储目录。确保在快速恢复区有足够的空间可以用来还原root表空间与undo表空间。如果快速恢复区没有足够的空间,可以通过使用auxiliary destination子句来指定其它的目录。

对CDB执行数据库按时间点恢复
1.登录数据库记录当前SCN号,然后将表t1中的数据删除。

SQL> conn jy/jy@jypdbConnected.SQL> SELECT CURRENT_SCN   FROM V$DATABASE;CURRENT_SCN-----------    6041183SQL> alter session set nls_date_format='yyyy-mm-dd hh34:mi:ss';Session altered.SQL> select sysdate from dual;SYSDATE-------------------2017-12-18 18:28:30SQL> select count(*) from t1;  COUNT(*)----------        39SQL> truncate table t1;Table truncated.SQL> select count(*) from t1;  COUNT(*)----------         0

2.如果使用时间表达式来代替目标SCN,那么在调用RMAN之前设置时间格式环境变量

[oracle@jytest1 ~]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh34:mi:ss'

3.使用RMAN连接到root容器

[oracle@jytest1 ~]$ rman target/ catalog rco/abcd@jypdb_173Recovery Manager: Release 12.2.0.1.0 - Production on Mon Dec 18 18:32:00 2017Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.connected to target database: JY (DBID=979425723)connected to recovery catalog database

4.将CDB重启到mount状态

RMAN> shutdown immediatestarting full resync of recovery catalogfull resync completedatabase closeddatabase dismountedOracle instance shut downRMAN> startup mountconnected to target database (not started)Oracle instance starteddatabase mountedTotal System Global Area    6442450944 bytesFixed Size                     8807168 bytesVariable Size               1895828736 bytesDatabase Buffers            4529848320 bytesRedo Buffers                   7966720 bytesstarting full resync of recovery catalogfull resync complete

5.使用RUN块来执行以下操作
a.对于数据库按时间点鶋,使用set until来指定恢复的目标时间,scn或日志序列号,或者使用set to来指定还原点。如果指定时间那么使用环境变量nls_lang与nls_date_format中所指定的日期格式。

b.如果RMAN没有配置自动通道,那么需要手动分配磁盘与磁带通道。

c.还原与恢复CDB

下面的命令将CDB恢复到SCN=6041183所在的状态

RMAN> run2> {3>    set until scn 6041183;4>    restore database;5>    recover database;6> }executing command: SET until clauseStarting restore at 2017-12-18 18:46:50flashing back control file to SCN 6041183allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=764 instance=jy1 device type=DISKskipping datafile 5; already restored to file +DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/system.256.962209675skipping datafile 6; already restored to file +DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/sysaux.270.962209675skipping datafile 8; already restored to file +DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/undotbs1.296.962209675channel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_DISK_1: restoring datafile 00001 to +DATA/JY/DATAFILE/system.317.962209603channel ORA_DISK_1: restoring datafile 00003 to +DATA/JY/DATAFILE/sysaux.298.962209605channel ORA_DISK_1: restoring datafile 00004 to +DATA/JY/DATAFILE/undotbs1.277.962209605channel ORA_DISK_1: restoring datafile 00007 to +DATA/JY/DATAFILE/users.301.962209605channel ORA_DISK_1: restoring datafile 00009 to +DATA/JY/DATAFILE/undotbs2.312.962209605channel ORA_DISK_1: reading from backup piece +TEST/rman_backup/jy_979425723_962563410_10slv3ai_1_1channel ORA_DISK_1: piece handle=+TEST/rman_backup/jy_979425723_962563410_10slv3ai_1_1 tag=TAG20171212T184328channel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:01:05channel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_DISK_1: restoring datafile 00010 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/system.271.962209649channel ORA_DISK_1: restoring datafile 00011 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/sysaux.316.962209649channel ORA_DISK_1: restoring datafile 00012 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undotbs1.264.962209649channel ORA_DISK_1: restoring datafile 00013 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undo_2.268.962209649channel ORA_DISK_1: restoring datafile 00014 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/users.278.962209649channel ORA_DISK_1: restoring datafile 00015 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/test.275.962210609channel ORA_DISK_1: reading from backup piece +TEST/rman_backup/jy_979425723_962563516_11slv3ds_1_1channel ORA_DISK_1: piece handle=+TEST/rman_backup/jy_979425723_962563516_11slv3ds_1_1 tag=TAG20171212T184328channel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:00:35channel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_DISK_1: restoring datafile 00016 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/system.260.962469409channel ORA_DISK_1: restoring datafile 00017 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/sysaux.259.962469409channel ORA_DISK_1: restoring datafile 00018 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undotbs1.265.962469409channel ORA_DISK_1: restoring datafile 00019 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undo_2.266.962469409channel ORA_DISK_1: restoring datafile 00020 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/users.267.962469409channel ORA_DISK_1: restoring datafile 00021 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/test.269.962469409channel ORA_DISK_1: reading from backup piece +TEST/rman_backup/jy_979425723_962563551_12slv3ev_1_1channel ORA_DISK_1: piece handle=+TEST/rman_backup/jy_979425723_962563551_12slv3ev_1_1 tag=TAG20171212T184328channel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:00:35Finished restore at 2017-12-18 18:49:09Starting recover at 2017-12-18 18:49:11using channel ORA_DISK_1applied offline range to datafile 00010offline range RECID=80 STAMP=963072332applied offline range to datafile 00011offline range RECID=79 STAMP=963072332applied offline range to datafile 00012offline range RECID=78 STAMP=963072332applied offline range to datafile 00013offline range RECID=77 STAMP=963072332applied offline range to datafile 00014offline range RECID=76 STAMP=963072332applied offline range to datafile 00015offline range RECID=75 STAMP=963072332applied offline range to datafile 00016offline range RECID=86 STAMP=963072332applied offline range to datafile 00017offline range RECID=85 STAMP=963072332applied offline range to datafile 00018offline range RECID=84 STAMP=963072332applied offline range to datafile 00019offline range RECID=83 STAMP=963072332applied offline range to datafile 00020offline range RECID=82 STAMP=963072332applied offline range to datafile 00021offline range RECID=81 STAMP=963072332starting media recoveryarchived log for thread 1 with sequence 34 is already on disk as file +TEST/arch/1_34_961976319.dbfarchived log for thread 1 with sequence 35 is already on disk as file +TEST/arch/1_35_961976319.dbfarchived log for thread 1 with sequence 36 is already on disk as file +TEST/arch/1_36_961976319.dbfarchived log for thread 1 with sequence 37 is already on disk as file +TEST/arch/1_37_961976319.dbfarchived log for thread 1 with sequence 38 is already on disk as file +TEST/arch/1_38_961976319.dbfarchived log for thread 1 with sequence 39 is already on disk as file +TEST/arch/1_39_961976319.dbfarchived log for thread 1 with sequence 40 is already on disk as file +TEST/arch/1_40_961976319.dbfarchived log for thread 1 with sequence 41 is already on disk as file +TEST/arch/1_41_961976319.dbfarchived log for thread 1 with sequence 42 is already on disk as file +TEST/arch/1_42_961976319.dbfarchived log for thread 1 with sequence 43 is already on disk as file +TEST/arch/1_43_961976319.dbfarchived log for thread 1 with sequence 44 is already on disk as file +TEST/arch/1_44_961976319.dbfarchived log for thread 1 with sequence 45 is already on disk as file +TEST/arch/1_45_961976319.dbfarchived log for thread 1 with sequence 46 is already on disk as file +TEST/arch/1_46_961976319.dbfarchived log for thread 1 with sequence 47 is already on disk as file +TEST/arch/1_47_961976319.dbfarchived log for thread 1 with sequence 48 is already on disk as file +TEST/arch/1_48_961976319.dbfarchived log for thread 1 with sequence 49 is already on disk as file +TEST/arch/1_49_961976319.dbfarchived log for thread 1 with sequence 50 is already on disk as file +TEST/arch/1_50_961976319.dbfarchived log for thread 1 with sequence 51 is already on disk as file +TEST/arch/1_51_961976319.dbfarchived log for thread 1 with sequence 52 is already on disk as file +DATA/JY/ONLINELOG/group_2.302.961976321archived log for thread 1 with sequence 53 is already on disk as file +DATA/JY/ONLINELOG/group_1.261.961976319archived log for thread 2 with sequence 28 is already on disk as file +TEST/arch/2_28_961976319.dbfarchived log for thread 2 with sequence 29 is already on disk as file +TEST/arch/2_29_961976319.dbfarchived log for thread 2 with sequence 30 is already on disk as file +TEST/arch/2_30_961976319.dbfarchived log for thread 2 with sequence 31 is already on disk as file +TEST/arch/2_31_961976319.dbfarchived log for thread 2 with sequence 32 is already on disk as file +TEST/arch/2_32_961976319.dbfarchived log for thread 2 with sequence 33 is already on disk as file +TEST/arch/2_33_961976319.dbfarchived log for thread 2 with sequence 34 is already on disk as file +TEST/arch/2_34_961976319.dbfarchived log for thread 2 with sequence 35 is already on disk as file +TEST/arch/2_35_961976319.dbfarchived log for thread 2 with sequence 36 is already on disk as file +TEST/arch/2_36_961976319.dbfarchived log for thread 2 with sequence 37 is already on disk as file +TEST/arch/2_37_961976319.dbfarchived log for thread 2 with sequence 38 is already on disk as file +TEST/arch/2_38_961976319.dbfarchived log for thread 2 with sequence 39 is already on disk as file +TEST/arch/2_39_961976319.dbfarchived log for thread 2 with sequence 40 is already on disk as file +TEST/arch/2_40_961976319.dbfarchived log for thread 2 with sequence 41 is already on disk as file +TEST/arch/2_41_961976319.dbfarchived log for thread 2 with sequence 42 is already on disk as file +TEST/arch/2_42_961976319.dbfarchived log for thread 2 with sequence 43 is already on disk as file +TEST/arch/2_43_961976319.dbfarchived log for thread 2 with sequence 44 is already on disk as file +TEST/arch/2_44_961976319.dbfarchived log for thread 2 with sequence 45 is already on disk as file +TEST/arch/2_45_961976319.dbfarchived log for thread 2 with sequence 46 is already on disk as file +TEST/arch/2_46_961976319.dbfarchived log for thread 2 with sequence 47 is already on disk as file +TEST/arch/2_47_961976319.dbfarchived log for thread 2 with sequence 48 is already on disk as file +TEST/arch/2_48_961976319.dbfarchived log for thread 2 with sequence 49 is already on disk as file +TEST/arch/2_49_961976319.dbfarchived log for thread 2 with sequence 50 is already on disk as file +TEST/arch/2_50_961976319.dbfarchived log for thread 2 with sequence 51 is already on disk as file +TEST/arch/2_51_961976319.dbfarchived log for thread 2 with sequence 52 is already on disk as file +DATA/JY/ONLINELOG/group_4.262.961976705archived log for thread 2 with sequence 53 is already on disk as file +DATA/JY/ONLINELOG/group_3.263.961976697archived log file name=+TEST/arch/1_34_961976319.dbf thread=1 sequence=34archived log file name=+TEST/arch/2_28_961976319.dbf thread=2 sequence=28archived log file name=+TEST/arch/1_35_961976319.dbf thread=1 sequence=35archived log file name=+TEST/arch/2_29_961976319.dbf thread=2 sequence=29archived log file name=+TEST/arch/1_36_961976319.dbf thread=1 sequence=36archived log file name=+TEST/arch/2_30_961976319.dbf thread=2 sequence=30archived log file name=+TEST/arch/2_31_961976319.dbf thread=2 sequence=31archived log file name=+TEST/arch/1_37_961976319.dbf thread=1 sequence=37archived log file name=+TEST/arch/2_32_961976319.dbf thread=2 sequence=32archived log file name=+TEST/arch/1_38_961976319.dbf thread=1 sequence=38archived log file name=+TEST/arch/2_33_961976319.dbf thread=2 sequence=33archived log file name=+TEST/arch/1_39_961976319.dbf thread=1 sequence=39archived log file name=+TEST/arch/2_34_961976319.dbf thread=2 sequence=34archived log file name=+TEST/arch/1_40_961976319.dbf thread=1 sequence=40archived log file name=+TEST/arch/2_35_961976319.dbf thread=2 sequence=35archived log file name=+TEST/arch/1_41_961976319.dbf thread=1 sequence=41archived log file name=+TEST/arch/2_36_961976319.dbf thread=2 sequence=36archived log file name=+TEST/arch/1_42_961976319.dbf thread=1 sequence=42archived log file name=+TEST/arch/2_37_961976319.dbf thread=2 sequence=37archived log file name=+TEST/arch/2_38_961976319.dbf thread=2 sequence=38archived log file name=+TEST/arch/1_43_961976319.dbf thread=1 sequence=43archived log file name=+TEST/arch/2_39_961976319.dbf thread=2 sequence=39archived log file name=+TEST/arch/1_44_961976319.dbf thread=1 sequence=44archived log file name=+TEST/arch/2_40_961976319.dbf thread=2 sequence=40archived log file name=+TEST/arch/1_45_961976319.dbf thread=1 sequence=45archived log file name=+TEST/arch/2_41_961976319.dbf thread=2 sequence=41archived log file name=+TEST/arch/1_46_961976319.dbf thread=1 sequence=46archived log file name=+TEST/arch/2_42_961976319.dbf thread=2 sequence=42archived log file name=+TEST/arch/2_43_961976319.dbf thread=2 sequence=43archived log file name=+TEST/arch/1_47_961976319.dbf thread=1 sequence=47archived log file name=+TEST/arch/2_44_961976319.dbf thread=2 sequence=44archived log file name=+TEST/arch/2_45_961976319.dbf thread=2 sequence=45archived log file name=+TEST/arch/1_48_961976319.dbf thread=1 sequence=48archived log file name=+TEST/arch/2_46_961976319.dbf thread=2 sequence=46archived log file name=+TEST/arch/1_49_961976319.dbf thread=1 sequence=49archived log file name=+TEST/arch/2_47_961976319.dbf thread=2 sequence=47archived log file name=+TEST/arch/2_48_961976319.dbf thread=2 sequence=48archived log file name=+TEST/arch/1_50_961976319.dbf thread=1 sequence=50archived log file name=+TEST/arch/2_49_961976319.dbf thread=2 sequence=49archived log file name=+TEST/arch/1_51_961976319.dbf thread=1 sequence=51archived log file name=+TEST/arch/2_50_961976319.dbf thread=2 sequence=50archived log file name=+TEST/arch/2_51_961976319.dbf thread=2 sequence=51media recovery complete, elapsed time: 00:08:44Finished recover at 2017-12-18 18:58:02

6.执行以下互斥操作
.以读写方式打开CDB,放弃目标SCN之后的所有改变。在这种情况下,你必须将CDB重启到mount状态后,然后执行以下命令

alter database open resetlogs

.使用Data Pump导出CDB中你所需要的对象。然后将CDB恢复到当前时间点并重新导入对象,因此可以将需要的对象进行恢复而不用放弃所有其它对象所发生的改变。

RMAN> alter database open read only;Statement processedRMAN> alter pluggable database all open read only;Statement processedSQL> conn jy/jy@jypdbConnected.SQL> select count(*) from t1;  COUNT(*)----------        39RMAN> shutdown immediatedatabase closeddatabase dismountedOracle instance shut downRMAN> startup mountconnected to target database (not started)Oracle instance starteddatabase mountedTotal System Global Area    6442450944 bytesFixed Size                     8807168 bytesVariable Size               1895828736 bytesDatabase Buffers            4529848320 bytesRedo Buffers                   7966720 bytesRMAN> recover database;Starting recover at 2017-12-18 22:26:55allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=10 instance=jy1 device type=DISKstarting media recoverymedia recovery complete, elapsed time: 00:00:05Finished recover at 2017-12-18 22:27:05RMAN> alter database open;Statement processedstarting full resync of recovery catalogfull resync completeRMAN> alter pluggable database all open read write;Statement processedstarting full resync of recovery catalogfull resync complete

感谢各位的阅读!关于"如何使用RMAN对CDB执行按时间点恢复"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

0