Compress RMAN Backup in Oracle

There are different compression levels with Oracle 11g R2. BASIC, LOW, MEDIUM and HIGH are the four different compression levels. We must have 'Advanced Compression' option license to use LOW, MEDIUM and HIGH levels of compression. 

The AS COMPRESSED BACKUPSET option of the RMAN BACKUP command allows RMAN to perform binary compression and they are automatically decompressed during recovery.


To check current compression option:-

RMAN> SHOW COMPRESSION ALGORITHM ;

using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name ACE are:
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default


To configure compression algorithm.

RMAN> CONFIGURE COMPRESSION ALGORITHM ‘LOW’;
RMAN> CONFIGURE COMPRESSION ALGORITHM ‘MEDIUM’;
RMAN> CONFIGURE COMPRESSION ALGORITHM ‘HIGH’;
RMAN> CONFIGURE COMPRESSION ALGORITHM ‘BASIC’; #default



Backup as compressed backupset using RMAN.

RMAN>BACKUP AS compressed backupset DATABASE;
RMAN>BACKUP AS compressed backupset ARCHIVELOG ALL;
RMAN>BACKUP AS COMPRESSED BACKUPSET DATABASE PLUS ARCHIVELOG; 
RMAN>BACKUP AS compressed backupset CURRENT CONTROLFILE;
RMAN>BACKUP AS COMPRESSED BACKUPSET DATAFILE 5;




We can do the compressed incremental backup as following.


INCREMENTAL LEVEL 0:-

RUN
{
BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 0
DATABASE PLUS ARCHIVELOG;
DELETE NOPROMPT ARCHIVELOG ALL BACKED UP 1 TIMES TO DISK;
}



INCREMENTAL LEVEL 1:-

RUN
{
BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 1
DATABASE PLUS ARCHIVELOG;
DELETE NOPROMPT ARCHIVELOG ALL BACKED UP 1 TIMES TO DISK;
}



Oracle RMAN Incremental Backup

RMAN incremental backups back up only datafile blocks that have changed since a specified previous backup. You can make incremental backups of whole databases, individual tablespaces or datafiles.

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


The actual reason behind incremental backup are following.
     
Reduce the time needed to take the full backup.
Save network bandwidth while backup taking over network.
Minimize the Disk I/O’s and server resource utilization.


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.

There are two types of incremental backup.

1>   Differential Incremental Backup.
2>   Cumulative Incremental Backup.



    1>Differential Incremental Backup:-differential backup, which backs up all blocks changed after the most recent incremental backup at level 1 or 0. Basically when using differential incremental backup (the default type of incremental backup), RMAN looks for changed data blocks which were changed after last level 1 incremental backup. It there's no level 1 backup made before it, it takes a backup of the changed data blocks which were made after level 0 incremental backup.


RMAN> BACKUP INCREMENTAL LEVEL 1 DATABASE;  

Differential Incremental Backup in Oracle

    
   2>Cumulative Incremental Backup:- In a cumulative incremental backup RMAN takes backup of all changed data blocks after level 0 or level 1 incremental backup.  Like a differential backup, incremental backups also back up only the changed data blocks, but an incremental backup only backs up the data that has changed since the last backup.  If the last backup was also an incremental backup, the current incremental backups only records "changes to the changes", a much smaller set of block changes, and hence, a much smaller recovery time than a differential backup.
  
    
    RMAN> BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;


Cumulative Incremental Backup in Oracle


L0 Increment  Backup Scripts:- A level 0 incremental backup is physically identical to a full backup and it includes every data block in the file except empty blocks. 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.



