Saturday, December 19, 2009

RMAN BASICS

RMAN is not "too" different from WinZip. Since everybody knows WinZip, it will probably be easier to understand RMAN. Just like compressing a folder using WinZip, RMAN creates a compressed backup of the physical database files, including controlfiles, datafiles, archived logs and stores them somewhere. This somewhere can be a disk or a tape.

Therefore, the first important point to remember is:

“RMAN creates compressed backups of the physical database; if you prefer, RMAN zips the database, the way you like it”.


The usual definition for RMAN is given as,

Recovery Manager is a client/server application that uses database server sessions to perform backup and recovery. It stores metadata about its operations in the control file of the target database and, optionally, in a recovery catalog schema in an Oracle database.

Why Should we use RMAN

Ability to perform incremental backups.Ability to recover one block of a datafile.
Ability to perform the backup and restore with parallelization.
Ability to automatically delete archived redo logs after they are backed up.
Ability to automatically backup the control file and the SPFILE.
Ability to restart a failed backup without having to start from the beginning.
Ability to verify the integrity of the backup.
Ability to test the restore process without having to actually perform the restore.
Comparison of RMAN Automated and User-Managed Procedures
By using operating system commands for User-Managed Backup and Recovery , a DBA manually keeps track of all database files and backups. But RMAN performs these same tasks automatically.

Understanding the RMAN Architecture
An oracle RMAN comprises of RMAN EXECUTABLE This could be present and fired even through client side, TARGET DATABASE (This is the database which needs to be backed up) and RECOVERY CATALOG (Recovery catalog is optional otherwise backup details are stored in target database controlfile .)

About the RMAN Repository

The RMAN repository is a set of metadata that RMAN uses to store information about the target database and its backup and recovery operations. RMAN stores information about:

Backup sets and pieces
Image copies (including archived redo logs)
Proxy copies
The target database schema
Persistent configuration settings
If you start RMAN without specifying either CATALOG or NOCATALOG on the command line, then RMAN makes no connection to a repository. If you run a command that requires the repository, and if no CONNECT CATALOG command has been issued yet, then RMAN automatically connects in the default NOCATALOG mode. After that point, the CONNECT CATALOG command is not valid in the session.

Types of Database Connections

You can connect to the following types of databases.
Target database
RMAN connects you to the target database with the SYSDBA privilege. If you do not have this privilege, then the connection fails.

Recovery catalog database

This database is optional: you can also use RMAN with the default NOCATALOG option.

Auxiliary database

You can connect to a standby database, duplicate database, or auxiliary instance (standby instance or tablespace point-in-time recovery instance
Note:
That a SYSDBA privilege is not required when connecting to the recovery catalog. The only requirement is that the RECOVERY_CATALOG_OWNER role be granted to the schema owner.

Using Basic RMAN Commands

After you have learned how to connect to a target database, you can immediately begin performing backup and recovery operations. Use the examples in this section to go through a basic backup and restore scenario using a test database. These examples assume the following:

The test database is in ARCHIVELOG mode.
You are running in the default NOCATALOG mode.
The RMAN executable is running on the same host as the test database.

Connecting to the Target Database

rman TARGET /

If the database is already mounted or open, then RMAN displays output similar to the following:

Recovery Manager: Release 9.2.0.0.0

connected to target database: RMAN (DBID=1237603294)

Reporting the Current Schema of the Target Database
In this example, you generate a report describing the target datafiles. Run the report schema command as follows:

RMAN> REPORT SCHEMA; (RMAN displays the datafiles currently in the target database.

Backing Up the Database

In this task, you back up the database to the default disk location. Because you do not specify the format parameter in this example, RMAN assigns the backup a unique filename.

You can make two basic types of backups: full and incremental.

Making a Full Backup

Run the backup command at the RMAN prompt as follows to make a full backup of the datafiles, control file, and current server parameter file (if the instance is started with a server parameter file) to the default device type:
RMAN> BACKUP DATABASE;

Making an Incremental Backup

Incremental backups are a convenient way to conserve storage space because they back up only database blocks that have changed. RMAN compares the current datafiles to a base backup, also called a level 0 backup, to determine which blocks to back up.

RMAN> BACKUP INCREMENTAL LEVEL 1 DATABASE;

Backing Up Archived Logs
Typically, database administrators back up archived logs on disk to a third-party storage medium such as tape. You can also back up archived logs to disk. In either case, you can delete the input logs automatically after the backup completes.To back up all archived logs and delete the input logs (from the primary archiving destination only), run the backup command at the RMAN prompt as follows:

RMAN> BACKUP ARCHIVELOG ALL DELETE INPUT;

Listing Backups and Copies

To list the backup sets and image copies that you have created, run the list command as follows:

RMAN> LIST BACKUP;

To list image copies, run the following command:

RMAN> LIST COPY;

Friday, December 18, 2009

RMAN - RESTORING A DATAFILE

1) Click the start button and give RUN. Type cmd and the command window will open.

2) Type sqlplusw/nolog and the sql window will open

