Database AdministrationUnit 411 min read
Oracle Backup, Restore & Recovery: Policies, Methods & Real-World Scenarios
Unit 4 of Database Administration covers Oracle’s backup strategies (full, incremental, RMAN), restore/recovery processes (point-in-time, crash recovery), and disaster preparedness—with real-world examples from Nepali banks and e-commerce platforms, plus step-by-step commands and failure scenarios.
Key points
- Oracle backup types (full, incremental, differential) differ in speed, storage cost, and recovery granularity—**choose based on RPO/RTO needs**.
- RMAN (Recovery Manager) automates backups, compression, and recovery with **channel multiplexing** and **proxy copies** for efficiency.
- Recovery processes (instance recovery, media recovery) follow a **3-phase cycle**: crash detection → redo apply → consistency checks.
- **Flashback Database** and **Flashback Drop** enable time-travel queries and accidental-data recovery without full restores.
- **Disaster recovery policies** (e.g., 3-2-1 rule) must align with **Oracle’s multiplexing** (redo logs, control files) to survive hardware failures.
- **Worked example**: Restoring a corrupted `HR.EMPLOYEES` table after a Daraz order-processing system crash using RMAN’s `RESTORE` + `RECOVER` commands.
- ```
Core Concepts: Backup, Restore, and Recovery Defined
Oracle’s backup, restore, and recovery (BRR) trio ensures data durability and availability. These terms are not interchangeable:
| Term | Definition | Example |
|---|---|---|
| Backup | A copy of database files (datafiles, redo logs, control files) to a secondary storage. | RMAN> BACKUP DATABASE PLUS ARCHIVELOG; copies all files to disk/tape. |
| Restore | Recreating backup files in their original locations (no data changes yet). | RMAN> RESTORE DATABASE; writes backup files back to disk. |
| Recovery | Applying redo logs to restore files to a consistent state (undoes corruption). | RMAN> RECOVER DATABASE; rolls forward transactions after a crash. |
Why all three?
- Backup = "Save a copy."
- Restore = "Put the copy back."
- Recovery = "Fix what’s broken in the copy."
1. Backup Strategies in Oracle
Oracle supports three backup types, each with trade-offs in speed, storage, and recovery flexibility.
A. Full Backup
- Definition: Copies all database files (datafiles, redo logs, control files) in one operation.
- Use case: Weekly full backups for disaster recovery (e.g., restoring an entire bank’s core banking system after a server failure).
- Command:
RMAN> BACKUP DATABASE FULL; - Pros/Cons:
Pros Cons Simple to manage. High storage cost. Fastest for full recovery. Long backup window. No dependency on prior backups. Inflexible for partial restores.
B. Incremental Backup
- Definition: Copies only changed blocks since the last backup (full or incremental).
- Cumulative: All changes since last full backup.
- Differential: Only changes since the last incremental backup.
- Use case: Daily incremental backups for e-commerce platforms (e.g., Daraz’s order database) to minimize downtime.
- Command:
-- Cumulative incremental RMAN> BACKUP DATABASE INCREMENTAL LEVEL 1; -- Differential incremental RMAN> BACKUP DATABASE INCREMENTAL FROM TIME 'SYSDATE-1'; - Pros/Cons:
Pros Cons Reduces storage and backup time. Requires full backup as baseline. Faster recovery for recent corruption. Complex to manage chains.
C. RMAN (Recovery Manager) Backups
- Definition: Oracle’s built-in tool for automated backups, compression, and recovery.
- Key Features:
- Channel multiplexing: Uses multiple I/O channels for parallel backups.
- Proxy copies: Backs up files to a staging area before final destination.
- Compression: Reduces backup size (e.g.,
BACKUP ... COMPRESSED 2).
- Example Workflow:
- Backup:
RMAN> BACKUP DATABASE PLUS ARCHIVELOG > FORMAT '/backup/%U' > CHANNEL 1: CHANNEL2: TYPE DISK; - Restore (after a crash):
RMAN> RESTORE DATABASE; RMAN> RECOVER DATABASE;
- Backup:
MERMAID DIAGRAM: RMAN Backup Process
2. Restore and Recovery Processes
Recovery in Oracle follows a structured cycle to handle failures (crash, media corruption, user errors).
A. Crash Recovery (Instance Recovery)
- Trigger: Oracle instance fails (e.g., power outage, OS crash).
- Steps:
- Detect failure: Oracle checks redo logs for uncommitted transactions.
- Apply redo: Rolls forward transactions from redo logs.
- Consistency check: Validates datafiles using
RECOVER DATABASE.
- Command:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT;
B. Media Recovery (File Corruption)
- Trigger: Datafile corruption (e.g.,
HR.EMPLOYEEStable damaged after a Daraz system update). - Steps:
- Restore the corrupted file from backup:
RMAN> RESTORE TABLESPACE HR; - Recover using redo logs:
RMAN> RECOVER TABLESPACE HR;
- Restore the corrupted file from backup:
- Worked Example: Daraz Order System Recovery
- Scenario: A Daraz database administrator notices
ORDERStable corruption after a failed update. - Solution:
-- Step 1: Restore the corrupted tablespace RMAN> RESTORE TABLESPACE ORDERS; -- Step 2: Recover using archived redo logs RMAN> RECOVER TABLESPACE ORDERS; -- Step 3: Verify data integrity SQL> SELECT COUNT(*) FROM ORDERS; -- Should match pre-crash count.
- Scenario: A Daraz database administrator notices
C. Point-in-Time Recovery (PITR)
- Definition: Restores the database to a specific point in time (e.g., before a rogue SQL
DELETE). - Requirements:
- Archived redo logs enabled (
LOG_ARCHIVE_DEST). - Full backup + incremental backups.
- Archived redo logs enabled (
- Command:
RMAN> RESTORE DATABASE TO TIME 'TO_TIMESTAMP('2023-10-15 14:30:00', 'YYYY-MM-DD HH24:MI:SS')'; RMAN> RECOVER DATABASE TO TIME 'TO_TIMESTAMP('2023-10-15 14:30:00', 'YYYY-MM-DD HH24:MI:SS')';
MERMAID DIAGRAM: Recovery Types
3. Backup Policies: Designing a Robust Strategy
A DBA’s backup policy must align with Recovery Point Objective (RPO) and Recovery Time Objective (RTO).
A. The 3-2-1 Rule
- 3 copies of data (primary + 2 backups).
- 2 different media (disk + tape).
- 1 offsite backup (e.g., cloud storage).
Example for a Nepali Bank (e.g., NMB Bank):
- RPO: 15 minutes (lose no more than 15 mins of transactions).
- RTO: 2 hours (restore within 2 hours).
- Policy:
- Daily full backup (tape).
- Hourly incremental backups (disk).
- Offsite replica (cloud storage in Singapore).
B. Oracle-Specific Best Practices
| Practice | Command/Example |
|---|---|
| Multiplex redo logs | ALTER SYSTEM SET LOG_FILE_GROUP_1='(MEMBER='/redo01.log', '/redo02.log')'; |
| Automate backups | RMAN> BACKUP DATABASE PLUS ARCHIVELOG DAILY; |
| Test restores | RMAN> RESTORE DATABASE FROM AUTOBACKUP; (simulate disaster) |
| Monitor backup jobs | SELECT * FROM V$BACKUP_SET; |
4. Advanced Recovery Tools
Oracle provides time-saving recovery features beyond basic RMAN.
A. Flashback Database
- Definition: Enables instantaneous rollback to a past point in time without restoring backups.
- Requirements:
- Flashback Database enabled (
FLASHBACK_DATABASE_ON). - Sufficient undo retention (
UNDO_RETENTION).
- Flashback Database enabled (
- Steps to Enable:
SQL> SHUTDOWN IMMEDIATE; SQL> STARTUP MOUNT; SQL> ALTER DATABASE FLASHBACK ON; SQL> ALTER DATABASE OPEN; - Worked Example: Kathmandu Traffic Route Correction
- Scenario: A traffic management system (like NTC’s route optimizer) accidentally updates routes due to a bug.
- Recovery:
SQL> SHUTDOWN IMMEDIATE; SQL> STARTUP MOUNT; SQL> FLASHBACK DATABASE TO TIME 'TO_TIMESTAMP('2023-10-15 10:00:00', 'YYYY-MM-DD HH24:MI:SS')'; SQL> RECOVER DATABASE; SQL> ALTER DATABASE OPEN;
B. Flashback Drop
- Definition: Recovers dropped tables/objects without full restores.
- Command:
SQL> FLASHBACK TABLE HR.EMPLOYEES TO BEFORE DROP;
5. Disaster Recovery Planning
A comprehensive DR plan includes:
- Backup strategy (full/incremental/RMAN).
- Offsite storage (cloud, tape vault).
- Failover testing (quarterly drills).
- Documentation (runbooks for DBAs).
Example DR Scenario for NEPSE (Nepal Stock Exchange):
- Risk: Server failure during trading hours.
- Solution:
- Primary site: Oracle RAC (2-node cluster).
- Secondary site: Standby database in Chitwan (synchronized via Data Guard).
- RTO: 10 minutes (failover to standby).
- RPO: 0 minutes (real-time replication).
In the Real World
eSewa (Nepali Digital Payment System)
- Backup Policy: Uses RMAN with multiplexed redo logs to ensure transaction integrity during peak hours (e.g., Dashain/Tihar).
- Recovery: Flashback Database to revert fraudulent transactions within minutes.
Ncell (Telecom Provider)
- Challenge: Millions of daily call records must survive hardware failures.
- Solution:
- Hourly incremental backups to disk.
- Daily full backups to tape (stored in a secure vault).
- PITR to recover from billing system errors.
Daraz (E-Commerce Platform)
- Backup Strategy:
- Order database: Incremental backups every 30 minutes.
- User data: Full backup nightly + offsite replica.
- Recovery Example: After a failed inventory update, Daraz uses
FLASHBACK TABLEto restore product quantities.
- Backup Strategy:
Exam Tip
Define vs. Explain:
- Backup = Copying files.
- Restore = Replacing files.
- Recovery = Fixing corruption via redo logs.
- Exam trick: Use the BRR cycle in your answer to show understanding.
Commands Are Key:
- Memorize RMAN syntax for backup/restore/recovery (e.g.,
BACKUP DATABASE,RESTORE TABLESPACE,RECOVER DATABASE). - Worked examples (like Daraz’s order recovery) fetch high marks.
- Memorize RMAN syntax for backup/restore/recovery (e.g.,
Policy Questions:
- For backup policy questions, structure your answer as:
- RPO/RTO goals.
- Backup types (full/incremental/RMAN).
- Multiplexing/offsite storage.
- Testing and documentation.
- For backup policy questions, structure your answer as:
Visuals in Exams:
- Draw a layered diagram of Oracle files (datafiles, redo logs, control files) when asked about architecture.
- Use a timeline for PITR (e.g., "Backup at T0, corruption at T1, recover to T0.5").
Common Pitfalls:
- ❌ Forgetting multiplexing for redo logs/control files.
- ❌ Confusing incremental levels (Level 0 = full, Level 1 = cumulative, Level 2 = differential).
- ❌ Skipping post-recovery verification (e.g.,
SELECT COUNT(*) FROM TABLE).
Based on the TU BSc CSIT syllabus for Database Administration (CSC414), unit 4.
Discussion
Loading…