Simple Backup and Restore Script Using RMAN

Here’s simple backup script using RMAN:

#!/bin/sh
. ~/.bash_profile
export ORACLE_SID=[instance_name]
rman target / log=[/path/to/logfile.log] << EOF
RUN {
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired backup;
delete noprompt expired archivelog all;
backup as compressed backupset database
   tag FULLBACKUPDATA;
sql "alter system switch logfile";
sql "alter system switch logfile";
backup archivelog all
   tag FULLBACKUPARCH
   not backed up 2 times
   delete input;
backup current controlfile;
delete noprompt obsolete RECOVERY WINDOW OF 2 DAYS;
}
EXIT;
EOF

Here’s simple restore script using RMAN duplicate (nocatalog command). Change the ORACLE_SID to the target restore instance first.

connect target sys/[syspassword]@[source_instance]
connect auxiliary /;
run {
set until sequence 23361 thread 1;

SET NEWNAME FOR DATAFILE 1 to '[/path/to/datafile1.dbf]';
SET NEWNAME FOR DATAFILE 2 to '[/path/to/datafile2.dbf]';
SET NEWNAME FOR DATAFILE 3 to '[/path/to/datafile3.dbf]';

set newname for tempfile 1 to '[/path/to/tempfile.dbf]';

duplicate target database to [target_instance]
logfile
           group 1
       ('[/path/to/redologfile1.log]') size 20M,
            group 2
       ('[/path/to/redologfile2.log]) size 20M,
            group 3
       ('[/path/to/redologfile3.log]') size 20M

NOFILENAMECHECK;

}
EXIT;
Simple Backup and Restore Script Using RMAN

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s