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;
}
Steps to create oracle RMAN Recovery catalog
Recovery catalog
A recovery catalog is a database schema used by RMAN to store metadata about Oracle databases. Generally, we store the catalog in a separate database.
Benefits of Recovery catalog are:
-
A recovery catalog creates redundancy for the RMAN repository stored in the control file of each target database. If the
target control file and all backups are lost, then the RMAN metadata
still exists in the recovery catalog.
-
A recovery catalog centralizes metadata for all target
databases. simpler reporting and
administration of backups.
-
A recovery catalog can store metadata history much longer than the
control file.
The catalog includes the following types of metadata:
-
Datafile and archived redo log backup sets and backup pieces
-
Datafile copies
-
Archived redo logs and their copies
-
Database structure (tablespaces and datafiles)
-
Stored scripts, which are named user-created sequences of RMAN commands
-
Persistent RMAN configuration settings
-
Step 1. Create Recovery Catalog
-- Create tablepsace to hold repository
SQL>CREATE TABLESPACE "RMAN"
DATAFILE 'D:\ORACLE \ORADATA\DB1\RMAN01.DBF' SIZE 1000K REUSE
AUTOEXTEND ON;
-- Create rman schema owner
SQL>CREATE USER rman IDENTIFIED BY rman
TEMPORARY TABLESPACE temp
DEFAULT TABLESPACE rman
QUOTA UNLIMITED ON rman;
SQL>GRANT connect, resource, recovery_catalog_owner TO rman;
C:>rman catalog=rman/rman@db1
Recovery Manager: Release 9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to recovery catalog database
recovery catalog is not installed
RMAN> create catalog tablespace "RMAN";
recovery catalog created
RMAN> exit
Recovery Manager complete.
Step 2. Register Database
C:>rman catalog=rman/rman@db1 target=sys/password@db2
Recovery Manager: Release 9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database: db2 (DBID=1371963417)
connected to recovery catalog database
RMAN> register database;
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
RMAN>
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.
|