Oracle RMAN Backup and Recovery on Linux – Complete Step-by-Step Guide

Share:
Article Summary

Learn Oracle RMAN Backup and Recovery on Linux with this complete step-by-step guide covering backup strategies, restore, recovery, validation, and disaster recovery scenarios.

A complete production-ready SOP for Oracle RMAN backup and recovery on Linux. Covers RMAN configuration, full and incremental backups, archivelog backups, backup to tape, RMAN catalog setup, point-in-time recovery, tablespace and datafile recovery, block media recovery, RMAN duplicate, crosscheck and validation, backup encryption, and full post-backup validation — with real commands, expected outputs, and consultant-level notes for both standard OFA and enterprise custom path conventions.


1. Document Info

ItemDetail
Oracle Version19c (19.3+)
OSOracle Linux 7.x / RHEL 7.x or 8.x
Backup TypeDisk-based (FRA) + Tape (SBT)
Recovery CatalogOptional but recommended (covered)
DatabaseORCL (standalone)
FRA Location/u01/app/oracle/fast_recovery_area
MOS ReferenceDoc ID 1513912.1 (RMAN Best Practices)
MOS ReferenceDoc ID 1116108.1 (RMAN Performance Tuning)
MOS ReferenceDoc ID 2505669.1 (RMAN in 19c)
Prepared ByOracle DBA / Consultant

2. RMAN — Concepts You Must Know First

📝 What is RMAN? RMAN (Recovery Manager) is Oracle’s native backup and recovery tool. It is the only officially supported method for Oracle database backup and recovery. RMAN understands Oracle internals — it only backs up used blocks (not empty space), validates block integrity during backup, and integrates tightly with Data Guard, Flashback, and ASM.

📝 Why use RMAN instead of OS-level file copy? OS-level copy (cp, tar) of Oracle datafiles while the database is running creates inconsistent backups — some blocks may be mid-write at the time of copy. RMAN coordinates with the database to ensure consistent backups. Also RMAN can backup while the database is open — no downtime needed.


Key RMAN Concepts

ConceptWhat It Means
Full BackupBacks up all used blocks in the database. Does not reset the incremental baseline. Also called a Level 0 backup when used as an incremental base.
Incremental BackupLevel 0 = base backup (same as full but registers as incremental base). Level 1 = backs up only blocks changed since the last Level 0 or Level 1 backup.
Cumulative IncrementalLevel 1 CUMULATIVE = backs up all blocks changed since the last Level 0. Larger than differential but faster recovery.
Differential IncrementalLevel 1 = backs up only blocks changed since the last Level 0 OR Level 1. Smaller backup but slower recovery.
Archivelog BackupBacks up archived redo logs. Required for point-in-time recovery to any point between full backups.
Full Backup SetThe default RMAN backup format. Multiple blocks packed into a backup piece file. More compact than image copies.
Image CopyExact block-for-block copy of a datafile. Can be used directly by Oracle without restore step — faster recovery.
Backup PieceAn individual file produced by RMAN backup. Multiple pieces make up a backup set.
Recovery CatalogA separate Oracle database (schema) that stores RMAN repository information for all databases. Provides longer retention history than control file. Recommended for enterprise environments.
Control File AutobackupRMAN automatically backs up the control file after every backup and after structure changes. Essential — without control file you cannot restore the database.
FRA (Fast Recovery Area)A dedicated disk location managed by Oracle for backup files, archivelogs, and flashback logs. Oracle manages space automatically.
SBT (System Backup to Tape)RMAN interface to third-party tape/media managers (Veritas NetBackup, IBM TSM, etc.)
CROSSCHECKVerifies that backup pieces/copies listed in the repository actually exist on disk or tape.
VALIDATEChecks backup files for corruption without actually restoring them.
Block Media RecoveryRecovers individual corrupt blocks within a datafile without taking the datafile offline.
DUPLICATECreates a copy of a database (used for standby creation, test databases, migration).
Retention PolicyRules for how long RMAN keeps backups before marking them as obsolete.

RMAN Backup Strategy — Recommended Production Schedule

Backup TypeFrequencyDayRetention
Level 0 (Full base)WeeklySunday 01:00 AM4 weeks
Level 1 CumulativeDailyMon-Sat 01:00 AM1 week
ArchivelogEvery 4 hoursAll days3 days
Controlfile AutobackupAfter every RMAN runAutomaticWith DB backup

📝 Why cumulative instead of differential? Cumulative Level 1 is larger but recovery requires only 2 pieces of backup — the last Level 0 and the last Level 1 cumulative. Differential Level 1 creates smaller daily backups but recovery may need multiple Level 1 backups in sequence. In a recovery emergency, fewer backup pieces = faster recovery.


3. Path Conventions and Environment Details

ItemConvention AConvention B
Oracle Base/u01/app/oracle/oracle
Oracle Home/u01/app/oracle/product/19.3.0/dbhome_1/oracle/RDBMS/19.31
FRA Location/u01/app/oracle/fast_recovery_area/oracle/fast_recovery_area
FRA Size200 GB (adjust per environment)200 GB
Backup to Disk/u01/app/oracle/backup/oracle/backup
RMAN Catalog DBRMANCAT (separate DB or server)RMANCAT
Oracle SIDORCLORCL

4. Pre-Backup Checks

⚠️ IMPORTANT: Run all pre-checks before configuring RMAN or starting any backup. A backup that silently fails is worse than no backup — you think you are protected but you are not.


4.1 — Verify Database is in ARCHIVELOG Mode

📝 Why? RMAN online backups require ARCHIVELOG mode. Without it, RMAN can only do offline (cold) backups which require database downtime. All production databases must be in ARCHIVELOG mode.

sqlplus / as sysdba

set linesize 150
set pagesize 50
col name     for a12
col log_mode for a15

SELECT name, log_mode FROM v$database;

-- Detailed archivelog status
ARCHIVE LOG LIST;

⚠️ IMPORTANT: If database is in NOARCHIVELOG mode — switch to ARCHIVELOG mode immediately before configuring RMAN:

SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;
ARCHIVE LOG LIST;

4.2 — Check FRA Configuration

sqlplus / as sysdba

set linesize 200
set pagesize 50
col name  for a35
col value for a60

-- Check FRA parameters
SELECT name, value
FROM   v$parameter
WHERE  name IN (
    'db_recovery_file_dest',
    'db_recovery_file_dest_size',
    'log_archive_dest_1',
    'log_archive_format'
)
ORDER BY name;

4.3 — Check FRA Space Usage

-- Check FRA space usage
set linesize 200
set pagesize 100
col file_type          for a30
col percent_space_used for 999.99
col percent_space_reclaimable for 999.99
col number_of_files    for 999999

SELECT file_type,
       percent_space_used,
       percent_space_reclaimable,
       number_of_files
FROM   v$recovery_area_usage
ORDER BY file_type;

-- Overall FRA space
set linesize 200
col name               for a50
col space_limit_gb     for 9999.99
col space_used_gb      for 9999.99
col space_reclaimable_gb for 9999.99
col number_of_files    for 999999

SELECT name,
       space_limit/1024/1024/1024          space_limit_gb,
       space_used/1024/1024/1024           space_used_gb,
       space_reclaimable/1024/1024/1024    space_reclaimable_gb,
       number_of_files
FROM   v$recovery_file_dest;

⚠️ IMPORTANT: FRA space used above 85% is a warning. Above 95% Oracle starts refusing archive log generation which will crash the database. Monitor FRA space constantly and extend it before it fills up.


4.4 — Check Disk Space for Backup Destination

