Backup and Restore Database using RMAN Script

Backup and Restore Database with RMAN Scripts

RMAN is the utility provided by Oracle for taking backup at physical level.
For hot backup through RMAN you must be enabled archive log at database level.
Check it with archive log list; command in SQL PROMPT.

SQL> ARCHILVE LOG LIST;

Backup the database with RMAN as follows:
 
1. Set the environment variable of Oracle

export ORACLE_HOME=/u01/oracle/dbhome_1
export PATH=$ORACLE_HOME/bin;$PATH
export ORACLE_SID=ORCL

2. Connect with RMAN and execute the file which is in next step or save this line in bat file

#rman nocatalog target / cmdfile=/u01/rmanbackup/Fullbackup.rcv log=/u01/rmanbackup/Fullbackup.log

3. You can save the following script as Fullbackup.rcv in /u01/rmanbackup directory.
Backup database Scripts

run {
allocate channel ch00 type disk;
allocate channel ch01 type disk;
allocate channel ch02 type disk;
backup format '/rmanbackup/full_db_%t_%p%p' filesperset 10 database plus archivelog;
release channel ch00;
release channel ch01;
release channel ch02;
allocate channel ch00 type disk;
backup format '/rmanbackup/cntrl_%s_%p_%t' CURRENT CONTROLFILE;
Backup format '/rmanbackup/spfile_%s_%p_%t' spfile;
release channel ch00;
}

Restore the database from following script:

1. Bring the database in startup nomount.
Startup nomount;

2. Empty the oradata folder for completed restore.

3. Start the recover process as follows.

4. Specify the time up to which you want to recover the database otherwise it will upto last full backup.

5. Restore the control file from backup

run{
allocate channel t1 type DISK;
set until time "to_date('2015/02/27 12:52:00','yyyy/mm/dd HH24:MI:SS')";
restore controlfile from 'scratch/rman_backup/cntrl_18_1_2384554';
release channel t1;
}

6. Bring the database at mount state

sqlplus / as sysdba
alter database mount;

7. Start the restore and recover process if you want database up to specific time then only need to give set until time

rman target /
run {
allocate channel t1 type DISK;
allocate channel t2 type DISK;
set until time "to_date('2015/02/27 12:52:00','yyyy/mm/dd HH24:MI:SS')";
restore database;
recover database;
release channel t1;
release channel t2;
}

8. Open the database in resetlogs:

sqlplus / as sysdba
alter database open resetlogs;

OR
You can also use RMAN single script for restore as follows :
Example:

run {
allocate channel t1 type DISK;
set until time "to_date('2009/02/09 07:00:00','yyyy/mm/dd HH24:MI:SS')";
restore controlfile;
sql "alter database mount";
RESTORE DATABASE;
recover database;
sql "alter database open resetlogs";
release channel t1;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.