使用基于scn的增量备份恢复数据库

使用基于scn的增量备份恢复数据库
最近遇到克隆数据库的时候,备份日志被清理掉,怎么办?
克隆命令:(克隆过程,类似于restore+recover)
run{
ALLOCATE CHANNEL ch1 TYPE DISK;
ALLOCATE AUXILIARY CHANNEL ch11 TYPE DISK;
duplicate target database to xxxx from active database nofilenamecheck ;
RELEASE CHANNEL ch1;
RELEASE CHANNEL ch11;
}

1.克隆到最后需要恢复归档日志的时候,发现归档日志没有,报错信息如下:
contents of Memory Script:
{
set until scn 181448051398;
recover
clone database
delete archivelog
;
}
executing Memory Script

executing command: SET until clause

Starting recover at 06-FEB-2018 16:16:45

starting media recovery

archived log for thread 1 with sequence 87 is already on disk as file +DATA_EX01/xxxx/archivelog/2018_02_06/thread_1_seq_87.601.967392937
archived log for thread 1 with sequence 88 is already on disk as file +DATA_EX01/xxxx/archivelog/2018_02_06/thread_1_seq_88.600.967392937
unable to find archived log
archived log thread=1 sequence=76
released channel: ch1
released channel: ch2
released channel: ch3
released channel: ch4
released channel: ch5
released channel: ch6
Oracle Error:
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '+DATA_EX01/xxxx/datafile/system.264.967310165'

released channel: ch11
released channel: ch12
released channel: ch13
released channel: ch14
released channel: ch15
released channel: ch16
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 02/06/2018 16:16:57
RMAN-05501: aborting duplication of target database
RMAN-03015: error occurred in stored script Memory Script
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 76 and starting SCN of 181447840153 ==>从上面的信息,可以看出,从scn=181447840153开始之后的日志都没有了

RMAN>

2.在原来的库做增量备份.备份中产生的归档日志,是需要的。
run{
ALLOCATE CHANNEL ch1 TYPE DISK;
backup incremental from scn 181447840153 database format '/backup/incre_%U_bak.bk';
RELEASE CHANNEL ch1;
}
3.备份之后,然后scp到克隆的库。使用rman注册该增量日志
RMAN> CATALOG START WITH '/backup/';

searching for all files that match the pattern /backup/

List of Files Unknown to the Database
=====================================
File Name: /backup/dp/control.dmp
File Name: /backup/dp/detail.dmp
File Name: /backup/dp/dependency.dmp
File Name: /backup/dp/control.log
File Name: /backup/dp/detail.log
File Name: /backup/dp/dependency.log
File Name: /backup/incre_d3sqj1nc_1_1_bak.bk
File Name: /backup/incre_d4sqj1nd_1_1_bak.bk
File Name: /backup/incre_d5sqj1nd_1_1_bak.bk
File Name: /backup/incre_d6sqj1nd_1_1_bak.bk
File Name: /backup/incre_d7sqj1nd_1_1_bak.bk
File Name: /backup/incre_d8sqj1nd_1_1_bak.bk
File Name: /backup/incre_d9sqj1ne_1_1_bak.bk
File Name: /backup/incre_dasqj1ne_1_1_bak.bk
File Name: /backup/incre_dbsqj1nf_1_1_bak.bk
File Name: /backup/incre_dcsqj8ll_1_1_bak.bk

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /backup/incre_d3sqj1nc_1_1_bak.bk
File Name: /backup/incre_d4sqj1nd_1_1_bak.bk
File Name: /backup/incre_d5sqj1nd_1_1_bak.bk
File Name: /backup/incre_d6sqj1nd_1_1_bak.bk
File Name: /backup/incre_d7sqj1nd_1_1_bak.bk
File Name: /backup/incre_d8sqj1nd_1_1_bak.bk
File Name: /backup/incre_d9sqj1ne_1_1_bak.bk
File Name: /backup/incre_dasqj1ne_1_1_bak.bk
File Name: /backup/incre_dbsqj1nf_1_1_bak.bk
File Name: /backup/incre_dcsqj8ll_1_1_bak.bk

List of Files Which Where Not Cataloged
=======================================
File Name: /backup/dp/control.dmp
RMAN-07520: Reason: Data pump dump file
File Name: /backup/dp/detail.dmp
RMAN-07520: Reason: Data pump dump file
File Name: /backup/dp/dependency.dmp
RMAN-07520: Reason: Data pump dump file
File Name: /backup/dp/control.log
RMAN-07517: Reason: The file header is corrupted
File Name: /backup/dp/detail.log
RMAN-07517: Reason: The file header is corrupted
File Name: /backup/dp/dependency.log
RMAN-07517: Reason: The file header is corrupted

RMAN>
4.直接使用recover databse noredo进行还原
RMAN> run{
2> ALLOCATE CHANNEL ch1 TYPE DISK;
3> RECOVER DATABASE NOREDO;
4> RELEASE CHANNEL ch1;
5> }

allocated channel: ch1
channel ch1: SID=2889 device type=DISK

Starting recover at 07-FEB-2018 08:06:36
channel ch1: starting incremental datafile backup set restore
channel ch1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00002: +DATA_EX01/xxxx/datafile/sysaux.260.967308659
…………………………
destination for restore of datafile 00348: +DATA_EX01/xxxx/datafile/undotbs.595.967392909
channel ch1: reading from backup piece /backup/incre_d5sqj1nd_1_1_bak.bk
channel ch1: piece handle=/backup/incre_d5sqj1nd_1_1_bak.bk tag=TAG20180206T212353
channel ch1: restored backup piece 1
channel ch1: restore complete, elapsed time: 00:00:55

Finished recover at 07-FEB-2018 08:12:57

released channel: ch1

RMAN>

5.由于使用scn增备份。控制文件记录的scn号,可能小于数据文件scn。需要重新建立控制文件
sql> alter database backup controlfile to trace as '/home/oracle/ctl.sql';
6.使用控制文件中resetlogs部分重建控制文件。
SQL> @ctl.sql

Control file created.

PL/SQL procedure successfully completed.

ORA-00279: change 181448086315 generated at 02/06/2018 21:23:56 needed for
thread 1
ORA-00289: suggestion : +DATA_EX01
ORA-15173: entry 'ARCHIVELOG' does not exist in directory 'xxxx'
ORA-00280: change 181448086315 for thread 1 is in sequence #89


ORA-00308: cannot open archived log '+DATA_EX01'
ORA-17503: ksfdopn:2 Failed to open file +DATA_EX01
ORA-15045: ASM file name '+DATA_EX01' is not in reference form

SQL>
SQL> RECOVER DATABASE USING BACKUP CONTROLFILE until cancel;     <<<<<<<<<<需要将增量备份过程中产生的归档日志传输到克隆的库
ORA-00279: change 181448086315 generated at 02/06/2018 21:23:56 needed for
thread 1
ORA-00289: suggestion : +DATA_EX01
ORA-00280: change 181448086315 for thread 1 is in sequence #89


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/home/oracle/thread_1_seq_89.659.967421919
ORA-00279: change 181448114439 generated at 02/07/2018 00:18:38 needed for
thread 1
ORA-00289: suggestion : +DATA_EX01
ORA-00280: change 181448114439 for thread 1 is in sequence #90
ORA-00278: log file '/home/oracle/thread_1_seq_89.659.967421919' no longer
needed for this recovery


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
CANCEL
Media recovery cancelled.
SQL> alter database open resetlogs;

Database altered.

SQL>

至此数据库正常打开。

原文地址:https://www.cnblogs.com/erwadba/p/8427544.html