# Check disk space for FRA and backup destinations
df -hP /u01/app/oracle/fast_recovery_area
df -hP /u01/app/oracle/backup

# Convention B
df -hP /oracle/fast_recovery_area
df -hP /oracle/backup

4.5 — Verify All Datafiles are Online

sqlplus / as sysdba

set linesize 200
set pagesize 100
col file#           for 999
col tablespace_name for a25
col status          for a12
col name            for a70

-- All datafiles must be ONLINE before backup
SELECT file#, tablespace_name, status, name
FROM   v$datafile
WHERE  status != 'ONLINE'
ORDER BY file#;

-- Should return no rows -- if any rows returned fix before backup

4.6 — Check for Block Corruption Before Backup

📝 Why? Backing up a database that already has block corruption just backs up the corruption. Run a block check before backup to identify any existing corruption that needs to be fixed first.

-- Check v$database_block_corruption
set linesize 200
set pagesize 100
col file#      for 999
col block#     for 9999999
col blocks     for 9999
col corruption_type for a20

SELECT file#, block#, blocks, corruption_type
FROM   v$database_block_corruption
ORDER BY file#, block#;

-- No rows = no known corruption (good)

5. RMAN Configuration

📝 What is RMAN configuration? RMAN has persistent configuration settings stored in the control file (or catalog). These settings apply to every RMAN session automatically — you do not need to specify them every time you run a backup. Configure them once and they are remembered.


5.1 — Connect to RMAN

# Connect to target database only (no catalog)
su - oracle
rman target /

# Connect with catalog (if catalog is configured)
rman target / catalog rman_user/rman_password@RMANCAT

# Connect to specific database
rman target sys/Oracle_123@ORCL

# Verify connection
RMAN> SELECT name, db_unique_name FROM v$database;

5.2 — Show Current RMAN Configuration

-- Display all current RMAN configuration settings
RMAN> SHOW ALL;

Default output (before any configuration):

RMAN configuration parameters for database with db_unique_name ORCL are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
CONFIGURE BACKUP OPTIMIZATION OFF;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE MAXSETSIZE TO UNLIMITED;
CONFIGURE ENCRYPTION FOR DATABASE OFF;
CONFIGURE ENCRYPTION ALGORITHM 'AES128';
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE;
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE;
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/19.3.0/dbhome_1/dbs/snapcf_ORCL.f';

5.3 — Configure FRA (Fast Recovery Area)

📝 Why configure FRA? FRA is Oracle’s managed location for all recovery-related files. When configured, Oracle automatically manages space — deleting obsolete backups when space is needed for new ones (within the retention policy). FRA is the recommended backup destination for disk-based backups.

-- Configure FRA in the database (run as SYSDBA, not RMAN)
sqlplus / as sysdba

-- Set FRA location
-- Convention A
ALTER SYSTEM SET DB_RECOVERY_FILE_DEST=
    '/u01/app/oracle/fast_recovery_area'
    SCOPE=BOTH;

-- Convention B
-- ALTER SYSTEM SET DB_RECOVERY_FILE_DEST=
--     '/oracle/fast_recovery_area'
--     SCOPE=BOTH;

-- Set FRA size -- set to at least 3x your database size
ALTER SYSTEM SET DB_RECOVERY_FILE_DEST_SIZE=200G SCOPE=BOTH;

-- Verify
SHOW PARAMETER db_recovery_file_dest;

5.4 — Set RMAN Retention Policy

📝 What is retention policy? Defines how long RMAN keeps backups before marking them obsolete. Two types:

  • REDUNDANCY n — keep n copies of each datafile backup
  • RECOVERY WINDOW OF n DAYS — keep enough backups to recover to any point within the last n days

📝 Which to use? RECOVERY WINDOW is more predictable for compliance requirements. REDUNDANCY is simpler for operations. Most production environments use RECOVERY WINDOW OF 7 DAYS.

-- Connect to RMAN
rman target /

-- Set retention policy to recovery window of 7 days
-- This means RMAN keeps enough backups to recover to any point
-- in the last 7 days
RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

-- Alternative: keep exactly 2 copies of each backup
-- RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY 2;

-- Verify
RMAN> SHOW RETENTION POLICY;

5.5 — Configure Controlfile Autobackup

📝 Why is controlfile autobackup critical? The control file contains the RMAN backup repository when no catalog is used. If the control file is lost and there is no autobackup, you cannot restore the database because RMAN does not know where the backups are. Enable autobackup ALWAYS.

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;

-- Set the format for autobackup
-- %F = unique format including DB ID, timestamp
-- Convention A
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT
        FOR DEVICE TYPE DISK TO
        '/u01/app/oracle/fast_recovery_area/ORCL/autobackup/%F';

-- Convention B
-- RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT
--         FOR DEVICE TYPE DISK TO
--         '/oracle/fast_recovery_area/ORCL/autobackup/%F';

-- Verify
RMAN> SHOW CONTROLFILE AUTOBACKUP;

5.6 — Configure Backup Parallelism

📝 Why parallelize? RMAN can use multiple channels to backup simultaneously — like having multiple backup streams running at the same time. More channels = faster backup. The optimal number of channels equals the number of available disk spindles or CPU cores (whichever is smaller).

-- Configure parallelism for disk backups
-- PARALLELISM 4 = use 4 simultaneous backup channels
RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO BACKUPSET;

-- For tape (SBT) -- match number of tape drives available
-- RMAN> CONFIGURE DEVICE TYPE SBT PARALLELISM 2 BACKUP TYPE TO BACKUPSET;

-- Verify
RMAN> SHOW DEVICE TYPE;

5.7 — Configure Backup Optimization

📝 Why enable optimization? Backup optimization tells RMAN to skip backing up files that have already been backed up and have not changed — specifically archivelogs and datafiles that are already backed up to the required redundancy. Saves significant time on large databases with stable data.

RMAN> CONFIGURE BACKUP OPTIMIZATION ON;

-- Verify
RMAN> SHOW BACKUP OPTIMIZATION;

5.8 — Configure Backup Compression

📝 Why compress? RMAN compression reduces backup size significantly — typically 50-70% reduction for typical Oracle data. Reduces disk space needed and speeds up network transfer for off-site backup. The trade-off is CPU overhead during backup.

📝 Compression algorithms:

  • BASIC — low CPU, moderate compression. Available without Advanced Compression license.
  • LOW — very fast, less compression. Requires Advanced Compression license.
  • MEDIUM — balanced. Requires Advanced Compression license.
  • HIGH — best compression, highest CPU. Requires Advanced Compression license.
-- BASIC compression (no license required)
RMAN> CONFIGURE COMPRESSION ALGORITHM 'BASIC';

-- Enable compression for backups (set in backup command or globally)
-- Using compression in the BACKUP command:
-- BACKUP AS COMPRESSED BACKUPSET DATABASE;

-- Verify compression setting
RMAN> SHOW COMPRESSION ALGORITHM;

5.9 — Configure Archivelog Deletion Policy

📝 Why configure deletion policy? Controls when RMAN deletes archivelogs from the FRA after they have been backed up. Setting this correctly prevents the FRA from filling up with archivelogs that have already been safely backed up.

-- Delete archivelogs only after they have been backed up at least once
-- AND only after they have been applied on all registered standby databases
RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO DISK;

-- For Data Guard environment:
-- RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;

-- Verify
RMAN> SHOW ARCHIVELOG DELETION POLICY;

5.10 — Configure Snapshot Controlfile Location

📝 Why? When RMAN backs up the control file, it creates a snapshot (temporary consistent copy) of the control file first. The default location is inside ORACLE_HOME which may not have enough space. Move it to FRA or backup area.

