Complete understanding of Oracle Database Backup and
Recovery
Recovery
Backup:
— backup is a copy
of data which helps in restoring data in case of original data is lost
of data which helps in restoring data in case of original data is lost
— Backups should be taken
in deferent disks than your original data disks to avoid loss of data as well as backups in case of hard disk
failure.
in deferent disks than your original data disks to avoid loss of data as well as backups in case of hard disk
failure.
Ground Rules for Backup and Recovery;
=================================
— We must keep our
backup data into separate drive
backup data into separate drive
— Consistent
Backup
Backup
— There should
not be any changes while taking the backup
not be any changes while taking the backup
— Cold Backup
–
DB Downtime required
DB Downtime required
–
Incomplete recovery
Incomplete recovery
–
Backup is consistent
Backup is consistent
–
You can only recover till the point where you had taken the backup
You can only recover till the point where you had taken the backup
— Database
Recovery
Recovery
–
Restore – Copying data from a backup location.
Restore – Copying data from a backup location.
– Recover
– Recover the database by applying logs or archive logs till the point in time
– Recover the database by applying logs or archive logs till the point in time
Types of Backup
===============
1. Logical backup –
Table backup
Table backup
— Oracle provides different
utilities to take logical backup
utilities to take logical backup
– Export / Import utility
– Datapump utility
2. Physical
backup – OS files (Datafile) backup
backup – OS files (Datafile) backup
Ways to perform backup:
=====================
1. User Managed
—
Cold Database Backup
Cold Database Backup
— Hot Database Backup
Manual
Backup:
Backup:
==============
—
Cold backup and Hot backup are called as manuall backup
Cold backup and Hot backup are called as manuall backup
—
Because backups are performed manually without using any backup tool
Because backups are performed manually without using any backup tool
Manual
Recovery:
Recovery:
================
– When
backups are performed using manual backup then we use manual recovery
backups are performed using manual backup then we use manual recovery
2. Recovery Manager RMAN
Backup states / Types:
==================
1. Consistent
Backup
Backup
— Cold backup
—
No recovery needed
No recovery needed
2.
Inconsistenet Backup
Inconsistenet Backup
—
Hot backup / RMAN Backups
Hot backup / RMAN Backups
—
Recovery needed
Recovery needed
Recovery:
========
1. Complete
Recovery
Recovery
—
Recovering the database exactly till the point of failure
Recovering the database exactly till the point of failure
2. Incomplete
Recovery
Recovery
—
It cannot recover the database till the point of failure
It cannot recover the database till the point of failure
—
You can recover the database till the time you had taken the backup
You can recover the database till the time you had taken the backup
What to back up?
===============
parameter file,
controle file and datafiles
controle file and datafiles
What file needed in deferent stages of
database:
database:
========================================
1. No mount –
Parameter files
Parameter files
2. Mount –
Control file
Control file
3. Open –
Datafiles
Datafiles
Cold Database Backup:
===================
1. Fully consistent
backup
backup
2. Performed
when DB is shut down
when DB is shut down
3. Requires down
time
time
4. User cannot
access the database
access the database
5. No need to
backup redo logs or archive logs
backup redo logs or archive logs
6. A cold backup
is performed using OS level Copy command
is performed using OS level Copy command
7. In real time,
we rarely perform cold backup
we rarely perform cold backup
Cold Database recovery:
====================
1. Simulate a
failure, All the database files have been deleted
failure, All the database files have been deleted
—
Delete pfile / spfile, control files and datafiles
Delete pfile / spfile, control files and datafiles
—
Copy pfile/spfile from cold backup location to dbs location – NO MOUNT STAGE
Copy pfile/spfile from cold backup location to dbs location – NO MOUNT STAGE
—
Copy control files from cold backup location to required location – MOUNT STAGE
Copy control files from cold backup location to required location – MOUNT STAGE
—
Copy datafiles from cold backup location to required location – OPEN STAGE
Copy datafiles from cold backup location to required location – OPEN STAGE
2. All the
transaction happened after the backup was taken will not be there
transaction happened after the backup was taken will not be there
3. You will
recover the database till the point where you have taken the backup
recover the database till the point where you have taken the backup
4. Cold Database
recovery is Incomplete recovery
recovery is Incomplete recovery
Performing Cold Backup and Recovery:
================================
– Get the
location of all the files to be backed up.
location of all the files to be backed up.
—
Parameter file: $ORACLE_HOME/dba
Parameter file: $ORACLE_HOME/dba
—
select name from v$confilfile;
select name from v$confilfile;
—
select name from v$datafile;
select name from v$datafile;
– shutdown the
Database
Database
– Copy all the
files to a Cold backup location
files to a Cold backup location
– Start the
Database and create some dummy tables
Database and create some dummy tables
– Simulate the
failure by removing all files at OS level
failure by removing all files at OS level
– shutdown the
database (Shut abort or kill the OS level instance process)
database (Shut abort or kill the OS level instance process)
– Copy the
parameter file from the Cold backup location to original location
parameter file from the Cold backup location to original location
– Start the
instance in no mount state.
instance in no mount state.
– Copy the
control files from Cold backup location to original location
control files from Cold backup location to original location
—
you can query show parameter controlfile;
you can query show parameter controlfile;
– Take the instance
to mount state
to mount state
– Copy all the
datafiles from Cold backup location to original location
datafiles from Cold backup location to original location
– Open the
Database
Database
– Check for the
dummy table which are created?
dummy table which are created?
—
dummy table will not be exists due to incomplete recovery
dummy table will not be exists due to incomplete recovery
Hot Database Backup:
===================
– Inconsistent
backup
backup
– Backup while
the database is up and running
the database is up and running
– No down time
required
required
– DB Must be in
archive log mode to perform Hot Backup
archive log mode to perform Hot Backup
– We must backup
all the Archive logs from the time of backup to recover the database
all the Archive logs from the time of backup to recover the database
Hot Database recovery (All Datafiles were
lost):
lost):
========================================
– Get the location
of all the files to be backed up.
of all the files to be backed up.
–
select name from v$datafile;
select name from v$datafile;
– Delete all the
data file from OS level
data file from OS level
– shutdown the
database (Shut abort or kill the OS leve instance process)
database (Shut abort or kill the OS leve instance process)
– Copy/Restore all the data
files from the hot backup location (restoring from backup)
files from the hot backup location (restoring from backup)
– Startup mount
– Recover
database;(This part if applying archive logs/redo logs)
database;(This part if applying archive logs/redo logs)
– Alter database
open;
open;
Performing Hot Backup and Recovery (All
Datafiles were lost):
Datafiles were lost):
====================================================
– DB must be up and
running
running
– No downtime
required
required
– Put the
Database in begin backup mode
Database in begin backup mode
–
alter database begin backup;
alter database begin backup;
–
select distinct status from v$backup
select distinct status from v$backup
– Copy all the file
at OS level to Hot backup location
at OS level to Hot backup location
– Put the Database
in end backup mode
in end backup mode
–
alter database end backup;
alter database end backup;
–
select district status from v$backup;
select district status from v$backup;
– Switch the log
file
file
–
alter system switch logfile;
alter system switch logfile;
– Take the
backup of archive logs
backup of archive logs
Hot Database recovery (All Datafiles and
Control files were lost):
Control files were lost):
======================================================
– Get the
location of all the files to be backed up.
location of all the files to be backed up.
–
select name from v$confilfile;
select name from v$confilfile;
–
select name from v$datafile;
select name from v$datafile;
– Delete all the
data files and confilfile from OS level
data files and confilfile from OS level
– shutdown the
database (Shut abort or kill the OS level instance process)
database (Shut abort or kill the OS level instance process)
– Copy/Restore
all the data & Control files from the hot backup location (restoring from
backup)
all the data & Control files from the hot backup location (restoring from
backup)
– Startup mount
– recover
database using backup controlfile until cancel; (applying archive logs/redo
logs)
database using backup controlfile until cancel; (applying archive logs/redo
logs)
–
AUTO
AUTO
– recover
database using backup controlfile until cancel;
database using backup controlfile until cancel;
–
CANCEL
CANCEL
– Alter database
open resetlogs;
open resetlogs;
(resetlogs will reset the
log sequence the start the archive log sequence starting from 1. Database new
in-carnation is started)
log sequence the start the archive log sequence starting from 1. Database new
in-carnation is started)
– login to
database check the archive log sequence
database check the archive log sequence
–
archive log list
archive log list
Performing Hot Backup and Recovery (All
Datafiles and Control files were lost):
Datafiles and Control files were lost):
==================================================================
– DB must be up and
running
running
– No downtime
required
required
– Put the
Database in begin backup mode
Database in begin backup mode
–
alter database begin backup;
alter database begin backup;
–
select distinct status from v$backup
select distinct status from v$backup
– Copy all the file
at OS level to Hot backup location
at OS level to Hot backup location
– Put the
Database in end backup mode
Database in end backup mode
–
alter database end backup;
alter database end backup;
–
select distict status from v$backup;
select distict status from v$backup;
– Switch the log
file
file
–
alter system switch logfile;
alter system switch logfile;
– Take the backup of
archive logs
archive logs
– Create a new
user and create a dummy table
user and create a dummy table
– Simulate
failure of controlefile and datafile loss and recover the Database
failure of controlefile and datafile loss and recover the Database
– Check if new
user and dummy table exists or not
user and dummy table exists or not
RMAN:
======
– Recovery Manager
– Oracle
Database backup and recovery automation
Database backup and recovery automation
– It Introduced
in Oracle 8i version
in Oracle 8i version
– It performs
block level backup
block level backup
– Parallelism
– Detecting
corruption in datafiles
corruption in datafiles
– Validating the
backup
backup
– Incremental
Backup
Backup
– Recovery
Catalog etc
Catalog etc
– Multi Destination
Backups
Backups
– Archive log
mode is must to use RMAN
mode is must to use RMAN
RMAN is faster because it takes block level
backups
backups
RMAN is faster because we can initiate
parallel processes
parallel processes
RMAN will data block corruptions and repair it
for you
for you
RMAN stores backup metadata information in the
database controlfile, you can also store the information into deferent database
on different server which is called as RECOVERY catalog
database controlfile, you can also store the information into deferent database
on different server which is called as RECOVERY catalog
RMAN Incremental Recovery
–
Level 0 – Full database backup
Level 0 – Full database backup
–
Level 1 – Backup of only changed blocks taken by referring data block header
for updated SCN
Level 1 – Backup of only changed blocks taken by referring data block header
for updated SCN
– As per
recovery, we must only restore the database from level 0 and recovery the
Database using level 1. When you try to take level 1 backup, RMAN checks if
already you have level 0 backup or not. If not then it will take level 0 backup
automatically.
recovery, we must only restore the database from level 0 and recovery the
Database using level 1. When you try to take level 1 backup, RMAN checks if
already you have level 0 backup or not. If not then it will take level 0 backup
automatically.
Recovery is of two parts:
–
Restore and Recover – We cannot perform recovery without restore. Hence Level 0
is used for restore and level 1 is used for recovery.
Restore and Recover – We cannot perform recovery without restore. Hence Level 0
is used for restore and level 1 is used for recovery.
RMAN configuration Items
–
show all;
show all;
RMAN Backup Methodology:
========================
– Full Backup
–
Entire Database backup
Entire Database backup
–
Cannot apply Incremental backup on full backup
Cannot apply Incremental backup on full backup
– Incremental
Backup
Backup
–
Level 0 – FULL Database backup
Level 0 – FULL Database backup
–
Level 1 – Backup changes only from last incremental backup
Level 1 – Backup changes only from last incremental backup
Connecting to RMAN utility:
========================
– RMAN utility comes
with Oracle Binaries
with Oracle Binaries
– No special
installation or license required for using RMAN
installation or license required for using RMAN
– At command
prompt just type rman
prompt just type rman
– It defaults
connects to database environmental variables defined
connects to database environmental variables defined
– RMAN utility
can be used only when your DB is in at least MOUNT stage
can be used only when your DB is in at least MOUNT stage
– RMAN is used while the DB
is up and running and have very little performance impact if the backup is
running
is up and running and have very little performance impact if the backup is
running
Components of RMAN:
===================
– RMAN Prompt
– Target
Database
Database
– Recovery
Catalog
Catalog
– Auxiliary
Database — When cloning, Clone DB is called as auxiliary Database
Database — When cloning, Clone DB is called as auxiliary Database
– Media Management Layer —
layer between RMAN 3rd part vendor backup tools netbackup, Veritos and Tape backups
layer between RMAN 3rd part vendor backup tools netbackup, Veritos and Tape backups
– RMAN Channels
RMAN Configuration Parameter:
===========================
– RETENTION POLICY – tells
till what date our backup will be stored which we can use for recovery
till what date our backup will be stored which we can use for recovery
–
Redundancy — How many backups to be retained
Redundancy — How many backups to be retained
–
Recover Window — How many days backup to be retained
Recover Window — How many days backup to be retained
– Channels — You
can define channel to take backup to disk or tape
can define channel to take backup to disk or tape
– Controlfile
auto backup — includes controlfile and spfile autobackup
auto backup — includes controlfile and spfile autobackup
– Parallelism —
Creates multiple processes to speed up backup
Creates multiple processes to speed up backup
– Encryption —
to secure the backup
to secure the backup
RMAN DB FULL back-up on Disk:
===========================
– rman target /
– set
controlfile autobackup on;
controlfile autobackup on;
– backup
database plus archivelog format=’/loc’;
database plus archivelog format=’/loc’;
– Checking
backups
backups
–
list backup;
list backup;
–
list backup of database summary;
list backup of database summary;
Database level 0 Incremental Backup on disk:
======================================
– rman target /
– backup
incremental level 0 database plus archivelog format=’/loc’;
incremental level 0 database plus archivelog format=’/loc’;
– backup
incremental level 1 database plus archivelog format=’/loc’;
incremental level 1 database plus archivelog format=’/loc’;
Recovering DB from Incremental Backup:
===================================
– rman target /
– restore
controlfile from ‘<backup loc>’
controlfile from ‘<backup loc>’
– sql ‘alter
database mount’;
database mount’;
– list backup of
database summery;
database summery;
– restore
database from tag ‘<level 0 Tag>’;
database from tag ‘<level 0 Tag>’;
– recover
database from tag ‘<level 1 Tag>’;
database from tag ‘<level 1 Tag>’;
– sql ‘alter
database open resetlogs’;
database open resetlogs’;
Regards,
Mallik