3) Type conn / as sysdba, a message “connected to an idle instance” will be displayed

4) Now give startup , you will get the below message,

Total System Global Area 118255568 bytes

Fixed Size 282576 bytes

Variable Size 83886080 bytes

Database Buffers 33554432 bytes

Redo Buffers 532480 bytes

Database mounted.

Database opened.

5) The above steps you have to use every time you use oracle

For working with RMAN, the archive log mode must be enabled.

6) To check whether the database is in archive log mode use this command,

Sql> select log_mode from v$database;

If its in noarchive log mode then you have to shut down the database and then start the database in mount state and then change it to archive log mode.

i.e. sql>shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down

Sql> conn / as sysdba

connected to an idle instance

sql>startup mount

Total System Global Area 18255568 bytes

Fixed Size 282576 bytes

Variable Size 83886080 bytes

Database Buffers 33554432 bytes

Redo Buffers 532480 bytes

Database mounted

Sql>alter database archivelog;

Database altered.

Sql>alter database open;

Database altered.

The database is in archive log mode, now we can use RMAN.

7) Go to the command prompt and type RMAN

Now you will see the directory will change from c:/documents and settings / to RMAN>

RMAN>connect target /

RMAN will now be connected to the target database

Taking backup of the entire database:

RMAN>BACKUP DATABASE;

The backup of the entire database is taken using this command

We can also use

RMAN>BACKUP DATABASE PLUS ARCHIVELOG;

Recovery from missing or corrupted datafile(s):


This scenario deals with a situation where a datafile has gone missing, or is corrupted beyond repair. Go to oracle->oradata->DINESH (db name)and delete users01.dbf.Then connect to oracle. Below is a transcript of an SQL Plus session that attempts to open a database with a missing datafile (typed commands in bold, lines in italics are my comments; all other lines are feedback from SQL Plus :) Backup of the entire database is necessary here.

.

Ok now,

In the command prompt give
C:\>sqlplusw /nolog



--Connect to the idle Oracle process as a privileged user and start up instance

SQL> connect / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.

Total System Global Area 118255568 bytes

Fixed Size 282576 bytes

Variable Size 83886080 bytes

Database Buffers 33554432 bytes

Redo Buffers 532480 bytes

Database mounted.

ORA-01157: cannot identify/lock data file 8 - see DBWR trace file

ORA-01110: data file 8: 'G:\ORACLE\ORADATA\DINESH\USERS01.DBF'

The error message tells us that file# 8 is missing. Note that although the startup command has failed, the database is in the mount state. Thus, the database control file, which is also the RMAN repository, can be accessed by the instance and by RMAN. We now recover the missing file using RMAN. The transcript of the recovery session is reproduced below (bold lines are typed commands, comments in italics, the rest is feedback from RMAN :)

--logon to RMAN

C:\>rman

Recovery Manager: Release 9.0.1.1.1 - Production

(c) Copyright 2001 Oracle Corporation. All rights reserved.

RMAN> connect target /

connected to target database: DINESH (DBID=3800052808)


--restore missing datafile



RMAN> restore datafile 8;

--restore missing datafile

Starting restore at 18-DEC-09

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00008 to G:\ORACLE\ORADATA\DINESH\USERS01.DBF

channel ORA_DISK_1: restored backup piece 1

piece handle=G:\ORACLE\ORA90\DATABASE\01L16IB2_1_1 tag=null params=NULL

channel ORA_DISK_1: restore complete

Finished restore at 18-DEC-09



RMAN> recover datafile 8;

Starting recover at 18-DEC-09

Using channel1 ORA_DISK_1

Starting media recovery

Media recovery complete

Finished recover at 18-DEC-09



--open database for general use

RMAN> alter database open;

database opene
d

Now open oracle->oradata->DINESH and you will find that the deleted USERS01.DBF is present.


CLICK HERE TO KNOW MORE