Dataguard 归档丢失处理
Dataguard 主库归档丢失处理或误删除,尚未传到备库,使用rman的增量备份功能解决gap,不需要重建DG
Using RMAN Incremental Backups to Refresh a Standby Database
You can create an incremental backup of the target database containing changes to the database since the creation of the duplicate or the previous syncrhonization. You can apply the incremental backup to the standby database.
Note:
This technique cannot be used to update a duplicate database.
RMAN enables you to synchronize a standby database with a primary database by creating an incremental backup at the source database that contains all changed blocks since the duplicate was created or last refreshed. You then apply the incremental backup to the standby database, which updates it with all changes.
This capability facilitates the temporary conversion of a physical standby database into a reporting database, as described in Oracle Data Guard Concepts and Administration. In particular, this capability makes it possible to reverse the effects of converting the standby into a reporting database. After the standby database has been used for reporting or testing, Flashback Database can reverse any changes resulting from that work, returning the database to its contents when it was still a standby. An incremental backup created with BACKUP INCREMENTAL... FROM SCN can be used to refresh the standby with changes at the primary since the conversion and then managed recovery can resume. The effect is to return the reporting database to its role as standby.
For more details on this scenario, see Oracle Data Guard Concepts and Administration.
Using BACKUP INCREMENTAL... FROM SCN
The incremental backup is created at the source database by means of the BACKUP INCREMENTAL FROM SCN=n form of the BACKUP command. For example:
BACKUP DEVICE TYPE SBT INCREMENTAL FROM SCN 750923 DATABASE;
BACKUP INCREMENTAL FROM SCN 750923 DATABASE;
BACKUP DEVICE TYPE DISK INCREMENTAL FROM SCN 750983 DATABASE
FORMAT '/tmp/incr_standby_%U';
RMAN uses the selected SCN as the basis for this incremental backup. For all files being backed up, RMAN includes all data blocks that were changed at SCNs greater than or equal to the FROM SCN in the incremental backup.
Note:
- RMAN does not consider the incremental backup as part of a backup strategy at the source database. The backup is not suitable for use in a normal RECOVER DATABASE operation at the source database.
- The backup sets produced by this command are written to ?/dbs by default, even if the flash recovery area or some other backup destination is defined as the default for disk backups.
- You must create this incremental backup on disk for it to be useful. When you move the incremental backup to the standby, you must catalog it at the standby as described in "Step 3: Catalog the Incremental Backup Files at the Standby Database". Backups on tape cannot be cataloged.
See Also:
《Oracle Database Backup and Recovery Reference 》 for more details on BACKUP command syntax
Refreshing a Standby Database With INCREMENTAL FROM SCN Backups: Example
This example shows the steps required to update a standby database using incremental backups. The assumption is that you have already activated the standby, performed your tests or other operations at the standby, and then used Flashback Database to undo the effects of those changes. The task here is to refresh the standby with the latest changes to the primary, so that it can resume its role as a standby database.
Step 1: Create the Incremental Backup
Create the needed incremental backup at the source database, using BACKUP with the INCREMENTAL FROM SCN clause.
Assume that the incremental backup to be used in updating the duplicate database is to be created on disk, with the filenames for backup pieces determined by the format /tmp/incr_for_standby/bkup_%U.
RMAN> BACKUP DEVICE TYPE DISK INCREMENTAL FROM SCN 750983 DATABASE
FORMAT '/tmp/incr_for_standby/bkup_%U';
Step 2: Make the Incremental Backup Accessible at the Standby Database
Make the backup pieces containing the incremental backup available in some directory accessible on the system containing the standby database. For this example, assume that the destination directory is called /standbydisk1/incrback/ and ensure that it contains nothing besides the incremental backups from Step 1.
Step 3: Catalog the Incremental Backup Files at the Standby Database
Use the RMAN CATALOG command to register the backup sets in the RMAN repository at the duplicate. With an RMAN client connected to the standby database and the recovery catalog (if you use one at the standby), mount the standby and run the following command:
RMAN> CATALOG START WITH '/standbydisk1/incrback/';
The backups are now available for use in recovery of the standby.
Step 4: Apply the Incremental Backup to the Standby Database
Use the RMAN RECOVER command with the NOREDO option to apply the incremental backup to the standby database. All changed blocks captured in the incremental backup are updated at the standby database, bringing it up to date with the primary database. With an RMAN client connected to the standby database, run the following command:
RMAN> RECOVER DATABASE NOREDO;
You can now resume managed recovery at the standby. Any redo logs required at the standby with changes since those contained in the incremental are automatically requested from the primary and applied
Data guard的Physical standby database环境中
当主库误删除或丢失了部分归档日志之后,在不重新部署standby环境的情况下同步主备两个库。
整个过程在Oracle的官方文档中也有说明
Oracle? Database Backup and Recovery Advanced User's Guide
--> Using RMAN Incremental Backups to Refresh a Standby Database
首先
在备库上查询缺失的归档号:
SQL>select first_time,first_change#,next_change#,sequence# from v$log_history;
在备库上查询GAP
SQL>SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;
在主库上查询丢失的归档是否存在
SQL>SELECT NAME FROM V$ARCHIVED_LOG WHERE THREAD#=1 AND DEST_ID=1 AND SEQUENCE# BETWEEN 31149 AND 31157;
如果确认主库已经不存在丢失的归档,需要找到丢失的归档所对应的SCN
10g 可以这样查看
SQL> select current_scn from v$database;
URRENT_SCN
----------
3470773
SQL> SELECT DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER FROM DUAL;
ET_SYSTEM_CHANGE_NUMBER
-----------------------
3470743
Step 1: 创建基于scn的增量备份
首先要知道你误删除或者丢失的归档日志是从哪个scn开始的。
V$ARCHIVED_LOG的FIRST_CHANGE#列能够查到归档日志对应的起始SCN(750983为例),然后就可以下面的操作。
在主库上使用backup ... incremental from scn为主库做一个增量备份,这个操作会将整个库中scn大于750983的block备份出来。(数据库的block中是有scn的,这个在 concept里有明确说明)
RMAN> BACKUP DEVICE TYPE DISK INCREMENTAL FROM SCN 750983 DATABASE
FORMAT '/tmp/incr_for_standby/bkup_incre.bk';
Step 2: 将备份的文件复制到standby端
例如:/standbydisk1/incrback/ ,注意要是一个空目录,不能有除了增量备份之外的其他东西。
/standbydisk1/incrback/bkup_incre.bk
Step 3: 在standby端将备份登记到RMAN repository,需要rman连接standby库和catalog库(如果有,没有就算了),Standby库要是mount状态
RMAN> CATALOG START WITH '/standbydisk1/incrback/';
上面命令会把/standbydisk1/incrback/目录中的备份在standby的controlfile和catalog中导入
Step 4:
在standby库执行recover,注意这样并不会把standby库recover到一致状态,因为主库备份时是在线的。但是recover完之后的状态是可以来做standby的managed recovery的,Standby库是mount状态。
RMAN> RECOVER DATABASE NOREDO;
下面就该
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;