Tuesday, September 6, 2016

RMAN Incremental Backups

RMAN Incremental Backups (Level 0 & Level 1)


The goal of an incremental backup is to backup only those data blocks that have changed 
since a previous backup.

RMAN incremental backups backup only datafile blocks that have changed since 
previous backup. We can use RMAN to create incremental backups of datafiles, tablespaces,
 or the whole database.

The primary reasons for making incremental backups, part of our strategy are:
  • For use in a strategy based on incrementally updated backups, where these incremental 
backups are used to periodically roll forward an image copy of the database
  • To reduce the amount of time needed for daily backups
  • To save network bandwidth when backing up over a network
  • To get adequate backup performance when the aggregate tape bandwidth available for 
tape write I/Os is much less than the aggregate disk bandwidth for disk read I/Os
  • To be able to recover changes to objects created with the NOLOGGING option. For example, 
direct load inserts do not create redo log entries and their changes cannot be reproduced with
 media recovery. They change data blocks and so are captured by incremental backups.
  • To reduce backup sizes for NOARCHIVELOG databases. Instead of making a whole
 database backup every time, we can make incremental backups.
As with full backups, if you are in ARCHIVELOG mode, you can make incremental backups
 if the database is open; if the database is in NOARCHIVELOG mode, then you can only make 
incremental backups after a consistent shutdown.

One effective strategy is to make incremental backups to disk, and then backup the resulting
 backup sets to a media manager with BACKUP AS BACKUPSET. The incremental backups are
 generally smaller than full backups, which limits the space required to store them until they 
are moved to tape. Then, when the incremental backups on disk are backed up to tape, it is 
more likely that tape streaming can be sustained because all blocks of the incremental backup 
are copied to tape. There is no possibility of delay due to time required for RMAN to locate 
changed blocks in the datafiles.

RMAN backups can be classified in these ways:
  • Full or incremental
  • Open or closed
  • Consistent or inconsistent

Note that these backup classifications apply only to datafile backups. Backups of other files, 
such as archivelogs and control files, always include the complete file and are never inconsistent. 

Backup Type
Definition
Full
A backup of a datafile that includes every allocated block in the file being backed up. A full backup of a datafile can be an image copy, in which case every data block is backed up. It can also be stored in a backup set, in which case datafile blocks not in use may be skipped.
A full backup cannot be part of an incremental backup strategy; that is, it cannot be the parent for a subsequent incremental backup.
Incremental
An incremental backup is either a level 0 backup, which includes every block in the file except blockscompressed out because they have never been used, or a level 1 backup, which includes only those blocksthat have been changed since the parent backup was taken.
A level 0 incremental backup is physically identical to a full backup. The only difference is that the level 0 backup is recorded as an incremental backup in the RMAN repository, so it can be used as the parent for a level 1 backup.
Open
A backup of online, read/write datafiles when the database is open.
Closed
A backup of any part of the target database when it is mounted but not open. Closed backups can be consistent or inconsistent.
Consistent
A backup taken when the database is mounted (but not open) after a normal shutdown. The checkpointSCNs in the datafile headers match the header information in the control file. None of the datafiles has changes beyond its checkpoint. Consistent backups can be restored without recovery.
Note: If you restore a consistent backup and open the database in read/write mode without recovery, transactions after the backup are lost. You still need to perform an OPEN RESETLOGS.
Inconsistent
A backup of any part of the target database when it is open or when a crash occurred or SHUTDOWN ABORT was run prior to mounting.
An inconsistent backup requires recovery to become consistent.

During media recovery, RMAN examines the restored files to determine whether it can recover them with an incremental backup. If it has a choice, then RMAN always chooses incremental backups over archived logs, as applying changes at a block level is faster than reapplying individual changes.

RMAN does not need to restore a base incremental backup of a datafile in order to apply incremental backups to the datafile during recovery. For example, we can restore non-incremental image copies of the datafiles in the database, and RMAN can recover them with incremental backups.

Incremental Backup Algorithm
Each data block in a datafile contains a system change number (SCN), which is the SCN at which the most recent change was made to the block. During an incremental backup, RMAN reads the SCN of each data block in the input file and compares it to the checkpoint SCN of the parent incremental backup. If the SCN in the input data block is greater than or equal to the checkpoint SCN of the parent, then RMAN copies the block.

Note that if you enable the block change tracking feature, RMAN can refer to the change tracking file to identify changed blocks in datafiles without scanning the full contents of the datafile. Once enabled, block change tracking does not alter how we take or use incremental backups, other than offering increased performance.

Level 0 and Level 1 Incremental Backups
Incremental backups can be either level 0 or level 1. A level 0 incremental backup, which is the base for subsequent incremental backups, copies all blocks containing data, backing the datafile up into a backup set just as a full backup would. The only difference between a level 0 incremental backup and a full backup is that a full backup is never included in an incremental strategy.

A level 1 incremental backup can be either of the following types:
  • differential backup, which backs up all blocks changed after the most recent incremental backup at level 1 or 0
  • cumulative backup, which backs up all blocks changed after the most recent incremental backup at level 0

Incremental backups are differential by default.

Note:
Cumulative backups are preferable to differential backups when recovery time is more important than disk space, because during recovery each differential backup must be applied in succession. Use cumulative incremental backups instead of differential, if enough disk space is available to store cumulative incremental backups.

The size of the backup file depends solely upon the number of blocks modified and the incremental backup level.

The following commands performs a level 0 backup of the database:
RMAN> BACKUP INCREMENTAL LEVEL=0 DATABASE;
RMAN> BACKUP INCREMENTAL LEVEL 0 DATABASE PLUS ARCHIVELOG;

