BIT352 ยท 2080 ยท 10 marks
Explain the term backup, restore and recovery in oracle database. Also explain the different backups and recovery process with example.
Explain the term backup, restore and recovery in oracle database. Also explain the different backups and recovery process with example.[10]
Quick answer
Suppose the datafile users01.dbf of a production database is lost at 11:00 AM. A Level 0 backup exists from Sunday, Level 1 backups exist from each weekday night, and the database runs in ARCHIVELOG mode.
Backup, Restore, and Recovery in Oracle Database
Note: Reference notes were not available for this topic. The following answer is based on standard Oracle Database concepts as taught in BSc CSIT curriculum.
1. Key Terminology
Backup
A backup is a copy of data (database files, control files, archived redo logs, etc.) that can be used to reconstruct lost or damaged data. It protects the database against data loss due to hardware failure, user errors, or disasters.
"A backup is a copy of data that can be used to reconstruct data."
Restore
Restore is the process of copying backup files back to their original (or new) location. It is the physical act of placing backup files onto disk so that recovery can proceed.
Example: Copying a datafile from tape/backup location back to the original directory.
Recovery
Recovery is the process of applying redo logs (archived and online) to a restored backup to bring the database to a consistent and up-to-date state. Recovery happens after restore.
Backup --> Restore (copy files back) --> Recovery (apply redo logs) --> Database Online
2. Types of Backups in Oracle
A. Physical Backup
A copy of the actual physical files used in storing and recovering the database.
| Type | Description |
|---|---|
| Cold Backup (Offline) | Taken when database is shut down cleanly |
| Hot Backup (Online) | Taken while database is running (requires ARCHIVELOG mode) |
i. Cold Backup (Offline Backup)
- Database is shut down before taking backup.
- All datafiles, control files, and redo log files are copied.
- Simple but causes downtime.
Example:
SHUTDOWN IMMEDIATE;
-- Copy all datafiles, controlfiles, redo logs to backup location
-- (OS level copy)
STARTUP;
ii. Hot Backup (Online Backup)
- Database remains open and available during backup.
- Requires database to be in ARCHIVELOG mode.
- Used for 24x7 production systems.
Example using RMAN:
RMAN> BACKUP DATABASE;
B. Logical Backup
A backup of the logical data (tables, schemas, procedures) using Oracle utilities like Data Pump (expdp/impdp) or the older exp/imp.
Example:
expdp system/password FULL=Y DUMPFILE=fullbackup.dmp LOGFILE=backup.log
To restore:
impdp system/password FULL=Y DUMPFILE=fullbackup.dmp LOGFILE=restore.log
C. Full Backup
A backup of the entire database -- all datafiles, control files, and archived redo logs.
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;
D. Incremental Backup
Only backs up data blocks that have changed since the last backup. Saves time and storage.
| Level | Description |
|---|---|
| Level 0 | Full baseline backup (like a full backup) |
| Level 1 | Only blocks changed since last Level 0 or Level 1 |
Example:
-- Level 0 (Full baseline)
RMAN> BACKUP INCREMENTAL LEVEL 0 DATABASE;
-- Level 1 (Changed blocks only)
RMAN> BACKUP INCREMENTAL LEVEL 1 DATABASE;
E. Cumulative vs Differential Incremental
| Type | Backs Up |
|---|---|
| Differential (default) | Blocks changed since last incremental backup |
| Cumulative | Blocks changed since last Level 0 backup |
RMAN> BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;
3. Recovery Process in Oracle
A. Complete Recovery
Recovers the database to the most current state -- no data loss. All redo logs are applied.
Steps:
-- Step 1: Restore the database
RMAN> RESTORE DATABASE;
-- Step 2: Recover (apply all redo logs)
RMAN> RECOVER DATABASE;
-- Step 3: Open the database
RMAN> ALTER DATABASE OPEN;
B. Incomplete Recovery (Point-in-Time Recovery)
Recovers the database to a specific point in time before a failure or user error (e.g., accidental table drop).
Types:
| Type | Description |
|---|---|
| Time-based | Recover up to a specific time |
| SCN-based | Recover up to a System Change Number |
| Log sequence-based | Recover up to a specific log sequence |
Example (Time-based):
RMAN> RUN {
SET UNTIL TIME "TO_DATE('2024-01-15 10:00:00','YYYY-MM-DD HH24:MI:SS')";
RESTORE DATABASE;
RECOVER DATABASE;
ALTER DATABASE OPEN RESETLOGS;
}
Note: After incomplete recovery, database must be opened with
RESETLOGS.
C. Tablespace Recovery
Recover a single tablespace without affecting the rest of the database.
RMAN> RESTORE TABLESPACE users;
RMAN> RECOVER TABLESPACE users;
RMAN> ALTER TABLESPACE users ONLINE;
D. Datafile Recovery
Recover a single damaged or missing datafile.
RMAN> RESTORE DATAFILE '/u01/oradata/users01.dbf';
RMAN> RECOVER DATAFILE '/u01/oradata/users01.dbf';
4. ARCHIVELOG Mode vs NOARCHIVELOG Mode
| Feature | ARCHIVELOG | NOARCHIVELOG |
|---|---|---|
| Online backup | Supported | Not supported |
| Complete recovery | Possible | Not possible |
| Point-in-timerecovery | Possible | Not possible |
| Redo log handling | Filled online redo logs are archived before being reused | Online redo logs are overwritten, history is lost |
| Recovery limit | Any point up to the last committed transaction | Only up to the last cold backup |
| Storage cost | Higher, an archive destination must be maintained | Lower |
To enable it:
SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;
5. A Complete Worked Example
RMAN> SQL 'ALTER DATABASE DATAFILE ''/u01/oradata/users01.dbf'' OFFLINE';
RMAN> RESTORE DATAFILE '/u01/oradata/users01.dbf'; -- restore: copy from backup
RMAN> RECOVER DATAFILE '/u01/oradata/users01.dbf'; -- recovery: apply redo
RMAN> SQL 'ALTER DATABASE DATAFILE ''/u01/oradata/users01.dbf'' ONLINE';
RMAN restores the datafile from the Level 0 image, rolls it forward with the Level 1 incrementals, then applies the archived and online redo logs generated since that backup, so the datafile is brought back to 11:00 AM with no committed transaction lost. The rest of the database stays open for users throughout.
If instead a user had dropped a critical table at 10:00 AM, the loss is logical rather than physical, so an incomplete (point-in-time) recovery to 09:59 AM would be used and the database opened with RESETLOGS.
6. Conclusion
Backup, restore and recovery are three distinct stages of one protection strategy: backup creates the redundant copy in advance, restore puts that copy back on disk, and recovery applies redo to make it consistent and current. Oracle supports physical backups (cold and hot) and logical backups (Data Pump), full and incremental levels, and complete or point-in-time recovery. Running the database in ARCHIVELOG mode is the single decision that makes online backup and complete recovery possible, which is why every production Oracle database is configured that way.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.