RUN {
BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 0
DEVICE TYPE DISK
TAG = 'DAILY_INC_FULL' FORMAT '/backup01/RMAN_HOTBACKUP/PROD_DB/%d_DB_%u_%s_%p' database;

#*** DAILY CONTROLFILE BACKUP

BACKUP AS BACKUPSET
DEVICE TYPE DISK
TAG = 'DAILY_CONTROLFILE'
FORMAT '/backup01/RMAN_HOTBACKUP/PROD_DB/%d_CTL_%u_%s_%p'
CURRENT CONTROLFILE;

#***** DAILY SPFILE BACKUP

BACKUP AS BACKUPSET
DEVICE TYPE DISK
TAG = 'DAILY SPFILE'
FORMAT '/ backup01/RMAN_HOTBACKUP/PROD_DB/%d_SPFILE_%u_%s_%p'
SPFILE;

#*******ARCHIVELOG BACKUP****

sql 'alter system archive log current';
BACKUP
AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 0
DEVICE TYPE DISK
TAG = 'DAILY_INCR_CUM_ARCHIVEDLOG'
FORMAT '/ backup01/RMAN_HOTBACKUP/PROD_DB/%d_ARC_%u_%s_%p'
ARCHIVELOG ALL;

#*****Remove backuped archivelog before 6 day's******#
DELETE ARCHIVELOG UNTIL TIME 'sysdate-6' BACKED UP 1 TIMES TO DEVICE TYPE DISK;

#****MAINTENANCE********#
DELETE EXPIRED BACKUP;
DELETE NOPROMPT OBSOLETE;
DELETE NOPROMPT EXPIRED COPY;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
DELETE OBSOLETE REDUNDANCY = 14;
CROSSCHECK COPY;
CROSSCHECK BACKUP;
CROSSCHECK ARCHIVELOG ALL;
}


L1 Incremental Backup Script:- A level 1 backup includes only those blocks that have been changed since the "parent" backup was taken. Remember a parent backup may be either a level 0 or a level 1 backup.

RUN {
BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 1
DEVICE TYPE DISK
TAG = 'DAILY_INC_L1_BACKUP' FORMAT '/backup01/RMAN_HOTBACKUP/PROD_DB/%d_DB_%u_%s_%p' database;

#*** DAILY CONTROLFILE BACKUP

BACKUP AS BACKUPSET
DEVICE TYPE DISK
TAG = 'DAILY_CONTROLFILE'
FORMAT '/backup01/RMAN_HOTBACKUP/PROD_DB/%d_CTL_%u_%s_%p'
CURRENT CONTROLFILE;

#***** DAILY SPFILE BACKUP

BACKUP AS BACKUPSET
DEVICE TYPE DISK
TAG = 'DAILY SPFILE'
FORMAT '/backup01/RMAN_HOTBACKUP/PROD_DB/%d_SPFILE_%u_%s_%p'
SPFILE;

#*******ARCHIVELOG BACKUP****

sql 'alter system archive log current';
BACKUP
AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 1
DEVICE TYPE DISK
TAG = 'DAILY_INCR_L1_ARCHIVEDLOG'
FORMAT '/backup01/RMAN_HOTBACKUP/PROD_DB/%d_ARC_%u_%s_%p'
ARCHIVELOG ALL;

#*****Remove backuped archivelog before 6 day's******#
DELETE ARCHIVELOG UNTIL TIME 'sysdate-6' BACKED UP 1 TIMES TO DEVICE TYPE DISK;

#****MAINTENANCE********#
DELETE EXPIRED BACKUP;
DELETE NOPROMPT OBSOLETE;
DELETE NOPROMPT EXPIRED COPY;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
DELETE OBSOLETE REDUNDANCY = 14;
CROSSCHECK COPY;
CROSSCHECK BACKUP;
CROSSCHECK ARCHIVELOG ALL;
}


Hope this article helpful to you. For more details about RMAN backup click Here.

RMAN BACKUP AND RECOVERY Interview Questions.

Here is useful 'RMAN BACKUP AND RECOVERY Interview Questions/Answers' for DBA.


QWhat is RMAN?

A⟹RMAN is an Oracle Database client that performs backup,restoration,
recovery and administrative tasks in oracle Database.It greatly simplifies the dba jobs by managing the production database's backup, restoration, and recovery.

This tool integrates with sessions running on an Oracle database to perform a range of backup and recovery activities, including maintaining an RMAN repository of historical data about backups. There is no additional installation required for this tool. Its by default get installed with the oracle database installation. The RMAN environment consists of the utilities and databases that play a role in backing up your data.You can access RMAN through the command line or through Oracle Enterprise Manager.


QDifference between expired backup and obsolete backup.

