Wednesday, July 23, 2008

RMAN

Recovery Manager (RMAN)
Recovery manager is a platform independent utility for coordinating your backup and restoration procedures across multiple servers. In my opinion it's value is limited if you only have on or two instances, but it comes into it's own where large numbers of instances on multiple platforms are used. The reporting features alone mean that you should never find yourself in a position where your data is in danger due to failed backups.
CONNECT sys/password@rmandb AS SYSDBA

-- Create tablepsace to hold repository
CREATE TABLESPACE "RMAN" DATAFILE '/u01/oracle/oradata/rmandb/RMAN01.DBF' SIZE 6208K EXTENT MANAGEMENT LOCALSEGMENT SPACE MANAGEMENT AUTO;
-- Create rman schema owner
CREATE USER rman IDENTIFIED BY rman
TEMPORARY TABLESPACE temp
DEFAULT TABLESPACE rman
QUOTA UNLIMITED ON rman;


GRANT connect, resource, recovery_catalog_owner TO rman;

Then create the recovery catalog:
C:>rman

catalog=rman/rman@rmandb
Recovery Manager: Release 9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to recovery catalog databaserecovery catalog is not installed
RMAN> create catalog tablespace "RMAN";
recovery catalog created
RMAN> exit
Recovery Manager complete.


Register DatabaseEach database to be backed up by RMAN must be registered:


$rman

catalog=rman/rman@rmandb target=sys/password@test
Recovery Manager: Release 9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database: test (DBID=1371963417)connected to recovery catalog database
RMAN> register database;
database registered in recovery catalogstarting full resync of recovery catalogfull resync complete


RMAN>Existing user-created backups can be added to the catalog using:


RMAN> catalog datafilecopy '/u01/oracle/oradata/TSH1.dbf';RMAN> catalog archivelog 'log1', 'log2', 'log3', ... 'logN';
Full BackupFirst we configure several persistant parameters for this instance:
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 '/uo1\test\Backup%d_DB_%u_%s_%p';
Next we perform a complete database backup using a single command:

RMAN> run

{
2> backup database plus archivelog;
3> delete noprompt obsolete;
4> }
The recovery catalog should be resyncronized on a regular basis so that changes to the database structure and presence of new archive logs is recorded. Some commands perform partial and full resyncs implicitly, but if you are in doubt you can perform a full resync using the follwoing command:

RMAN> resync catalog;
Restore & Recover The Whole DatabaseIf the controlfiles 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;
}
This will result in all datafiles being restored then recovered.
RMAN will apply archive logs as necessary until the recovery is complete.
At that point the database is opened. If the tempfiles are still present you can issue a command like like the following for each of them:

sql "ALTER TABLESPACE temp ADD TEMPFILE ''/u01/oracle/oradata/test/temp01.dbf'' REUSE";

If the tempfiles are missing they must be recreated as follows:

sql "ALTER TABLESPACE temp ADD TEMPFILE ''/u01/oracle/oradata/test/temp01.dbf'' SIZE 100M AUTOEXTEND ON NEXT 64K";




*******************************************************************************************************************************


Backup script For NON RAC

run
{
allocate channel c1 type disk;
BACKUP AS COMPRESSED BACKUPSET DATABASE FORMAT '/u01/rman_%d_%u_%s_%T';
release channel c1;
allocate channel c1 type disk;
backup as compressed backupset archivelog all FORMAT '/u01/rman_arch_%d_%u_%s_%T';
release channel c1;
}

Backup script For RAC

run
{
allocate channel c1 type disk connect 'syst/syst@car1';
allocate channel c2 type disk connect 'syst/syst@car2';
BACKUP AS COMPRESSED BACKUPSET DATABASE FORMAT '+DATA/rman_%d_%u_%s_%T';
release channel c1;
release channel c2;
allocate channel c1 type disk connect 'syst/syst@car1';
allocate channel c2 type disk connect 'syst/syst@car2';
backup as compressed backupset archivelog all FORMAT '+DATA/rman_arch_%d_%u_%s_%T';
release channel c1;
release channel c2;
}
 

No comments: