7 Backup Recovery And Data Protection

Database Administration · Unit 7

Backup, Recovery and Data Protection

Exam-focused notes for Backup, Recovery and Data Protection (Database Administration, BIT352): what the TU syllabus asks and how it has actually been tested, with 3 solved past questions from this unit.

Backup, Recovery and Data Protection in short

Hardware fails, people make mistakes and disasters happen. Backup and recovery let a DBA bring data back, and Data Guard keeps a ready copy of the database.

Backup, Recovery and Data Protection: notes

Backup definition and necessity

A backup is a copy of data that can be used to rebuild the database after a loss. It can be of datafiles, control files, redo logs and parameter files.

A backup is needed because of:

  • Media failure, such as a disk crash.
  • User error, such as deleting a table by mistake.
  • Software bugs and corruption.
  • Fire, flood or theft.
  • The need to copy the database to another place.

Types of database backup

By how it is made:

  • Physical backup: copies of the actual database files.
  • Logical backup: export of objects and data with Data Pump.

By database state:

  • Cold (offline) backup: taken when the database is shut down.
  • Hot (online) backup: taken while the database is open. It needs ARCHIVELOG mode.

By amount of data:

  • Full backup: all blocks of the chosen files.
  • Incremental backup: only blocks changed since an earlier backup.

By tool:

  • User managed: the DBA copies files with operating system commands.
  • RMAN (Recovery Manager): Oracle's own tool that reads blocks, compresses and tracks backups.
PointCold backupHot backup
Database stateClosedOpen
UsersCannot workCan work
Archive mode neededNoYes
RecoveryRestore to backup timeCan recover up to the last commit

Cold backup procedures and commands

Cold backup is simple. The database must be shut down cleanly so that all files agree.

SELECT name FROM v$datafile;
SELECT name FROM v$controlfile;
SELECT member FROM v$logfile;
SHUTDOWN IMMEDIATE;

Copy all datafiles, control files, redo log files and the parameter file with the operating system.

cp /u01/oradata/orcl/*.dbf  /backup/cold/
cp /u01/oradata/orcl/*.ctl  /backup/cold/
cp /u01/oradata/orcl/*.log  /backup/cold/
cp $ORACLE_HOME/dbs/spfileorcl.ora /backup/cold/

Then start the database again with STARTUP;. The cost of a cold backup is downtime.

What this unit covers

  • Backup definition and necessity
  • Types of database backup
  • Cold backup procedures and commands
  • Hot backup procedures
  • Restore definition and procedures
  • Recovery definition and processes
  • Recovery with examples
  • Oracle Data Guard concepts
  • Data Guard importance and usage

Backup definition and necessity

2080 · 10 marks

Explain the term backup, restore and recovery in oracle database. Also explain the different backups and recovery process with example.[10]

Show solved answer

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.

TypeDescription
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.

LevelDescription
Level 0Full baseline backup (like a full backup)
Level 1Only 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

TypeBacks Up
Differential (default)Blocks changed since last incremental backup
CumulativeBlocks 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:

TypeDescription
Time-basedRecover up to a specific time
SCN-basedRecover up to a System Change Number
Log sequence-basedRecover 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

FeatureARCHIVELOGNOARCHIVELOG
Online backupSupportedNot supported
Complete recoveryPossibleNot possible
Point-in-timerecoveryPossibleNot possible
Redo log handlingFilled online redo logs are archived before being reusedOnline redo logs are overwritten, history is lost
Recovery limitAny point up to the last committed transactionOnly up to the last cold backup
Storage costHigher, an archive destination must be maintainedLower

To enable it:

SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;

5. A Complete Worked Example

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.

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.

Open this answer on its own page →

0 · 10 marks

Why database backup is needed? What are types of database backup? Explain the procedure of cold backup of oracle database with necessary commands.[10]

Note: The reference notes did not contain material on this topic. The following answer is based on standard Oracle Database Administration concepts as taught in BSc CSIT curriculum. --- Database backup is the process of copying and archiving database data so that it can be restored in case of dat...

Open this answer on its own page →

Oracle Data Guard concepts

2080 · 5 marks

What is oracle data guard? Explain its importance in oracle database. [5]

Oracle Data Guard is a high availability, data protection, and disaster recovery solution provided by Oracle Corporation. It creates, maintains, and monitors one or more standby databases as copies of the primary (production) database. If the primary database becomes unavailable due to hardware f...

Open this answer on its own page →