AIn RMANexpired means that the backup piece or backup set is not found in the backup destination. ... Therefore, the backup piece is expired as well. A status of ‘obsolete’ means the backup piece is still available, but it is no longer needed.


QWhat does mean by Level 0, Level 1 backups:-

A⟹level 0 incremental backup, which copies all blocks in the data file, is used as a starting point for an incremental backup strategy. level 0 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.level 1 incremental backup copies only images of blocks that have changed since the previous level 0 or level 1 incremental backup.

RMAN> BACKUP INCREMENTAL LEVEL 0 DATABASE;
RMAN> BACKUP INCREMENTAL LEVEL 1 DATABASE;


Q⟾ How to check RMAN configuration.
A⟹By using command 
RMAN> show all;


Q⟾Can we take the rman backup while database in shutdown.

A⟹ No, Database should be in mount or open mode. For Open mode archivelog  must be enable in oracle database.


Q⟾Difference between backup piece and backup set.

A⟹Backup piece is physical and backup set is logical.



Q⟾ Crosscheck command in RMAN.

A⟹CROSSCHECK command to synchronize the physical reality of backups and copies with their logical records in the RMAN repository. If a corresponding backup is not available on the disk then Crosscheck command marks the backup as Expired otherwise it marks it as Available.

To check status of all rman backup.

RMAN> crosscheck backup;

Q⟹How to  Reset to default Configuration ?
A⟹ Below command to reset default rman configuration 

SQL> connect <sys/passwd as sysdba>@target_database; 

SQL> execute dbms_backup_restore.resetConfig;



Q⟹ RMAN terminology 

A target database : An Oracle database to which RMAN is connected with the TARGET keyword. A target database is a database on which RMAN is performing backup and recovery operations. RMAN always maintains metadata about its operations on a database in the control file of the oracle database.

RMAN>rman target sys;

A recovery Catalog : A separate database schema used to record RMAN activity against one or more target databases. A recovery catalog preserves RMAN repository metadata if the control file is lost, making it much easier to restore and recover following the loss of the control file. The database may overwrite older records in the control file, but RMAN maintains records forever in the catalog unless deleted by the user.

Backup sets : RMAN can store backup data in a logical structure called a backup set, which is the smallest unit of an RMAN backup. One backup set contains one or more datafiles a section of datafile or archivelogs.

Backup Piece : A backup set contains one or more binary files in an RMAN-specific format. This file is known as a backup piece. Each backup piece is a single output file. The size of a backup piece can be restricted; if the size is not restricted, the backup set will comprise one backup piece. Backup piece size should be restricted to no larger than the maximum file size that your filesystem will support.

Image copies : An image copy is a copy of a single file (datafile, archivelog, or controlfile). It is very similar to an O/S copy of the file. It is not a backupset or a backup piece. No compression is performed.

Snapshot Controlfile : When RMAN needs to resynchronize from a read-consistent version of the control file, it creates a temporary snapshot control file. The default name for the snapshot control file is port-specific.

Database Incarnation : Whenever you perform incomplete recovery or perform recovery using a backup control file, you must reset the online redo logs when you open the database. The new version of the reset database is called a new incarnation. The reset database command directs RMAN to create a new database incarnation record in the recovery catalog. This new incarnation record indicates the current incarnation.



QWhat are the database file's that RMAN can backup?

A⟹RMAN can backup objects such as  Controlfile , Datafiles , Archive logs , standby database controfile, Spfile.


QWhat is RMAN consistent backup and inconsistent backup?

A⟹ A consistent backup occurs when the database is in a consistent state(not in open mode). That means backup of the database taken after a shutdown immediate , shutdown normal or shutdown transnational. If the database is shutdown with  abort option then it’s not a consistent backup.


A backup when the database is up and running is called an inconsistent backup. When a database is restored from an inconsistent backup, Oracle must perform media recovery before the database can be opened, applying any pending changes from the redo logs. You can not take inconsistent backup when the database is in No Archivelog mode.



QWhat is Oracle Secure backup?

A⟹ Oracle Secure Backup is a media manager provided by oracle that provides reliable and secure data protection through file system backup to tape. All major tape drives and tape libraries in SAN, Gigabit Ethernet, and SCSI environments are supported.