-- Convention A
RMAN> CONFIGURE SNAPSHOT CONTROLFILE NAME TO
        '/u01/app/oracle/fast_recovery_area/ORCL/snapcf_ORCL.f';

-- Convention B
-- RMAN> CONFIGURE SNAPSHOT CONTROLFILE NAME TO
--         '/oracle/fast_recovery_area/ORCL/snapcf_ORCL.f';

RMAN> SHOW SNAPSHOT CONTROLFILE NAME;

5.11 — Verify All RMAN Configuration Settings

-- Display complete RMAN configuration after all settings
RMAN> SHOW ALL;

6. RMAN Catalog Setup (Optional but Recommended)

📝 What is the RMAN Recovery Catalog? The catalog is a separate Oracle database schema that stores RMAN repository information for all your target databases. Instead of RMAN storing backup metadata only in the control file (which can be lost with the database), the catalog stores it externally. The catalog provides:

  • Longer backup history than the control file allows
  • Stored scripts that can be shared across databases
  • Ability to recover a database even if you lose the entire control file
  • Central reporting on all database backups

📝 When is a catalog mandatory? In large environments with many databases, the catalog is effectively mandatory for proper backup management. For single databases in small environments, control file only is acceptable.


6.1 — Create RMAN Catalog Database and Schema

-- On CATALOG DATABASE SERVER (a separate Oracle DB -- RMANCAT)
sqlplus / as sysdba

-- Create dedicated tablespace for RMAN catalog
CREATE TABLESPACE rman_ts
    DATAFILE '/u01/app/oracle/oradata/RMANCAT/rman_ts01.dbf'
    SIZE 5G
    AUTOEXTEND ON NEXT 1G MAXSIZE 50G;

-- Create RMAN catalog owner user
CREATE USER rman_user
    IDENTIFIED BY Rman_Password_123
    DEFAULT TABLESPACE rman_ts
    TEMPORARY TABLESPACE temp
    QUOTA UNLIMITED ON rman_ts;

-- Grant RECOVERY_CATALOG_OWNER role
-- This role contains all privileges needed to own and manage the catalog
GRANT RECOVERY_CATALOG_OWNER TO rman_user;
GRANT CREATE SESSION TO rman_user;

-- Verify
SELECT username, default_tablespace
FROM   dba_users
WHERE  username = 'RMAN_USER';

6.2 — Create the Catalog Schema

# Connect to RMAN as catalog owner
rman catalog rman_user/Rman_Password_123@RMANCAT
-- Create the catalog schema (creates all catalog tables)
-- This takes 1-2 minutes
RMAN> CREATE CATALOG;

Expected output:

recovery catalog created

6.3 — Register Target Database with Catalog

# Connect to RMAN with both target and catalog
rman target sys/Oracle_123@ORCL catalog rman_user/Rman_Password_123@RMANCAT
-- Register the target database in the catalog
RMAN> REGISTER DATABASE;

Expected output:

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
-- Verify registration
RMAN> REPORT SCHEMA;

6.4 — Create Stored Scripts in Catalog

📝 Why stored scripts? Stored scripts are RMAN scripts saved in the catalog that can be executed by name. They standardize backup procedures across all DBAs and can be shared across multiple databases.

-- Create a full database backup script
RMAN> CREATE SCRIPT full_db_backup
{
   BACKUP AS COMPRESSED BACKUPSET
   INCREMENTAL LEVEL 0
   DATABASE
   FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/backupset/full_%d_%T_%s_%p'
   TAG 'WEEKLY_FULL';

   BACKUP ARCHIVELOG ALL
   FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/archivelog/arch_%d_%T_%s_%p'
   DELETE INPUT
   TAG 'ARCH_WITH_FULL';

   DELETE NOPROMPT OBSOLETE;
}

-- Create incremental backup script
RMAN> CREATE SCRIPT incr_db_backup
{
   BACKUP AS COMPRESSED BACKUPSET
   INCREMENTAL LEVEL 1 CUMULATIVE
   DATABASE
   FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/backupset/incr_%d_%T_%s_%p'
   TAG 'DAILY_INCR';

   BACKUP ARCHIVELOG ALL
   FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/archivelog/arch_%d_%T_%s_%p'
   DELETE INPUT
   TAG 'ARCH_WITH_INCR';
}

-- List stored scripts
RMAN> LIST SCRIPT NAMES;

-- Execute a stored script
RMAN> EXECUTE SCRIPT full_db_backup;

7. RMAN Backup Operations


7.1 — Full Database Backup (Level 0)

📝 What does Level 0 mean? Level 0 is a full backup that also serves as the base for subsequent incremental backups. It backs up ALL used blocks in the database. Run this weekly.

su - oracle
rman target /
-- Full database backup with compressed backupset
-- Including archivelog backup and control file
BACKUP AS COMPRESSED BACKUPSET
    INCREMENTAL LEVEL 0
    DATABASE
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/backupset/full_%d_%T_%s_%p'
    TAG 'WEEKLY_FULL_BACKUP'
    PLUS ARCHIVELOG
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/archivelog/arch_%d_%T_%s_%p'
    DELETE INPUT;

-- Immediately after full backup -- delete obsolete backups
DELETE NOPROMPT OBSOLETE;

-- Verify backup completed successfully
LIST BACKUP SUMMARY;

7.2 — Incremental Level 1 Backup (Daily)

📝 What does incremental backup contain? Only blocks that have changed since the last Level 0 backup (or last Level 1 if differential). Significantly smaller and faster than Level 0. Run daily between weekly full backups.

-- Daily cumulative incremental backup
-- CUMULATIVE = back up all changes since last Level 0
BACKUP AS COMPRESSED BACKUPSET
    INCREMENTAL LEVEL 1 CUMULATIVE
    DATABASE
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/backupset/incr_%d_%T_%s_%p'
    TAG 'DAILY_INCR_BACKUP'
    PLUS ARCHIVELOG
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/archivelog/arch_%d_%T_%s_%p'
    DELETE INPUT;

-- Verify
LIST BACKUP SUMMARY;

7.3 — Archivelog Backup Only

📝 Why backup archivelogs separately? Archivelogs fill up the FRA quickly. Backing them up regularly (every 4 hours) and deleting them from the FRA after backup keeps FRA space usage under control while ensuring they are safely stored.

-- Backup all unbackedup archivelogs
-- DELETE INPUT removes them from disk after backup
BACKUP
    ARCHIVELOG ALL
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/archivelog/arch_%d_%T_%s_%p'
    DELETE INPUT
    TAG 'ARCHIVELOG_BACKUP';

-- Backup archivelogs from last 4 hours only
BACKUP
    ARCHIVELOG FROM TIME 'SYSDATE-1/6'
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/archivelog/arch_%d_%T_%s_%p'
    TAG 'ARCHIVELOG_4H';

-- Verify
LIST ARCHIVELOG ALL;

7.4 — Backup Specific Tablespace

📝 When to use? After making significant changes to a specific tablespace (large data load, schema change) — backup just that tablespace immediately without waiting for the nightly backup.

-- Backup specific tablespaces
BACKUP
    TABLESPACE users, example
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/backupset/ts_%d_%T_%s_%p'
    TAG 'TABLESPACE_BACKUP';

-- With archivelogs for consistent recovery
BACKUP
    TABLESPACE users
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/backupset/ts_%d_%T_%s_%p'
    TAG 'USERS_TS_BACKUP'
    PLUS ARCHIVELOG
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/archivelog/arch_%d_%T_%s_%p';

LIST BACKUP OF TABLESPACE users;

