Sunday, October 9, 2011

Oracle RMAN -Simple commands

Recovery Manager :RMAN is a oracle utility used for backup and recovery purpose, following are simple commands to initiate with RMAN

connecting to RMAN
===========================

$ rman target sys/
If you’re accessing your target database remotely via Oracle Net, then you will need to
specify a connection string as follows:
$ rman target sys/@
You can also invoke RMAN and then connect to your target database as a second step,
from the RMAN prompt:
$ rman
RMAN> connect target /

Backing Up Your Database
===========================
You’re new to RMAN, and you want to back up your database. You just need to get a backup
created, and you want to take the simplest possible approach.
Solution
Start the rman utility, connect to your target database, and use the backup command to back up
your entire database:
$ rman target /
RMAN> backup database;


Simulating a Failure
================================
You want to simulate a failure as a prelude to testing RMAN’s restore and recovery capabilities.
Solution
To simulate a failure, perform the following steps:
1. Ensure you have a backup.
2. Determine the location and name of a datafile to rename. You will simulate failure by
renaming a datafile so that it appears to have been lost.
3. Stop the database.
4. Rename a datafile at the OS level (simulates media failure).
5. Attempt to start the database.

Before simulating a media failure, ensure that you’re in a noncritical test database environment
and that you have a good RMAN backup of your database. Run the following
command in your target database, and ensure that you have a good backup:
RMAN> connect target /
RMAN> list backup;

Caution If no backup information is listed, then stop here. You need to ensure that you have a good
backup of your database before you simulate media failure.
Determine the location of a target database datafile so that you can rename it to simulate
media failure:

RMAN> report schema;

Shown next is an abbreviated portion of the output of the previous command. This shows
the name of the file that you’re going to rename.

File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
4 22 USERS *** C:\ORA01\BRDSTN\USERS01.DBF

RMAN> shutdown immediate;
RMAN> exit

then rename the datafile to simulate

RMAN> connect target /
RMAN> startup

RMAN-03002: failure of startup command
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: 'C:\ORA01\BRDSTN\USERS01.DBF'



Restoring and Recovering Your Database
==========================================
You’ve experienced a failure and want to use RMAN to restore and recover your database. You
have a current and good backup in the default location, and all needed control files, archived
redo log files, and online redo log files are available.
Solution
Connect to RMAN, and use the following commands to restore and recover your database. In
this recipe you’ll perform the following steps:
1. Connect to the target database.
2. Mount the database.
3. Restore the database.
4. Recover the database.
5. Open the database.


RMAN> connect target /
RMAN> startup mount;
RMAN> restore database;
RMAN> recover database;
RMAN> alter database open;
database opened