How to Perform Backup and Recovery Using Oracle RMAN Commands

English

In Oracle Database operations, automating and streamlining backup and recovery is essential. This article explains the primary commands of Oracle RMAN (Recovery Manager), the standard tool, along with specific execution examples useful in practice, in a way that is easy for beginners to understand.

Conclusion: “To-Do List” of RMAN Commands to Prioritize

To master RMAN, first learn these five actions and commands:

  1. Connect: rman target / (Connect to the local target database)
  2. Back up: BACKUP DATABASE PLUS ARCHIVELOG; (Capture the entire DB and logs together)
  3. Check Status: LIST BACKUP; (Display history of captured backups)
  4. Clean up Unneeded Files: DELETE OBSOLETE; (Delete old files outside the retention policy)
  5. Attempt Repair: RESTORE DATABASE; / RECOVER DATABASE; (Restore and synchronize data)

Background and Mechanism of RMAN: Why Use RMAN?

RMAN (Recovery Manager) is a command-line interface dedicated to backups, included as a standard feature in Oracle Database.

  • Difference from OS Copy: RMAN can detect corruption within data blocks and skips unused blocks, making it faster and safer than copying with OS commands.
  • Management Automation: It allows for easy backup generation management (retention policies), automatic deletion of archivelogs, and incremental backups.

1. Starting RMAN and Connecting to the Database

To execute RMAN, you must first start it by specifying the target database (connection destination).

Prerequisites

  • The OS user must belong to the dba group.
  • Environment variables ORACLE_SID and ORACLE_HOME must be set correctly.

Execution Commands

Local Connection (OS Authentication)

rman target /

Remote Connection (Using Net Service Name)

rman target sys/password_example@tns_alias

Note: Avoid including the “@” symbol in passwords as it can cause connection errors.

Connection Using a Recovery Catalog

Used when managing multiple databases centrally.

rman target / catalog rman_user/pass_example@catalog_db

2. Backup Execution Commands

These are the most frequently used backup-related commands.

Entire Database Backup (Recommended Example)

Captures the database itself and the archivelogs required for recovery together.

-- Execute a full backup including archivelogs
BACKUP DATABASE PLUS ARCHIVELOG;

Specific Objects and Incremental Backups

You can narrow down the target depending on your needs.

| Target | Command Example |

| :— | :— |

| Specific Tablespace | BACKUP TABLESPACE USERS; |

| Control File | BACKUP CURRENT CONTROLFILE; |

| Incremental (Level 1) | BACKUP INCREMENTAL LEVEL 1 DATABASE; |

Explanation of Execution Example

When you execute BACKUP DATABASE;, RMAN automatically allocates channels (processes) and writes out data files as backup sets. Upon completion, a “control file autobackup” runs, saving the latest configuration information.

3. Restore and Recovery Procedures

These are the steps to return data in the event of a failure.

  • RESTORE: Reinstates physical files from backup pieces.
  • RECOVER: Applies archivelogs to bring the data forward to the latest state (or a specific point in time).

Entire Database Recovery

Execute while the database is in the MOUNT state.

-- 1. Physical restoration of files
RESTORE DATABASE;

-- 2. Ensuring consistency by applying logs
RECOVER DATABASE;

-- 3. Opening the database
ALTER DATABASE OPEN;

4. Backup Management and Maintenance

Regular maintenance is necessary to avoid exhausting disk space.

Integrity Checks and Deletion

  • CROSSCHECK: Verifies if the actual files exist on disk and updates the catalog information.
  • DELETE OBSOLETE: Deletes old backups that are no longer needed based on the configured retention policy.
-- Synchronize with physical files
CROSSCHECK BACKUP;

-- Delete unnecessary backups past the retention period
DELETE OBSOLETE;

5. RMAN Configuration (CONFIGURE Command)

By setting operation rules in advance, you can simplify commands.

| Configuration Item | Command Example |

| :— | :— |

| Retention Policy (2 generations) | CONFIGURE RETENTION POLICY TO REDUNDANCY 2; |

| Backup Destination Settings | CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/backup/%U'; |

| Control File Autobackup | CONFIGURE CONTROLFILE AUTOBACKUP ON; |

6. Troubleshooting: Common ORA Errors

Error NumberCauseVerification/Remedy
ORA-19809Fast Recovery Area (FRA) fullCheck with REPORT OBSOLETE and DELETE, or expand the FRA size.
ORA-12154TNS service name cannot be resolvedCheck tnsnames.ora entries and use tnsping.
ORA-19504File creation failed (Permissions/Path)Check write permissions for the output directory and available disk space.

Operational and Security Notes

  • Impact and Risk: Disk I/O load increases during BACKUP execution. Schedule it to avoid peak business hours.
  • Verifying Recovery: Don’t just take backups; perform “restore tests” regularly to verify that you can actually recover.
  • Using Reference Commands: If you only want to check for abnormalities, prioritize using LIST or REPORT commands, which do not involve changes.

FAQ: Frequently Asked Questions

Q: Do I need to stop the database during an RMAN backup?

A: No. If the database is in ARCHIVELOG mode, online backups are possible even while the database is operational (OPEN state).

Q: Can I restore a backup accidentally deleted via RMAN?

A: Files physically deleted with the RMAN DELETE command cannot be restored. Unless there is an OS-side trash bin function or tape backup, recovery is impossible, so execute deletion commands with caution.

Q: Can I execute SQL from RMAN?

A: Yes. Since 12c, you can execute SELECT statements and other commands directly without using the SQL 'SQL statement' format.

Summary

  • RMAN is a high-performance backup tool dedicated to Oracle Database.
  • BACKUP DATABASE PLUS ARCHIVELOG; is the most standard command for capturing backups.
  • After capture, manage appropriately with CROSSCHECK and DELETE OBSOLETE.
  • Recovery consists of two steps: RESTORE (bring back) and RECOVER (bring forward).

Note: This article is based on Oracle Database 19c (screens and default values may differ for other versions).

[reference]
Oracle Database Backup and Recovery Reference, 19c

コメント

Copied title and URL