7.5 — Backup Control File and SPFILE

📝 Why separate controlfile backup? The controlfile contains the database structure and RMAN backup catalog. If lost, recovery becomes extremely difficult. Back it up explicitly and often, especially after any structural changes (adding tablespaces, datafiles etc.).

-- Backup controlfile explicitly
BACKUP CURRENT CONTROLFILE
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/ctrl/ctrl_%d_%T_%s_%p'
    TAG 'CONTROLFILE_BACKUP';

-- Backup SPFILE
BACKUP SPFILE
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/spfile/spfile_%d_%T_%s_%p'
    TAG 'SPFILE_BACKUP';

-- Backup both together
BACKUP CURRENT CONTROLFILE
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/ctrl/ctrl_%d_%T_%s_%p'
    INCLUDE CURRENT CONTROLFILE SPFILE;

LIST BACKUP OF CONTROLFILE;
LIST BACKUP OF SPFILE;

7.6 — Backup to Tape (SBT Channel)

📝 What is SBT? System Backup to Tape — RMAN’s interface to third-party media managers like Veritas NetBackup, IBM Spectrum Protect (TSM), Commvault, and others. The media manager provides a shared library (sbt_tape) that RMAN loads to communicate with the tape system.

-- Configure SBT channel for tape backup
-- The parms string is specific to your tape media manager
-- Example shown for Veritas NetBackup:
CONFIGURE CHANNEL DEVICE TYPE SBT
    PARMS 'SBT_LIBRARY=/usr/openv/netbackup/bin/nbora,
           ENV=(NB_ORA_SERV=netbackup_server,
           NB_ORA_CLASS=Oracle_Backup_Policy)';

-- Backup to tape using SBT
BACKUP
    DEVICE TYPE SBT
    DATABASE
    FORMAT 'ORCL_%d_%T_%s_%p'
    TAG 'TAPE_FULL_BACKUP'
    PLUS ARCHIVELOG
    DELETE INPUT;

-- Backup to both disk AND tape simultaneously
BACKUP
    DATABASE
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/backupset/%d_%T_%s_%p'
    PLUS ARCHIVELOG;

BACKUP
    DEVICE TYPE SBT
    BACKUPSET ALL;

7.7 — RMAN Backup with Encryption

📝 Why encrypt backups? Backup files stored on disk or tape can be stolen. Encrypting RMAN backups ensures backup files are unreadable without the encryption key. This is separate from TDE (which encrypts the database itself). RMAN backup encryption encrypts the backup files on media.

📝 Two encryption modes:

  • TRANSPARENT — uses TDE wallet. Requires TDE to be configured. Key managed by Oracle wallet.
  • PASSWORD — uses a password you provide. No TDE required but password must be available during restore.
-- Enable transparent encryption (uses TDE wallet -- preferred)
-- TDE must be configured and wallet must be open
CONFIGURE ENCRYPTION FOR DATABASE ON;
CONFIGURE ENCRYPTION ALGORITHM 'AES256';

-- Backup with transparent encryption
BACKUP AS ENCRYPTED BACKUPSET
    DATABASE
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/backupset/enc_%d_%T_%s_%p'
    TAG 'ENCRYPTED_FULL_BACKUP';

-- Enable password-based encryption (no TDE required)
SET ENCRYPTION ON IDENTIFIED BY BackupEncPwd_123 ONLY;

BACKUP AS ENCRYPTED BACKUPSET
    DATABASE
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/backupset/enc_%d_%T_%s_%p'
    TAG 'PWD_ENCRYPTED_BACKUP';

-- Verify encryption setting
SHOW ENCRYPTION FOR DATABASE;
SHOW ENCRYPTION ALGORITHM;

7.8 — Multisection Backup (Large Files)

📝 Why multisection? For very large datafiles (hundreds of GBs to TBs), a single file cannot be parallelized across channels. Multisection backup splits a single large file into sections that can be backed up in parallel — dramatically reducing backup time for VLDB (Very Large Database) environments.

-- Enable multisection backup
-- Each section is 32GB -- adjust based on file size
BACKUP
    AS COMPRESSED BACKUPSET
    DATABASE
    SECTION SIZE 32G
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/backupset/ms_%d_%T_%s_%p'
    TAG 'MULTISECTION_FULL';

LIST BACKUP SUMMARY;

8. RMAN Backup Validation and Crosscheck


8.1 — List Backup Summary

-- Complete backup listing
RMAN> LIST BACKUP SUMMARY;

-- Detailed listing
RMAN> LIST BACKUP;

-- List backups of specific type
RMAN> LIST BACKUP OF DATABASE;
RMAN> LIST BACKUP OF ARCHIVELOG ALL;
RMAN> LIST BACKUP OF CONTROLFILE;
RMAN> LIST BACKUP OF SPFILE;

-- List backups from last 7 days
RMAN> LIST BACKUP COMPLETED AFTER 'SYSDATE-7';

-- List expired backups
RMAN> LIST EXPIRED BACKUP;

8.2 — Crosscheck Backups

📝 What is crosscheck? Crosscheck compares what RMAN believes exists (from its repository in control file or catalog) against what actually exists on disk or tape. If a backup file was manually deleted or corrupted, crosscheck marks it as EXPIRED in the repository.

-- Crosscheck all backups on disk
RMAN> CROSSCHECK BACKUP;

-- Crosscheck specific backup types
RMAN> CROSSCHECK BACKUP OF DATABASE;
RMAN> CROSSCHECK BACKUP OF ARCHIVELOG ALL;
RMAN> CROSSCHECK BACKUP OF CONTROLFILE;

-- Crosscheck tape backups
RMAN> CROSSCHECK BACKUP DEVICE TYPE SBT;

-- After crosscheck -- list expired backups
RMAN> LIST EXPIRED BACKUP;

-- Delete expired backups from repository
RMAN> DELETE NOPROMPT EXPIRED BACKUP;

8.3 — Validate Backups (Check for Corruption)

📝 What does validate do? VALIDATE reads backup pieces and checks every block for corruption — without actually restoring anything. Use it regularly to confirm your backups are restorable.

-- Validate all backups (reads backup pieces and checks block integrity)
-- This can take a while for large databases
RMAN> VALIDATE BACKUPSET ALL;

-- Validate specific backup set
RMAN> VALIDATE BACKUPSET <backupset_key>;

-- Validate database backup (simulates restore without writing files)
RMAN> RESTORE DATABASE VALIDATE;

-- Validate specific tablespace restore
RMAN> RESTORE TABLESPACE users VALIDATE;

-- Validate that database can be recovered to current time
RMAN> RESTORE DATABASE VALIDATE PREVIEW;

-- After validate -- check for any corruption found
SELECT *
FROM   v$database_block_corruption;

8.4 — Delete Obsolete Backups

📝 Why delete obsolete? RMAN tracks which backups are obsolete based on the retention policy. Deleting them reclaims disk/tape space. RMAN only deletes backups that are no longer needed to meet the retention policy.

-- Preview what would be deleted (REPORT first, then DELETE)
RMAN> REPORT OBSOLETE;

-- Delete obsolete backups (confirms before deleting)
RMAN> DELETE OBSOLETE;

-- Delete without confirmation prompt (for scripts)
RMAN> DELETE NOPROMPT OBSOLETE;

-- Delete obsolete backups for a specific retention window override
RMAN> DELETE OBSOLETE RECOVERY WINDOW OF 14 DAYS;

8.5 — Report Database Structure and Backup Requirements

-- Report current database file structure
RMAN> REPORT SCHEMA;