Differential Incremental Backups
In a differential level 1 backup, RMAN backs up all blocks that have changed since the most recent cumulative or differential incremental backup, whether at level 1 or level 0. RMAN determines which level 1 backup occurred most recently and backs up all blocks modified after that backup. If no level 1 is available, RMAN copies all blocks changed since the level 0 backup.

The following command performs a level 1 differential incremental backup of the database:
RMAN> BACKUP INCREMENTAL LEVEL 1 DATABASE;  

If no level 0 backup is available, then the behavior depends upon the compatibility mode setting. If compatibility is >=10.0.0, RMAN copies all blocks changed since the file was created, and stores the results as a level 1 backup. In other words, the SCN at the time the incremental backup is taken is the file creation SCN. If compatibility <10.0.0, RMAN generates a level 0 backup of the file contents at the time of the backup, to be consistent with the behavior in previous releases.

Source: Oracle Website

In the example shown in above Figure, the following occurs:
  • Sunday
An incremental level 0 backup backs up all blocks that have ever been in use in this database.
  • Monday - Saturday
On each day from Monday through Saturday, a differential incremental level 1 backup backs up all blocks that have changed since the most recent incremental backup at level 1 or 0. So, the Monday backup copies blocks changed since Sunday level 0 backup, the Tuesday backup copies blocks changed since the Monday level 1 backup, and so forth.
  • The cycle is repeated for the next week.

Cumulative Incremental Backups
In a cumulative level 1 backup, RMAN backs up all the blocks used since the most recent level 0 incremental backup. Cumulative incremental backups reduce the work needed for a restore by ensuring that you only need one incremental backup from any particular level. Cumulative backups require more space and time than differential backups, because they duplicate the work done by previous backups at the same level.

The following command performs a cumulative level 1 incremental backup of the database:
RMAN> BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;
RMAN> BACKUP INCREMENTAL LEVEL 1 CUMULATIVE SKIP INACCESSIBLE DATABASE;
                                    Source: Oracle Website

In the example shown in Figure, the following occurs:
  • Sunday
An incremental level 0 backup backs up all blocks that have ever been in use in this database.
  • Monday - Saturday
A cumulative incremental level 1 backup copies all blocks changed since the most recent level 0 backup. Because the most recent level 0 backup was created on Sunday, the level 1 backup on each day Monday through Saturday backs up all blocks changed since the Sunday backup.
  • The cycle is repeated for the next week.

Basic Incremental Backup Strategy
Choose a backup scheme according to an acceptable MTTR (mean time to recover). For example, you can implement a three-level backup scheme so that a full or level 0 backup is taken monthly, a cumulative level 1 is taken weekly, and a differential level 1 is taken daily. In this scheme, you never have to apply more than a day's worth of redo for complete recovery.

When deciding how often to take full or level 0 backups, a good rule of thumb is to take a new level 0 whenever 50% or more of the data has changed. If the rate of change to your database is predictable, then you can observe the size of your incremental backups to determine when a new level 0 is appropriate.

The following query displays the number of blocks written to a backup set for each datafile with at least 50% of its blocks backed up:
SQL> SELECT FILE#, INCREMENTAL_LEVEL, COMPLETION_TIME, BLOCKS, DATAFILE_BLOCKS FROM V$BACKUP_DATAFILE WHERE INCREMENTAL_LEVEL > 0 AND BLOCKS / DATAFILE_BLOCKS > .5 ORDER BY COMPLETION_TIME;  

Compare the number of blocks in differential or cumulative backups to a base level 0 backup. For example, if you only create level 1 cumulative backups, then when the most recent level 1 backup is about half of the size of the base level 0 backup, take a new level 0.

Making Incremental Backups: BACKUP INCREMENTAL
After starting RMAN, run the BACKUP INCREMENTAL command at the RMAN prompt. This example makes a level 0 incremental backup of the database:
RMAN> BACKUP INCREMENTAL LEVEL 0 DATABASE;  

This example makes a differential level 1 backup of the SYSTEM tablespace and datafile tools01.dbf. It will only backup those data blocks changed since the most recent level 1 or level 0 backup:
RMAN> BACKUP INCREMENTAL LEVEL 1 TABLESPACE SYSTEM DATAFILE 'ora_home/oradata/trgt/tools01.dbf';  

This example makes a cumulative level 1 backup of the tablespace users, backing up all blocks changed since the most recent level 0 backup.
RMAN> BACKUP INCREMENTAL LEVEL = 1 CUMULATIVE TABLESPACE users; 

Incrementally Updated Backups: Rolling Forward Image Copy Backups
Oracle's Incrementally Updated Backups feature avoid the overhead of taking full image copy backups of datafiles, while providing the same recovery advantages as image copy backups.

At the beginning of a backup strategy, RMAN creates an image copy backup of the datafile. Then, at regular intervals, such as daily, level 1 incremental backups are taken, and applied to the image copy backup, rolling it forward to the point in time when the level 1 incremental was created.

During restore and recovery of the database, RMAN can restore from this incrementally updated copy and then apply changes from the redo log, with the same results as restoring the database from a full backup taken at the SCN of the most recently applied incremental level 1 backup.

A backup strategy based on incrementally updated backups can help minimize time required for media recovery of your database. For example, if you run scripts to implement this strategy daily, then at recovery time, you never have more than one day of redo to apply.

SELECT FILE#, INCREMENTAL_LEVEL, COMPLETION_TIME, BLOCKS, DATAFILE_BLOCKS FROM V$BACKUP_DATAFILE WHERE INCREMENTAL_LEVEL > 0 AND BLOCKS / DATAFILE_BLOCKS > .5 ORDER BY COMPLETION_TIME;

No comments:

Post a Comment