backup and recovery procedure
TRANSCRIPT
Anar Godjaev
Backup & Recovery Procedure
Anar Godjaev
Introduction
In general, backup and recovery refers to the various strategies and procedures involved in protecting your database against data loss and reconstructing the database after any kind of data loss.
Oracle various kinds of backup like Physical, Logical.
Physical Backup is backups of physical files used in database like controlfile, datafile and archivelog files.
Logical Backup contain logical data, like table and procedure, exported from the database with oracle export utility and stored in binary format
1. Type of failures
Following are the types of failures that require recovery from the backup:
User Error
User errors occur when, either due to an error in application logic or a manual misstep; data in your database is changed or deleted incorrectly. Data loss due to user error includes such missteps as dropping important tables or deleting or changing the contents of a table. While user training and careful management of privileges can prevent most user errors, your backup strategy determines how gracefully you recover the lost data when user error does cause data loss.
Media Failure
A media failure is the failure of a read or write of a disk file required to run the database, due to a physical problem with the disk such as a head crash. Any database file can be vulnerable to a media failure.
2. Backup options in Oracle
Physical backups
Cold (off-line) backup Full database only Require downtime Not flexible for point in time recovery
Hot (on-line) backup Different types of backups: full, incremental,
archive logs No need of database downtime Database can be recovered to any point in
time ,based on backup retention period
Logical backups
Logical copy of data in the database (like tables, packages) Can be taken either with Export/Import tools or with Data Pump (10g/11g)
Anar Godjaev
3. Perform backup and recovery based on physical backups
There are two ways to perform backup and recovery based on physical backups:
Recovery Manager (RMAN)
RMAN is as a tool (with command-line client and Enterprise Manager GUI interfaces) that integrates with sessions running on the Oracle server to perform backup and recovery activity
User Managed
In user managed backup user has to make the periodic backup of all the datafiles, control files, parameter files using operating system commands and recovery the database using SQL* Plus recovery command
4. Recovery Manager (RMAN)
RMAN can back up entire database; all datafiles in a tablespace, selected datafiles, control files and archived redo log files.
Benefits of RMAN
RMAN is a tool that comes at no extra cost. It is available free with the Oracle Database. Supports incremental backup strategies Supports parallel operations (Multiple Channels for Backup and Restore) RMAN can detect corrupted blocks Controlfiles and spfile of database can be configured to automatically backup by RMAN Knows what needs to be backup Knows what is required for the recovery Remembers location of the backup sets
5. RMAN Incremental Backup
RMAN incremental backups back up only datafile blocks that have changed since a specified previous backup. Incremental backups can be of full databases, individual tablespaces or datafiles. For full backups, if database is in ARCHIVELOG mode, you can make incremental backups if the database is open; if the database is in NOARCHIVELOG mode, then you can only make incremental backups after a consistent shutdown.
Level 0 and Level 1 Incremental Backups
Incremental backups can be either level 0 or level 1. A level 0 incremental backup, which is the base for subsequent incremental backups, copies all blocks containing data, backing the datafile up into a backup set just as a full backup would.
Incremental level 1 backup can be of two types
Differential Backup
It backs up all blocks changed after the most recent incremental backup at level 1 or 0
Anar Godjaev Cumulative Backup
It backs up all blocks changed after the most recent incremental backup at level 0.
The size and the time to take backup solely depend upon the number of modified and incremental backup level.
6. RMAN Setup
RMAN configuration
RMAN has been configured to support the backup and recover strategies. The backup strategy is as follows,
A level zero backup on Sundays A level one cumulative backup on the remaining days
RMAN configuration parameters
The configuration parameters are as follows
Configure RMAN to backup the control file after each backup.
CONFIGURE CONTROLFILE AUTOBACKUP ON;
Configure RMAN to write controlfile autobackups to the /backup directory.
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '<backup_path>/%F';
Configure RMAN to use <no of cpu> disk channels for backup, restore, recovery, and maintenance operations.
CONFIGURE DEVICE TYPE DISK PARALLELISM <no of cpu>;
Configure the channel to use <no of cpu> disk channels for backup, restore, recovery, and maintenance operations.
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT ‘<path for backup>/ ora_df%t_s%s_s%p';
RMAN backup scripts
The level 0 backup script is as follows:
RMAN> BACKUP INCREMENTAL LEVEL 0 DATABASE PLUS ARCHIVELOG;
The level 1 backup script is as follows:
RMAN> BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE PLUS ARCHIVELOG;
Anar Godjaev
RMAN restore and recovery scenarios
Case 1: Datafile recovery
This section assumes that datafile 5 has been damaged and needs to be restored and recovered, and that the current controlfile and all other datafiles are intact. The database is open during the restore and recovery.
The steps are:
Offline the datafile that needs recovery
RMAN> SQL 'ALTER DATABASE DATAFILE 5 OFFLINE';
Restore the datafile from backups
RMAN> RESTORE DATAFILE 5;
Recover the datafile
RMAN> RECOVER DATAFILE 5;
Make online recovered datafile
RMAN> SQL 'ALTER DATABASE DATAFILE 5 ONLINE';
Case 2: Tablespace recovery
This section assumes that tablespace tbs_5, containing datafiles 5, 6, and 7 has been damaged and needs to be restored and recovered, and that the current controlfile and all other datafiles are intact. The database is open during the restore and recovery.
The steps are:
Offline the tablespace that needs recovery
RMAN> SQL 'ALTER TABLESPACE TBS_5 OFFLINE';
Restore the tablespace from backups
RMAN> RESTORE TABLESPACE TBS_5;
Recover the tablespace
RMAN>RECOVER TABLESPACE TBS_5;
Online the recovered tablespace
RMAN>SQL 'ALTER TABLESPACE TBS_5 ONLINE';
Anar Godjaev
Case 3: Disaster recovery
This section assumes that all control files, data files and parameter files are lost. To perform recovery in this case, the initialization parameters needs to be restored manually by editing the default initialization parameter file available in the ORACLE_HOME path and set the parameters according to the requirements. Then use RMAN to restore and recover the database as described below.
The commands below assume that all initialization parameter files are restored and the complete directory structures for datafiles are recreated.
Login to RMAN command prompt
$rman target /
Set the DBID of the database
Set dbid <DBID of database to restore>
Start the database in nomount mode
RMAN> STARTUP NOMOUNT;
Restore the control file from backup
RMAN>RESTORE CONTROLFILE FROM ‘<path_of_backup>/<latest controlfile from backup>;
Change the database from nomunt mode to mount mode
RMAN> ALTER DATABASE MOUNT;
Restore the database
RMAN> RESTORE DATABASE;
Recover the database
RMAN> RECOVER DATABASE;
Open the database with resetlogs
RMAN> ALTER DATABASE OPEN RESETLOGS;
You must take a new whole database backup after resetlogs, since backups of previous incarnation are not easily usable.