-- Report files that need backup
-- Files needing backup according to retention policy
RMAN> REPORT NEED BACKUP;

-- Files unrecoverable (no backup exists)
RMAN> REPORT UNRECOVERABLE;

-- Files not backed up in last 2 days
RMAN> REPORT NEED BACKUP DAYS 2;

9. RMAN Recovery Operations

⚠️ IMPORTANT: Recovery is a high-stress operation usually performed during an outage. Prepare and practice these procedures in a non-production environment BEFORE you ever need them in production. Know these steps by heart.

📝 Recovery scenario decision tree:

  • Lost one or few datafiles → Section 9.2 (Datafile Recovery)
  • Lost entire database → Section 9.3 (Complete Database Recovery)
  • Need specific point in time → Section 9.4 (PITR)
  • Lost control file → Section 9.5 (Control File Recovery)
  • Corrupt blocks in datafile → Section 9.6 (Block Media Recovery)
  • Lost tablespace → Section 9.7 (Tablespace Recovery)

9.1 — Pre-Recovery Checklist

⚠️ IMPORTANT: Before starting any recovery, complete this checklist.

# 1. Identify exactly what is missing or corrupt
sqlplus / as sysdba
-- Check what is missing
SELECT file#, name, status FROM v$datafile WHERE status != 'ONLINE';
SELECT * FROM v$recover_file;
SELECT * FROM v$database_block_corruption;

-- Check alert log for error details
EXIT;
# 2. Check available backups
rman target /
RMAN> LIST BACKUP SUMMARY;
RMAN> LIST BACKUP OF DATABASE COMPLETED AFTER 'SYSDATE-7';

-- Check what is available for recovery
RMAN> RESTORE DATABASE PREVIEW;
# 3. Confirm FRA has sufficient space for recovery
df -hP /u01/app/oracle/fast_recovery_area

9.2 — Datafile Recovery (One or More Datafiles Lost)

📝 Scenario: One or more datafiles are missing (accidentally deleted, disk failure, filesystem corruption). Database is either still running with that tablespace offline, or database is mounted but not open.

-- Step 1: Identify missing/corrupt datafile
sqlplus / as sysdba

SELECT file#, name, status
FROM   v$datafile
WHERE  status != 'ONLINE';

SELECT * FROM v$recover_file;
-- Step 2: Take offline the affected datafile (if DB is open)
-- Skip this if DB is already not open
ALTER DATABASE DATAFILE '/u01/app/oracle/oradata/ORCL/users01.dbf' OFFLINE;
# Step 3: Restore and recover the specific datafile
rman target /
-- Restore the missing datafile
RESTORE DATAFILE '/u01/app/oracle/oradata/ORCL/users01.dbf';

-- Alternative: restore by file number
RESTORE DATAFILE 5;

-- Recover the datafile (applies archivelogs to bring it current)
RECOVER DATAFILE '/u01/app/oracle/oradata/ORCL/users01.dbf';

-- Alternative: recover by file number
RECOVER DATAFILE 5;
-- Step 4: Bring the datafile back online
sqlplus / as sysdba

ALTER DATABASE DATAFILE '/u01/app/oracle/oradata/ORCL/users01.dbf' ONLINE;

-- Verify
SELECT file#, name, status FROM v$datafile WHERE file# = 5;

9.3 — Complete Database Recovery (All Datafiles Lost)

📝 Scenario: Complete database loss — all datafiles, redo logs, and possibly control files are gone. Server rebuilt on same or new hardware. This is the worst-case scenario.

# Step 1: Set Oracle environment
export ORACLE_SID=ORCL
export ORACLE_HOME=/u01/app/oracle/product/19.3.0/dbhome_1

# Step 2: Create required directories if they do not exist
mkdir -p /u01/app/oracle/oradata/ORCL
mkdir -p /u01/app/oracle/fast_recovery_area
mkdir -p /u01/app/oracle/admin/ORCL/adump

# Step 3: Start RMAN and connect to target
rman target /
-- Step 4: Start instance in NOMOUNT (only init.ora/spfile needed)
-- If spfile is also lost, create a minimal pfile first
STARTUP NOMOUNT;

-- Step 5: Restore the SPFILE from autobackup
-- Replace <DBID> with your actual database ID
SET DBID <DBID>;
RESTORE SPFILE FROM AUTOBACKUP;

-- Restart with restored spfile
STARTUP FORCE NOMOUNT;

-- Step 6: Restore control file from autobackup
RESTORE CONTROLFILE FROM AUTOBACKUP;

-- Step 7: Mount the database
ALTER DATABASE MOUNT;

-- Step 8: Restore the entire database
RESTORE DATABASE;

-- Step 9: Recover the database (apply archivelogs)
RECOVER DATABASE;

-- Step 10: Open database with RESETLOGS (always required after full recovery)
ALTER DATABASE OPEN RESETLOGS;

-- Step 11: Verify database is open and healthy
SELECT name, open_mode FROM v$database;
-- Step 12: Check for INVALID objects after recovery
sqlplus / as sysdba

SELECT COUNT(*) FROM dba_objects WHERE status = 'INVALID';

-- Recompile if needed
@?/rdbms/admin/utlrp.sql

9.4 — Point-in-Time Recovery (PITR)

📝 Scenario: A user accidentally dropped a table or corrupted data at 2:00 PM and you need to recover the database to 1:55 PM. PITR restores the database to a specific point in time, recovering all data that existed at that moment.

⚠️ IMPORTANT: PITR recovers the ENTIRE database to a point in time — all changes after that time are lost across the entire database. If only one tablespace or table needs recovery, use Flashback (if enabled) or Tablespace PITR instead.

rman target /
-- Identify the target time or SCN
-- First check what time the problem occurred
-- Ask user when they ran the bad statement

-- Option A: Recovery to specific time
-- Shutdown database first
SHUTDOWN IMMEDIATE;
STARTUP MOUNT;

-- Set time for recovery
RUN {
    SET UNTIL TIME "TO_DATE('2024-01-15 13:55:00','YYYY-MM-DD HH24:MI:SS')";
    RESTORE DATABASE;
    RECOVER DATABASE;
}

-- Open with RESETLOGS (mandatory after PITR)
ALTER DATABASE OPEN RESETLOGS;

-- Option B: Recovery to specific SCN (more precise)
-- Get SCN from flashback query or logminer if needed
SHUTDOWN IMMEDIATE;
STARTUP MOUNT;

RUN {
    SET UNTIL SCN 1234567;
    RESTORE DATABASE;
    RECOVER DATABASE;
}

ALTER DATABASE OPEN RESETLOGS;

9.5 — Control File Recovery

📝 Scenario: All copies of the control file are lost. Database cannot start because it cannot find the control file.

# Step 1: Start RMAN
rman target /
-- Step 2: Start in NOMOUNT
STARTUP NOMOUNT;

-- Step 3: Restore control file from autobackup
-- If you know the autobackup path:
RESTORE CONTROLFILE FROM
    '/u01/app/oracle/fast_recovery_area/ORCL/autobackup/2024_01_15/o1_mf_s_12345_%.bkp';

-- Or restore from autobackup (RMAN searches FRA automatically)
RESTORE CONTROLFILE FROM AUTOBACKUP;

-- Or restore from specific backup set
RESTORE CONTROLFILE FROM BACKUPSET <key>;

-- Step 4: Mount the database
ALTER DATABASE MOUNT;

-- Step 5: Recover database (apply archivelogs)
RECOVER DATABASE;

-- Step 6: Open with RESETLOGS
ALTER DATABASE OPEN RESETLOGS;

-- Step 7: Resync catalog if using catalog
RESYNC CATALOG;

