Oracle RMAN Commands and Scripts Examples
Full Backup
Full database plus archivelog backup on file system
RMAN> configure retention policy to recovery window of 7 days;
RMAN> configure default device type to disk;
RMAN> configure controlfile autobackup on;
RMAN> configure channel device type disk format 'D:\Oracle\Admin\db2\Backup%d_DB_%u_%s_%p';
RMAN> run {
2> backup database plus archivelog;
3> delete noprompt obsolete;
4> }
#*** Weekly full database plus archivelog backup Script on disk
BACKUP CHECK LOGICAL
AS COMPRESSED BACKUPSET
INCREMENTAL LEVEL = 0
DEVICE TYPE DISK
TAG = 'WEEKLY_DATABASE'
FORMAT '/srv/oradata/backups/weekly_database_%d_t%t_s%s_p%p' or ’Path’
DATABASE;
#*** Daily full database backup Script on disk
BACKUP CHECK LOGICAL
AS COMPRESSED BACKUPSET
INCREMENTAL LEVEL = 1 CUMULATIVE
DEVICE TYPE DISK
TAG = 'DAILY_COMULATIVE_DATABASE'
FORMAT '/srv/oradata/backups/daily_comulative_database_%d_t%t_s%s_p%p' or ‘Path’
DATABASE;
#*** Maintenance steps
CROSSCHECK COPY;
CROSSCHECK BACKUP;
CROSSCHECK ARCHIVELOG ALL;
DELETE NOPROMPT OBSOLETE;
DELETE NOPROMPT EXPIRED COPY;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
Restore & Recover The Whole Database
If the control files and
online redo logs are still present a whole database recovery can be achieved by
running the following script:
run {
shutdown immediate; # use abort if this fails
startup mount;
restore database;
recover database;
alter database open;
}
SAMPLE RMAN SCRIPTS
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
set newname for datafile 1 to
'/extracts1/DB01_temp/system_01a.dbf';
set newname for datafile 2 to
'/extracts1/DB01_temp/rbslrg01.dbf';
set newname for datafile 3 to
'/extracts1/DB01_temp/tools01.dbf';
set newname for datafile 4 to
'/extracts1/DB01_temp/temp01.dbf';
set newname for datafile 5 to
'/extracts1/DB01_temp/usersdata01.dbf';
set newname for datafile 6 to
'/extracts1/DB01_temp/usersidx01.dbf';
set newname for datafile 7 to
'/extracts1/DB01_temp/oem_repository.dbf';
set newname for datafile 8 to
'/extracts1/DB01_temp/users01.dbf';
restore database ;
switch datafile all;
}
-- If archivelogs are
backed up by RMAN, use RMAN to restore them:
rman target / nocatalog
allocate channel ch1 type disk;
run {
restore archivelog from time = 'date-of-start-of-backup';
}
exit
rman target / nocatalog
allocate channel ch1 type disk;
run {
restore database;
}
exit
Hot Backup
Hot backups using RMAN are
very simple. There is no need to alter the tablespace or database mode.
run {
allocate channel ch1 type disk format 'd:\oracle\backup%d_DB_%u_%s_%p';
backup database;
backup archivelog all;
release channel ch1;
}
What are different modes of Backup in Oracle RMAN ?
Backup Modes in Oracle RMAN:
|
Backup Type
|
Definition
|
|
Full
|
This is method in which backup of a datafile
that includes every allocated block in the file being backed up. A full
backup of a datafile can be an image copy, in which every data block is
backed up. It can also be stored in a backup set, in which case datafile
blocks not in use may be skipped.
A
full backup cannot be part of an incremental backup strategy; that is, it
cannot be the parent for a subsequent incremental backup.
|
|
Incremental
|
An incremental backup is either a level 0 backup,
which includes every block in the file except blocks compressed out because
they have never been used, or a level 1 backup, which includes only those
blocks that have been changed since the parent backup was taken.
A level 0
incremental backup is physically identical to a full backup. The only
difference is that the level 0 backup is recorded as an incremental backup in
the RMAN repository, so it can be used as the parent for a level 1 backup.
|
What is RMAN (Recovery Manager) ?
RECOVERY MANAGER
Recovery Manager is one of the most
efficient method of executing the backup, restore, or recovery
operation and then executes these operations in concert with the Oracle
database server. Recovery Manager and the server automatically identify
changes to the structure of the database and dynamically modify the required operation to incorporate the changes.
Recovery
manager is a platform independent utility for backup and
restoration procedures across multiple servers. IMO it's value is
limited if we only have on or two instances, but it comes into it's own where
large numbers of instances on multiple platforms are used. The reporting
features alone mean that you should never find yourself in a position where
your data is in risk due to failed backups
Recovery Manager is
Oracle’s utility to manage the backup, and more importantly the recovery, of
the database. It eliminates operational complexity while providing superior
performance and availability of the database. Recovery Manager introduced in
Oracle8 to provide DBA's a integrated backup and recovery solution
