47. RMAN in Details: - Agnivo102/Database_Architect GitHub Wiki

Flowchart in Details:

┌──────────────────────────────────────────────────────────────┐
│             RMAN CLIENT (connect to Traget DataBase          │     //The RMAN client we connect 
│                  or optionaly a recover catalog              │     to backup or restore database 
└──────────────────────────────────────────────────────────────┘
                               │
                               ▼
┌──────────────────────────────────────────────────────────────┐   
│             RMAN CHANNEL (The channel which reads            │   //The server session to read or backup data    
│                       or writes data                         │
└──────────────────────────────────────────────────────────────┘
                               │
                               ▼
┌──────────────────────────────────────────────────────────────┐
│                     Connects to database files               │   //The source files, whose backup is taken
│     (Data files, Control files, Archived log files, SPfile)  │
└──────────────────────────────────────────────────────────────┘
                               │
                               ▼
┌──────────────────────────────────────────────────────────────┐   //Backup destination where backup is kept
│          Writes the backup in backup destination             │    (like /u01/backup/)
└──────────────────────────────────────────────────────────────┘     
                               │
                               ▼
┌──────────────────────────────────────────────────────────────┐ //Metadata like the timestamp of the backup taken, 
│    Repository update (Control file or recovery catalog)      │  location of the backup, is avalable or expired etc 
└──────────────────────────────────────────────────────────────┘  is written in control file or recovery catalog
                               │
                               ▼
┌──────────────────────────────────────────────────────────────┐  //RMAN detarmines which backup is obsolete  
│                     Retention Evaluation                     │  according to recovery window and redundancy policy
└──────────────────────────────────────────────────────────────┘
                               │
                               ▼
┌──────────────────────────────────────────────────────────────┐ //Validation by crosscheck backup and v$rman_status
│                       Monitor and Crosscheck                 │  dynamic view and list backup to see is they are 
└──────────────────────────────────────────────────────────────┘  physically available or not. 
                               │
                               ▼
┌──────────────────────────────────────────────────────────────┐ //Restore Validate and validate database
│                    Test Restore Readiness                    │  to check (?)
└──────────────────────────────────────────────────────────────┘
                               │
                               ▼
┌──────────────────────────────────────────────────────────────┐  //restore database, recover database
│                          Recovery Use                        │    restore data from backup
└──────────────────────────────────────────────────────────────┘    
 

RMAN Repository Architecture:

RMAN repository or the repository of physical backup holds the metadata (data about data) information about the backup like when the backup was taken the exact time, the location of the backup etc.

This repository can be 2 things:

Control File:

We know control file is the repository of the physical backup and holds all metadata information about backup.

Recovery catalog:

This is another place which can be used as a repository for backup. This recovery catalog is a separate database schema, entirety dedicated for metadata about backup. This requires an extra database schema, their separate maintenance and backup. In return it keeps longer historical information about backups, centralized reporting, can be used to store scripts for backup, and will hold historical metadata even if the control file is lost.

Core Concepts:

Target Database:

The database that is being backed up or recovered.

Example Command: rman target /

Recovery Catalog:

External database schema for metedata regarding backup. This is optional.

Example Command: rman catalog rman@RCAT

Channel:

The server session which does the backup and read and write operation on the storage.

Example Command: device type disk (?)

Backup piece:

Physical file produced by backup

Example Command: backup datafile 1; Sample file: db_1.bkp

Backup set:

Logical RMAN backup containing one or more backup piece.

Example Command: backup database;

Image copy:

Copy of a datafile, control file or archived log (?)

Example Command: backup as copy database;

Tag:

A level assigned to the backup file.

Example Command: backup datafile 1 tag 'Name'; OR backup incremental level 1 database tag 'Level_1_differential';

Checkpoint SCN:

System change number, a number generated every nano second the database is active, used in many things, like to put the SCN of the commited DML sentence in control file and the header of data file to know which statements are commited. Here RMAN uses this for incomplete recovery and complete recovery (?) .

Obsolete:

No longer required by configured retention policy.

Expired:

Recorded in repository but the physical file got lost. Need crosscheck backup; to find them.

Avaiable:

Physcal backup file exist now and its record exist in repository.

Backup Types and Format:

Backup Set:

Feature

Storage Format: RMAN propritory backup pieces.

Compression: Supports RMAN compression.

Unused Block Skipping: (?) Supported

Restore required: Yes.

Typical Use: Standard Backup Strategy.

Image Copy:

Feature

Storage Format: Exact copy of source file.

Compression: Normally same size as source.

Unused Block Skipping: (?) Not applicable in the same way.

Restore required: Can switch directly to copies.

Typical Use: Incrementally updated copy or fast switch over recovery ?.

Command: Backup as copy database.


Screenshot

Types:

Compressed Backup set: Database backup in compressed state.

backup as compressed backupset database;

Archived log backup:

backup archivelog all;

Channel:

The session through whch backup input and output operations are done.

Set up Automatic Channel:

configure device type disk parallelism 3 backup type backupset;


Screenshot

Set up Manual channel:

run
{
allocate channel c1 device type disk;
backup database;
release channel c1;
}


Screenshot

Set up Multiple Manual channel:

run
{
allocate channel c1 device type disk;
allocate channel c3 device type disk;
allocate channel c3 device type disk;

backup database;

release channel c1;
release channel c2;
release channel c3;
}


Screenshot
Screenshot

Channel Format:

configure channel device type disk format '/u05/rman/%d_%T_%U_%s_%p_%t_%c.bkp';

These are format variables. Their use is optional and can be used as you want.

%d : Variable for Database Name.

&T : Variable for date in YYYYMMDD Format

%U : Garunteed unique backup piece name

%s : Backup set number

%p : Backup piece number within set

%t : Backup set timestamp

%c : Copy number


Screenshot

The location of the backup changed.

Retention and Deletion Policies:

Retention policy is the settings RMAN keeps backup files of the database. It (?)

Recovery Window:

configure retention policy to recovery window of 10 days;


Screenshot

RMAN retains enough backups to recover the database to any point within the last 10 days (?)

Redundancy:

configure retention policy to redundancy 2;


Screenshot

RMAN retains 2 complete backup generation. (?)

Disable retention policy:

configure retention policy to none;


Screenshot

Report obsolete:

which one to report obsolete? (?)

report obsolete;


Screenshot

Archived Log Deletion policy:

configure archivelog deletion policy to backed up 1 times to disk;

This means that after that arhive log is backed up 1 time in a backup file, the archive log will be deleted.(?)


Screenshot

Data Gaurd deletion policy example: ?

Screenshot

Associated Views and Commands:

v$rman_status:

RMAN Operation status and timing

v$rman_output:

Recent RMAN output in memory.

v$rman_backup_job_details:

Backup job duration, size, throughput, status.

v$backup_set:

Backup set metadata.

v$backup_piece:

Backup piece metadata.

v$backup_datafile:

Datafile backup records.

v$backup_redolog:

Archive log backup records.

v$controlfile_record_section:

Control file record usage and capacity.

v$recovery_file_dest:

Fast Recovery Area (FRA) Size and usage

v$recovery_area_usage:

FRA usage by file type.

report:

Screenshot

crosscheck:

Screenshot

RMAN Connection:

Normal OS Authentication:

rman target /

Connect using net services:

rman target sys@PROD


Screenshot

Connect with recovery catalog:

How to create a catalog database?

rman target / catalog rman_catalog@RCAT


Screenshot

Inside RMAN:

Connect target /


Screenshot

Validate Target:

sql 'select name, open_mode, log_mode from v$database';

(?)


Screenshot

Display configuration:

A configuration is the set of setting for all the features of a tool.

show all:

Screenshot

Show retention policy;

Screenshot

show controlfile autobackup; ?

Screenshot

show device type; (what else can be the device types?)

Screenshot

show default device type; (why these 2 are separate?)

Screenshot

show channel;

Screenshot

This is what I set.

show compression algorithm; ?

Screenshot

show encryption for database; ?

Screenshot

show archivelog deletion policy;

Screenshot

show snapshot controlfile name; ?

Screenshot

Capture configuration to log:

rman target / log=/u01/backup/log_rman_$(date +%Y%m%d_%H%M%S).log append

Screenshot

Setting up the RMAN Tool for a Standalone Lap Database:

Requirement: Comfigure a 14 day recovery window, disk backup destination, 2 channels, compressed backup set, control file autobackup, archive log deletion after one successfull disk backup.

Step 1: To see the current configuration: show all


Screenshot

Step 2: For 14 days recovery window: configure retention policy to recovery window of 14 days;


Screenshot

Step 3: 2 channels, disk backup destination, and compressed backup set: configure device type disk parallelism 2 backup type to compressed backupset;


Screenshot

Step 4: Control file autobackup: configure controlfile autobackup on;


Screenshot

Step 5: Archive log deletion policy to delete after one succesful disk backup: configure archivelog deletion policy to backed up 1 times to disk;


Screenshot

Step 6: Validate: show all;


Screenshot

Previously the backup optimization (?) was turned off so i turned it on. And see the highlighted ones, it matches with the requirement.

Some Backup command;

Control file: backup current controlfile;

Screenshot

Spfile: backup spfile;

Screenshot

Archived log from specific time: backup archivelog from time "sysdata-1";

sysdate - 1 (?)


Screenshot

Backup with tag and specific format and location: backup database tag 'tags' format = '/home/oracle/%d_%T_%U.bkp';

Screenshot

Monitor RMAN Jobs:

select session_key, input_type, status, start_time, end_time, elapsed_seconds, input_bytes_display, output_bytes_display, output_device_type, compression_ratio from v$rman_backup_job_details order by start_time desc fetch first 30 rows only;


Screenshot

select session_recid, session_stamp, operation, status, start_time, end_time, object_type, output_bytes from v$rman_status where start_time > sysdate - 7 order by start_time desc;


Screenshot

select recid, stamp, output from v$rman_output order by recid;


Screenshot
Screenshot

select sid, serial#, opname, sofar, totalwork, units, round(sofar * 100/nullif(totalwork,0),2) as pct_done, elapsed_seconds, time_remaining from v$session_longops where opname like 'RMAN%' and totalwork > 0 and sofar = totalwork order by start_time;


Screenshot

select handle, status, device_type, bytes/1024/1024 as size_mb, start_time, completion_time, compressed from v$backup_piece order by completion_time desc fetch first 50 rows only;


Screenshot

Some backup commands:

List Backup Commands:

List backup;


Screenshot

List backup summary;


Screenshot

list backup of database;


Screenshot

list backup of archivelog all;


Screenshot

list copy;


Screenshot

list expired backup;


Screenshot

Crosscheck Commands:

crosscheck archivelog all;


Screenshot

crosscheck copy;


Screenshot

crosscheck backup;


Screenshot

catalog existing backup piece:

Catalog backuppiece 'name and location to the backup file';


Screenshot

Create a logical directory and record it in the repository:

This is similar to create directory for expdp and impdp.

Catalog start with '/u05/rman/';

Or

Catalog start with '/u05/rman/' noprompt;


Screenshot

No prompt is for not prompt the user to enter yes or no.

Delete expired backup:

Delete expired backup;


Screenshot

Delete expired archivelog all;


Screenshot

Uncatalog without deleting the file:

Change backuppiece 'the name and path of the catalogged file' uncatalog;


Screenshot

Validation and restore Readiness:

Validate database blocks: ?

Validate database;


Screenshot

Validate database with logical checks: ?

Backup validate check logical database;


Screenshot

Restore validate:

Restore database validate;


Screenshot

Validate control file: ?

Restore controlfile validate;


Screenshot

Validate spfile: ?

Restore spfile validate:


Screenshot

Preview Restore: ?

Restore database preview;


Screenshot

Preview Restore summary: ?

Restore database preview summary;


Screenshot

Corruption view: ?

Select file#, block#, blocks, corruption_change#, corruption_type from v$database_block_corruption order by file#, block#;


Screenshot

Control File and spfile protection:

Enable autobackup:

Configure controlfile autobackup on;


Screenshot

Do an manual control file backup:

Backup current controlfile;


Screenshot

Manual spfile backup:

Backup spfile;


Screenshot

List control file backups:

List backup of controlfile:


Screenshot

List spfile backups:

List backup of spfile;


Screenshot

Control file record usage:

Select type, record_size, records_total, records_used, first_index, last_index, last_recid from v$controlfile_record_section where type like 'BACKUP%' or type like 'ARCHIVED%' ordered by type;


Screenshot

Record keep time:

Show parameter control_file_record_keep_time;


Screenshot

Common Error and Troubleshooting:

RMAN-06171: Not connected to target database

Screenshot

ORA-19504/ORA-27040: Cannot create backup file

Screenshot

RMAN-06059: Expected Archived Log Not found

RMAN-06023: No backup or Copy Found to Restore

Backup is Slow:

select input_type, status, elapsed_seconds, input_bytes_per_sec_display, output_bytes_per_sec_display, compression_ratio from v$rman_backup_job_details order by start_time desc fetch first 20 rows only;


Screenshot

Production-Safe RMAN Checklist:

Before Configuration Changes:

1. Capture show all output.

2. Confirm database role, archivelog mode, fast recovery area, data gaurd status.

3. Review RPO, RTO, retention, archive deletion and offsite requirement. ?

4. Validate backup destintion capacity and throughput. ?

5. Confirm control file autobackup and SPFILE protection.

6. Plan rollback commands for every configure statement. ?

7. Test restore and recovery regularly. ?

SQL Check:

select name, open_mode, log_mode, database_role, force_logging from v$database;


Screenshot

select name, space_limit/1024/1024/1024 as limit_gb, space_used/1024/1024/1024 as used_gb, space_reclaimable/1024/1024/1024 as reclaimable_gb from v$recovery_file_dest;


Screenshot

select file_type, percent_space_used, percent_space_reclaimable, number_of_files from v$recovery_area_usage order by file_type;


Screenshot

Pre-backup summary:

show all;
crosscheck backup;
crosscheck archivelog all;
list backup summary,
report obsolete;

Post backup validation:

list backup summary;
list backup of database;
list backup of archivelog all;
restore database preview summary;
report need backup recovery window of 14 days;
⚠️ **GitHub.com Fallback** ⚠️