9.6 — Block Media Recovery (BMR)

📝 What is BMR? Block Media Recovery allows RMAN to recover individual corrupt blocks within a datafile without taking the datafile offline. This is the least disruptive recovery method — the tablespace stays online and other blocks in the same datafile are still accessible during recovery.

📝 How to identify corrupt blocks? From alert log (ORA-01578, ORA-01110) or from v$database_block_corruption.

-- First identify corrupt blocks
sqlplus / as sysdba

set linesize 200
set pagesize 100
col corruption_type for a20

SELECT file#, block#, blocks, corruption_type
FROM   v$database_block_corruption;

-- Also check alert log for ORA-01578 errors
EXIT;
rman target /
-- Recover specific corrupt blocks (database stays OPEN)
-- Syntax: RECOVER DATAFILE <file#> BLOCK <block#>

-- Example: recover blocks 100-105 in datafile 5
RECOVER DATAFILE 5 BLOCK 100, 101, 102, 103, 104, 105;

-- Example: recover a range of blocks
RECOVER DATAFILE 5 BLOCK 100 TO 105;

-- Recover all corrupt blocks found in v$database_block_corruption
RECOVER CORRUPTION LIST;

-- After BMR -- verify corruption is cleared
-- Verify no corrupt blocks remain
sqlplus / as sysdba
SELECT file#, block#, blocks, corruption_type
FROM   v$database_block_corruption;
-- Should return no rows

9.7 — Tablespace Point-in-Time Recovery (TSPITR)

📝 What is TSPITR? Allows you to recover a specific tablespace to a point in the past while keeping the rest of the database at the current point in time. This is much less disruptive than full database PITR because only the affected tablespace is rolled back.

📝 Limitation: Objects in the recovered tablespace cannot have dependencies on objects in other tablespaces (foreign keys etc.). Check dependencies before TSPITR.

rman target /
-- Check for dependencies that would block TSPITR
-- Run this first to see if TSPITR is feasible
RMAN> TSPITR TABLESPACE users UNTIL TIME
        "TO_DATE('2024-01-15 13:55:00','YYYY-MM-DD HH24:MI:SS')";

-- Actual TSPITR execution
RUN {
    -- Auxiliary destination is where RMAN creates a temp instance
    SET AUXILIARY DESTINATION '/u01/app/oracle/tspitr_aux';

    RECOVER TABLESPACE users
    UNTIL TIME "TO_DATE('2024-01-15 13:55:00','YYYY-MM-DD HH24:MI:SS')"
    AUXILIARY DESTINATION '/u01/app/oracle/tspitr_aux';
}

-- After TSPITR -- tablespace is recovered and back online
-- Verify
sqlplus / as sysdba
SELECT tablespace_name, status FROM dba_tablespaces WHERE tablespace_name = 'USERS';
SELECT file#, name, status FROM v$datafile WHERE ts# IN
    (SELECT ts# FROM v$tablespace WHERE name = 'USERS');

10. RMAN Duplicate Database

📝 What is RMAN DUPLICATE? Creates a copy of a database on the same or different server. Used for:

  • Creating standby databases (covered in DG SOP)
  • Creating test/dev copies of production
  • Database migration (to new server, new storage)
  • Cloning for application testing

10.1 — Duplicate for Test/Dev Environment

# On TARGET (duplicate) server -- start instance in NOMOUNT
export ORACLE_SID=TESTDB
sqlplus / as sysdba
STARTUP NOMOUNT PFILE='/u01/app/oracle/product/19.3.0/dbhome_1/dbs/initTESTDB.ora';
EXIT;
# From SOURCE server -- run RMAN duplicate
rman target sys/Oracle_123@ORCL auxiliary sys/Oracle_123@TESTDB
-- Duplicate from active database (no backup needed)
DUPLICATE TARGET DATABASE TO testdb
    FROM ACTIVE DATABASE
    SPFILE
        SET DB_UNIQUE_NAME='TESTDB'
        SET DB_NAME='TESTDB'
        SET DB_FILE_NAME_CONVERT=
            '/u01/app/oracle/oradata/ORCL',
            '/u01/app/oracle/oradata/TESTDB'
        SET LOG_FILE_NAME_CONVERT=
            '/u01/app/oracle/oradata/ORCL',
            '/u01/app/oracle/oradata/TESTDB'
        SET LOG_ARCHIVE_DEST_1=
            'LOCATION=/u01/app/oracle/fast_recovery_area/TESTDB'
        SET AUDIT_FILE_DEST='/u01/app/oracle/admin/TESTDB/adump'
        SET DIAGNOSTIC_DEST='/u01/app/oracle'
    NOFILENAMECHECK;

-- After duplication verify new database
RMAN> CONNECT TARGET sys/Oracle_123@TESTDB
RMAN> REPORT SCHEMA;

11. RMAN in RAC Environment

📝 What is different about RMAN in RAC? In a RAC environment, RMAN can use channels on multiple nodes simultaneously for faster backup and recovery. The backup repository is shared (in the control file or catalog). Backup and recovery operations can be initiated from any node.


11.1 — Configure RMAN Channels for RAC

-- Connect to RAC database
rman target /

-- Configure channels across multiple nodes
CONFIGURE CHANNEL 1 DEVICE TYPE DISK
    CONNECT 'sys/Oracle_123@RACDB1'
    FORMAT '/u01/app/oracle/fast_recovery_area/RACDB/backupset/node1_%d_%T_%s_%p';

CONFIGURE CHANNEL 2 DEVICE TYPE DISK
    CONNECT 'sys/Oracle_123@RACDB1'
    FORMAT '/u01/app/oracle/fast_recovery_area/RACDB/backupset/node1_%d_%T_%s_%p';

CONFIGURE CHANNEL 3 DEVICE TYPE DISK
    CONNECT 'sys/Oracle_123@RACDB2'
    FORMAT '/u01/app/oracle/fast_recovery_area/RACDB/backupset/node2_%d_%T_%s_%p';

CONFIGURE CHANNEL 4 DEVICE TYPE DISK
    CONNECT 'sys/Oracle_123@RACDB2'
    FORMAT '/u01/app/oracle/fast_recovery_area/RACDB/backupset/node2_%d_%T_%s_%p';

11.2 — RAC Full Backup Using Multiple Nodes

-- Backup using all configured channels (runs on both nodes simultaneously)
BACKUP AS COMPRESSED BACKUPSET
    INCREMENTAL LEVEL 0
    DATABASE
    TAG 'RAC_WEEKLY_FULL'
    PLUS ARCHIVELOG
    DELETE INPUT;

LIST BACKUP SUMMARY;

12. Automated Backup Scripts

📝 Why automate? Manual backups are error-prone and easy to forget. Automate all backup types and schedule them using cron. Every production database must have automated backup scripts.


12.1 — Create Full Backup Shell Script

# Create full backup script
vi /u01/app/oracle/admin/ORCL/scripts/rman_full_backup.sh
#!/bin/bash
# -------------------------------------------------------
# RMAN Full Backup Script — Level 0
# Schedule: Every Sunday at 01:00 AM
# File: /u01/app/oracle/admin/ORCL/scripts/rman_full_backup.sh
# -------------------------------------------------------

# Set Oracle environment
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/19.3.0/dbhome_1
export ORACLE_SID=ORCL
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib

# Log file location
LOG_DIR=/u01/app/oracle/admin/ORCL/rman_logs
mkdir -p $LOG_DIR
LOG_FILE=$LOG_DIR/rman_full_$(date +%Y%m%d_%H%M%S).log

# Run RMAN full backup
$ORACLE_HOME/bin/rman target / << EOF >> $LOG_FILE 2>&1

-- Log the backup start time
SQL "SELECT TO_CHAR(SYSDATE,''YYYY-MM-DD HH24:MI:SS'') start_time FROM dual";

-- Full Level 0 backup
BACKUP AS COMPRESSED BACKUPSET
    INCREMENTAL LEVEL 0
    DATABASE
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/backupset/full_%d_%T_%s_%p'
    TAG 'WEEKLY_FULL_BACKUP'
    PLUS ARCHIVELOG
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/archivelog/arch_%d_%T_%s_%p'
    DELETE INPUT;

-- Delete obsolete backups
DELETE NOPROMPT OBSOLETE;

-- List backup summary
LIST BACKUP SUMMARY;

-- Log the backup end time
SQL "SELECT TO_CHAR(SYSDATE,''YYYY-MM-DD HH24:MI:SS'') end_time FROM dual";

EXIT;
EOF

# Check if backup succeeded
RMAN_EXIT=$?
if [ $RMAN_EXIT -eq 0 ]; then
    echo "$(date): RMAN full backup completed successfully" >> $LOG_FILE
else
    echo "$(date): RMAN full backup FAILED with exit code $RMAN_EXIT" >> $LOG_FILE
    # Send alert email if mail is configured
    echo "RMAN full backup FAILED for ORCL on $(hostname)" | \
        mail -s "RMAN BACKUP FAILURE - $(hostname) - $(date)" dba@company.com
fi

# Keep log files for 30 days
find $LOG_DIR -name "rman_full_*.log" -mtime +30 -delete

exit $RMAN_EXIT
chmod 750 /u01/app/oracle/admin/ORCL/scripts/rman_full_backup.sh

12.2 — Create Incremental Backup Shell Script

vi /u01/app/oracle/admin/ORCL/scripts/rman_incr_backup.sh
#!/bin/bash
# -------------------------------------------------------
# RMAN Incremental Backup Script — Level 1 Cumulative
# Schedule: Monday-Saturday at 01:00 AM
# File: /u01/app/oracle/admin/ORCL/scripts/rman_incr_backup.sh
# -------------------------------------------------------

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/19.3.0/dbhome_1
export ORACLE_SID=ORCL
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib

LOG_DIR=/u01/app/oracle/admin/ORCL/rman_logs
mkdir -p $LOG_DIR
LOG_FILE=$LOG_DIR/rman_incr_$(date +%Y%m%d_%H%M%S).log

$ORACLE_HOME/bin/rman target / << EOF >> $LOG_FILE 2>&1

SQL "SELECT TO_CHAR(SYSDATE,''YYYY-MM-DD HH24:MI:SS'') start_time FROM dual";

BACKUP AS COMPRESSED BACKUPSET
    INCREMENTAL LEVEL 1 CUMULATIVE
    DATABASE
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/backupset/incr_%d_%T_%s_%p'
    TAG 'DAILY_INCR_BACKUP'
    PLUS ARCHIVELOG
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/archivelog/arch_%d_%T_%s_%p'
    DELETE INPUT;

DELETE NOPROMPT OBSOLETE;

LIST BACKUP SUMMARY;

SQL "SELECT TO_CHAR(SYSDATE,''YYYY-MM-DD HH24:MI:SS'') end_time FROM dual";

EXIT;
EOF

RMAN_EXIT=$?
if [ $RMAN_EXIT -ne 0 ]; then
    echo "$(date): RMAN incremental backup FAILED with exit code $RMAN_EXIT" >> $LOG_FILE
    echo "RMAN incremental backup FAILED for ORCL on $(hostname)" | \
        mail -s "RMAN BACKUP FAILURE - $(hostname) - $(date)" dba@company.com
fi

find $LOG_DIR -name "rman_incr_*.log" -mtime +30 -delete
exit $RMAN_EXIT
chmod 750 /u01/app/oracle/admin/ORCL/scripts/rman_incr_backup.sh

12.3 — Create Archivelog Backup Script

vi /u01/app/oracle/admin/ORCL/scripts/rman_arch_backup.sh
#!/bin/bash
# -------------------------------------------------------
# RMAN Archivelog Backup Script
# Schedule: Every 4 hours (00:00, 04:00, 08:00, 12:00, 16:00, 20:00)
# File: /u01/app/oracle/admin/ORCL/scripts/rman_arch_backup.sh
# -------------------------------------------------------

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/19.3.0/dbhome_1
export ORACLE_SID=ORCL
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib

LOG_DIR=/u01/app/oracle/admin/ORCL/rman_logs
mkdir -p $LOG_DIR
LOG_FILE=$LOG_DIR/rman_arch_$(date +%Y%m%d_%H%M%S).log

$ORACLE_HOME/bin/rman target / << EOF >> $LOG_FILE 2>&1

BACKUP
    ARCHIVELOG ALL
    FORMAT '/u01/app/oracle/fast_recovery_area/ORCL/archivelog/arch_%d_%T_%s_%p'
    DELETE INPUT
    TAG 'ARCHIVELOG_BACKUP';

LIST BACKUP OF ARCHIVELOG ALL COMPLETED AFTER 'SYSDATE-1';

EXIT;
EOF

RMAN_EXIT=$?
find $LOG_DIR -name "rman_arch_*.log" -mtime +7 -delete
exit $RMAN_EXIT
chmod 750 /u01/app/oracle/admin/ORCL/scripts/rman_arch_backup.sh

12.4 — Schedule Backups in Cron

# Edit oracle user's crontab
su - oracle
crontab -e

Add the following cron entries:

# -------------------------------------------------------
# Oracle RMAN Backup Schedule
# -------------------------------------------------------

# Full backup every Sunday at 1:00 AM
0 1 * * 0 /u01/app/oracle/admin/ORCL/scripts/rman_full_backup.sh

# Incremental backup Monday-Saturday at 1:00 AM
0 1 * * 1-6 /u01/app/oracle/admin/ORCL/scripts/rman_incr_backup.sh

# Archivelog backup every 4 hours
0 0,4,8,12,16,20 * * * /u01/app/oracle/admin/ORCL/scripts/rman_arch_backup.sh
# Verify crontab
crontab -l

13. Post-Backup Verification Checks

⚠️ IMPORTANT: Never assume a backup succeeded just because the script ran. Verify backup completion every day. A backup that silently fails is the worst possible situation — you only discover it when you need to recover.


13.1 — Verify Latest Backup Exists and Is Recent

rman target /
-- Check most recent backups
RMAN> LIST BACKUP COMPLETED AFTER 'SYSDATE-1' SUMMARY;

-- Check specific backup completion
RMAN> LIST BACKUP OF DATABASE COMPLETED AFTER 'SYSDATE-2';
RMAN> LIST BACKUP OF ARCHIVELOG ALL COMPLETED AFTER 'SYSDATE-1';
RMAN> LIST BACKUP OF CONTROLFILE COMPLETED AFTER 'SYSDATE-1';

13.2 — Check Backup Status via SQL

sqlplus / as sysdba

set linesize 200
set pagesize 100
col input_type       for a25
col status           for a25
col start_time       for a25
col end_time         for a25
col input_bytes_gb   for 9999.99
col output_bytes_gb  for 9999.99
col output_device_type for a15

-- Recent RMAN backup jobs
SELECT input_type,
       status,
       TO_CHAR(start_time,'YYYY-MM-DD HH24:MI:SS')  start_time,
       TO_CHAR(end_time,'YYYY-MM-DD HH24:MI:SS')    end_time,
       input_bytes/1024/1024/1024                    input_bytes_gb,
       output_bytes/1024/1024/1024                   output_bytes_gb,
       output_device_type
FROM   v$rman_backup_job_details
WHERE  start_time > SYSDATE - 7
ORDER BY start_time DESC;

13.3 — Check for Failed Backup Jobs

-- Check for any FAILED backup jobs
set linesize 200
set pagesize 100
col input_type for a25
col status     for a25
col start_time for a25
col end_time   for a25

SELECT input_type, status,
       TO_CHAR(start_time,'YYYY-MM-DD HH24:MI:SS') start_time,
       TO_CHAR(end_time,  'YYYY-MM-DD HH24:MI:SS') end_time
FROM   v$rman_backup_job_details
WHERE  status  != 'COMPLETED'
AND    start_time > SYSDATE - 7
ORDER BY start_time DESC;

What to look for: No rows with status FAILED or COMPLETED WITH WARNINGS. If any failed jobs exist — investigate immediately.


13.4 — Verify FRA Space After Backup

sqlplus / as sysdba

set linesize 200
set pagesize 100
col file_type                for a30
col percent_space_used       for 999.99
col percent_space_reclaimable for 999.99
col number_of_files          for 999999

SELECT file_type,
       percent_space_used,
       percent_space_reclaimable,
       number_of_files
FROM   v$recovery_area_usage
ORDER BY file_type;

-- Overall FRA usage
SELECT name,
       space_limit/1024/1024/1024       space_limit_gb,
       space_used/1024/1024/1024        space_used_gb,
       space_reclaimable/1024/1024/1024 space_reclaimable_gb
FROM   v$recovery_file_dest;

13.5 — Verify Backup Is Restorable (Weekly Validation)

📝 Why validate weekly? Just because RMAN wrote a backup does not mean the backup is readable. Backup media can corrupt silently. Run VALIDATE weekly to confirm backups are actually restorable.

rman target /
-- Validate most recent backup without actually restoring
RMAN> RESTORE DATABASE VALIDATE;

-- This reads every backup piece and validates every block
-- Output should show: Total blocks examined: XXXXX
--                     Blocks declared corrupt: 0

-- Validate specific backup set
RMAN> VALIDATE BACKUPSET <backupset_key>;

-- Check for corruption found during validation
sqlplus / as sysdba
SELECT file#, block#, blocks, corruption_type
FROM   v$database_block_corruption;
-- Should return no rows

13.6 — Check Alert Log for RMAN Errors

# Scan alert log for RMAN-related errors
tail -300 /u01/app/oracle/diag/rdbms/orcl/ORCL/trace/alert_ORCL.log \
     | grep -E "RMAN-|ORA-|archiver|cannot archive"

# Convention B
tail -300 /oracle/diag/rdbms/orcl/ORCL/trace/alert_ORCL.log \
     | grep -E "RMAN-|ORA-|archiver|cannot archive"

13.7 — Check Backup Log Files

# Check latest RMAN log for errors
ls -lt /u01/app/oracle/admin/ORCL/rman_logs/ | head -5

# View latest log
tail -50 /u01/app/oracle/admin/ORCL/rman_logs/rman_full_*.log | head -50

# Search for errors in log
grep -E "RMAN-|ORA-|error|failed|ERROR" \
    /u01/app/oracle/admin/ORCL/rman_logs/rman_full_*.log

13.8 — Verify Controlfile Autobackup Exists

rman target /
-- List control file autobackups
RMAN> LIST BACKUP OF CONTROLFILE;

-- Crosscheck controlfile backups
RMAN> CROSSCHECK BACKUP OF CONTROLFILE;
RMAN> LIST EXPIRED BACKUP OF CONTROLFILE;

13.9 — Check Database Backup Coverage

rman target /
-- Report files that are NOT backed up
-- Any files listed here need immediate backup attention
RMAN> REPORT NEED BACKUP;

-- Report files with no backup
RMAN> REPORT UNRECOVERABLE;

-- Check database recoverability
-- This checks if all archivelogs needed for recovery are available
RMAN> RESTORE DATABASE PREVIEW SUMMARY;

14. Quick Reference Card

TaskCommand
Connect RMAN (no catalog)rman target /
Connect RMAN (with catalog)rman target / catalog rman_user/pwd@RMANCAT
Show RMAN configRMAN> SHOW ALL;
Configure retentionCONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
Enable controlfile autobackupCONFIGURE CONTROLFILE AUTOBACKUP ON;
Configure parallelismCONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO BACKUPSET;
Full Level 0 backupBACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 0 DATABASE PLUS ARCHIVELOG DELETE INPUT;
Daily Level 1 backupBACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 1 CUMULATIVE DATABASE PLUS ARCHIVELOG DELETE INPUT;
Archivelog backupBACKUP ARCHIVELOG ALL DELETE INPUT;
Backup controlfileBACKUP CURRENT CONTROLFILE;
Backup spfileBACKUP SPFILE;
Backup tablespaceBACKUP TABLESPACE users;
List backup summaryLIST BACKUP SUMMARY;
List backups last 7dLIST BACKUP COMPLETED AFTER 'SYSDATE-7' SUMMARY;
Crosscheck backupsCROSSCHECK BACKUP;
Validate backupRESTORE DATABASE VALIDATE;
Report need backupREPORT NEED BACKUP;
Report unrecoverableREPORT UNRECOVERABLE;
Report schemaREPORT SCHEMA;
Delete obsoleteDELETE NOPROMPT OBSOLETE;
Delete expiredDELETE NOPROMPT EXPIRED BACKUP;
Restore datafileRESTORE DATAFILE 5; RECOVER DATAFILE 5;
Full DB restoreRESTORE DATABASE; RECOVER DATABASE; ALTER DATABASE OPEN RESETLOGS;
PITR by timeSET UNTIL TIME "TO_DATE('...')"; RESTORE DATABASE; RECOVER DATABASE;
PITR by SCNSET UNTIL SCN 1234567; RESTORE DATABASE; RECOVER DATABASE;
Block recoveryRECOVER DATAFILE 5 BLOCK 100;
Corrupt block listRECOVER CORRUPTION LIST;
TSPITRRECOVER TABLESPACE users UNTIL TIME "..." AUXILIARY DESTINATION '...';
Control file restoreRESTORE CONTROLFILE FROM AUTOBACKUP;
Duplicate databaseDUPLICATE TARGET DATABASE TO testdb FROM ACTIVE DATABASE ...;
Register DB in catalogREGISTER DATABASE;
Resync catalogRESYNC CATALOG;
Check FRA usage (SQL)SELECT file_type,percent_space_used FROM v$recovery_area_usage;
Check backup jobs (SQL)SELECT input_type,status,start_time FROM v$rman_backup_job_details WHERE start_time>SYSDATE-7;
Check block corruptionSELECT file#,block#,corruption_type FROM v$database_block_corruption;
MOS RMAN Best PracticesDoc ID 1513912.1
MOS RMAN PerformanceDoc ID 1116108.1
MOS RMAN 19cDoc ID 2505669.1

This SOP covers everything you need to configure, run, and manage Oracle RMAN backup and recovery on Linux without referring to any other source. Always verify FRA space before backup, always enable controlfile autobackup, always validate your backups weekly to confirm they are restorable, always automate backups with cron scripts and check the logs daily, and always test your recovery procedures in a non-production environment before you ever need them in production.

Was this helpful?

Written by

W3buddy
W3buddy

Explore W3Buddy for in-depth guides, breaking tech news, and expert analysis on AI, cybersecurity, databases, web development, and emerging technologies.