Tuesday 2 September 2014

RMAN backup and recovery for oracle database

RMAN
Backup and recovery manager...

Benefit of RMAN:
Database on Any OS, can be taken backup with only RMAN...
RMAN should be used for ASM.

RMAN Client --- > CATALOG Database
RMAN Server --- > TARGET Database

One RMAN catalog can take the backup and keep the backup information of any number of target databases on any OS.



RMAN Demo:

>>> RMAN Catalog Creation.

1 Identify the database to be used for CATALOG operations.
2 Create a tablespace of size 50m, to be used for RMAN catalog tables.
3 Create a user and grant rman permissions, to perform rman operations.
4 Connect to RMAN prompt and create catalog tables.


1. Identified orcl as catalog database.
set ORACLE_SID=orcl
sqlplus "/as sysdba"

2. Create a tablespace of size 50m.
create tablespace ts20 datafile'C:\app\prabhu\oradata\orcl\ts20_01.dbf' size 50m;

3. Create user and grant permissions..
SQL> create user suvendu identified by suvendu default tablespace ts20;
User created.
SQL> grant connect, resource to suvendu;
Grant succeeded.
SQL> grant recovery_catalog_owner to suvendu;
Grant succeeded.

4. Connect to RMAN prompt and create catalog tables.
SQL> host
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Prabhu>rman catalog suvendu/suvendu

Recovery Manager: Release 11.1.0.7.0 - Production on Thu Mar 1 15:34:05 2012
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
connected to recovery catalog database

RMAN> create catalog;
recovery catalog created

RMAN> exit
Recovery Manager complete.

C:\Users\Prabhu>exit
SQL> conn suvendu/suvendu
Connected.
SQL> select count(*) from tab;
  COUNT(*)
----------
       142
SQL> conn /as sysdba
Connected.
SQL>

========== Completes Catalog Creation =============

>>> Target Configuration to take backup using catalog.

1. Identify target database to be backed up.
2. It has to be in Archive Mode.
3. Check target database password file availability.
4. Configure and check connectivity for SYSDBA from catalog to target.
rman target / catalog user/pwd@tns -- from target to catalog
rman target user/pwd@tns catalog user/pwd -- from catalog to target
rman target / nocatalog -- No Catalog, Target cfile will be used for info
5. Connect to RMAN and Register target database with rman catalog.
6. Configure rman parameters.
7. Take backup to backup location.

1. Identify target database to be backed up.
C:\Users\Prabhu>set ORACLE_SID=oracle
C:\Users\Prabhu>sqlplus "/as sysdba"

2. It has to be in Archive Mode.
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled

3. Check target database password file availability.
SQL> select * from v$pwfile_users;
USERNAME                       SYSDB SYSOP SYSAS
------------------------------ ----- ----- -----
SYS                            TRUE  TRUE  FALSE
SQL> alter user sys identified by sys;
User altered.

Alternate Method to create password file..

C:\app\Prabhu\product\11.1.0\db_1\database>orapwd file='PWDoracle.ora' password=
sys force=y

4. Configure and check connectivity for SYSDBA from catalog to target.
tnsping oracle
sqlplus sys/pwd@oracle as sysdba

5. Connect to RMAN and Register target database with rman catalog.

C:\Users\Prabhu>rman catalog suvendu/suvendu target sys/sys@oracle

Recovery Manager: Release 11.1.0.7.0 - Production on Thu Mar 1 15:56:28 2012
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
connected to target database: ORACLE (DBID=1644963733)
connected to recovery catalog database

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

6. Configure rman parameters.
Rman> show all;

RMAN configuration parameters for database with db_unique_name ORACLE are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION on; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default (sbt_tape)
CONFIGURE CONTROLFILE AUTOBACKUP on; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO 'C:\app\Prabhu\rmanbkp\%F.ctl'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET; # default
configure channel 1 device type disk format 'C:\app\Prabhu\rmanbkp\%U.dbf';
configure channel 2 device type disk format 'C:\app\Prabhu\rmanbkp\%U.dbf';
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE BACKUPSET SIZE TO 20000m; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BZIP2'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO 'C:\APP\PRABHU\PRODUCT\11.1.0\DB_1\DATABASE\SNCFORACLE.ORA'; # default


7. Take backup to backup location.
open new terminal.

set ORACLE_SID=orcl
rman catalog suvendu/suvendu target sys/sys@oracle
rman> backup database;


============= Rman Configuration and backup complete ============

Q. What all the types of rman backup?
Ans Rman backups are of two types:
BACKUPSET -  Content bkp
COPY backup. -  As Is bkp.

Test For RMAN backup :Output



C:\Users\Prabhu>set ORACLE_SID=orclMicrosoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Prabhu>set ORACLE_SID=orcl

C:\Users\Prabhu>rman catalog ravi/ravi target sys/sys@oracle

Recovery Manager: Release 11.1.0.7.0 - Production on Thu Mar 1 16:14:46 2012

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

connected to target database: ORACLE (DBID=1644963733)
connected to recovery catalog database

RMAN>

RMAN> backup database;

Starting backup at 01-MAR-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=134 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=140 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=C:\APP\PRABHU\ORADATA\ORACLE\SYSAUX01.DBF
input datafile file number=00005 name=C:\APP\PRABHU\ORADATA\ORACLE\EXAMPLE01.DBF

channel ORA_DISK_1: starting piece 1 at 01-MAR-12
channel ORA_DISK_2: starting full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
input datafile file number=00001 name=C:\APP\PRABHU\ORADATA\ORACLE\SYSTEM01.DBF
input datafile file number=00004 name=C:\APP\PRABHU\ORADATA\ORACLE\USERS01.DBF
channel ORA_DISK_2: starting piece 1 at 01-MAR-12
channel ORA_DISK_1: finished piece 1 at 01-MAR-12
piece handle=C:\APP\PRABHU\RMANBKP\01N4PSCQ_1_1.CTL tag=TAG20120301T161521 comme
nt=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:26
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00003 name=C:\APP\PRABHU\ORADATA\ORACLE\UNDOTBS01.DBF

channel ORA_DISK_1: starting piece 1 at 01-MAR-12
channel ORA_DISK_2: finished piece 1 at 01-MAR-12
piece handle=C:\APP\PRABHU\RMANBKP\02N4PSCQ_1_1.CTL tag=TAG20120301T161521 comme
nt=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:01:26
channel ORA_DISK_1: finished piece 1 at 01-MAR-12
piece handle=C:\APP\PRABHU\RMANBKP\03N4PSFH_1_1.CTL tag=TAG20120301T161521 comme
nt=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 01-MAR-12

Starting Control File and SPFILE Autobackup at 01-MAR-12
piece handle=C:\APP\PRABHU\RMANBKP\C-1644963733-20120301-00.CTL comment=NONE
Finished Control File and SPFILE Autobackup at 01-MAR-12

RMAN>

RMAN> configure channel 1 device type disk format 'C:\app\Prabhu\rmanbkp\%U.dbf'
;

old RMAN configuration parameters:
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT   'C:\app\Prabhu\rmanbkp\%U.ctl';
new RMAN configuration parameters:
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT   'C:\app\Prabhu\rmanbkp\%U.dbf';
new RMAN configuration parameters are successfully stored
released channel: ORA_DISK_1
released channel: ORA_DISK_2
starting full resync of recovery catalog
full resync complete

RMAN> configure channel 2 device type disk format 'C:\app\Prabhu\rmanbkp\%U.dbf'
;

old RMAN configuration parameters:
CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT   'C:\app\Prabhu\rmanbkp\%U.ctl';
new RMAN configuration parameters:
CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT   'C:\app\Prabhu\rmanbkp\%U.dbf';
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

RMAN>

RMAN>

RMAN>

RMAN> list backup summary;

starting full resync of recovery catalog
full resync complete

List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
58      B  F  A DISK        01-MAR-12       1       1       NO         TAG201203
01T161521
59      B  F  A DISK        01-MAR-12       1       1       NO         TAG201203
01T161521
60      B  F  A DISK        01-MAR-12       1       1       NO         TAG201203
01T161521
73      B  F  A DISK        01-MAR-12       1       1       NO         TAG201203
01T161702

RMAN> backup database tag Thu_01Mar12
2> ;

Starting backup at 01-MAR-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=134 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=140 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=C:\APP\PRABHU\ORADATA\ORACLE\SYSAUX01.DBF
input datafile file number=00005 name=C:\APP\PRABHU\ORADATA\ORACLE\EXAMPLE01.DBF

channel ORA_DISK_1: starting piece 1 at 01-MAR-12
channel ORA_DISK_2: starting full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
input datafile file number=00001 name=C:\APP\PRABHU\ORADATA\ORACLE\SYSTEM01.DBF
input datafile file number=00004 name=C:\APP\PRABHU\ORADATA\ORACLE\USERS01.DBF
channel ORA_DISK_2: starting piece 1 at 01-MAR-12
channel ORA_DISK_1: finished piece 1 at 01-MAR-12
piece handle=C:\APP\PRABHU\RMANBKP\05N4PSIP_1_1.DBF tag=THU_01MAR12 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:01:28
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00003 name=C:\APP\PRABHU\ORADATA\ORACLE\UNDOTBS01.DBF

channel ORA_DISK_1: starting piece 1 at 01-MAR-12
channel ORA_DISK_2: finished piece 1 at 01-MAR-12
piece handle=C:\APP\PRABHU\RMANBKP\06N4PSIP_1_1.DBF tag=THU_01MAR12 comment=NONE

channel ORA_DISK_2: backup set complete, elapsed time: 00:01:26
channel ORA_DISK_1: finished piece 1 at 01-MAR-12
piece handle=C:\APP\PRABHU\RMANBKP\07N4PSLH_1_1.DBF tag=THU_01MAR12 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 01-MAR-12

Starting Control File and SPFILE Autobackup at 01-MAR-12
piece handle=C:\APP\PRABHU\RMANBKP\C-1644963733-20120301-01.CTL comment=NONE
Finished Control File and SPFILE Autobackup at 01-MAR-12

RMAN> list backup summary;


List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
58      B  F  A DISK        01-MAR-12       1       1       NO         TAG201203
01T161521
59      B  F  A DISK        01-MAR-12       1       1       NO         TAG201203
01T161521
60      B  F  A DISK        01-MAR-12       1       1       NO         TAG201203
01T161521
73      B  F  A DISK        01-MAR-12       1       1       NO         TAG201203
01T161702
116     B  F  A DISK        01-MAR-12       1       1       NO         THU_01MAR
12
117     B  F  A DISK        01-MAR-12       1       1       NO         THU_01MAR
12
118     B  F  A DISK        01-MAR-12       1       1       NO         THU_01MAR
12
136     B  F  A DISK        01-MAR-12       1       1       NO         TAG201203
01T162011

RMAN> backup as copy database;

Starting backup at 01-MAR-12
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=C:\APP\PRABHU\ORADATA\ORACLE\SYSTEM01.DBF
channel ORA_DISK_2: starting datafile copy
input datafile file number=00002 name=C:\APP\PRABHU\ORADATA\ORACLE\SYSAUX01.DBF
output file name=C:\APP\PRABHU\RMANBKP\DATA_D-ORACLE_I-1644963733_TS-SYSTEM_FNO-
1_09N4PSQ7.DBF tag=TAG20120301T162231 RECID=3 STAMP=776795016
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:08
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=C:\APP\PRABHU\ORADATA\ORACLE\EXAMPLE01.DBF

output file name=C:\APP\PRABHU\RMANBKP\DATA_D-ORACLE_I-1644963733_TS-SYSAUX_FNO-
2_0AN4PSQ7.DBF tag=TAG20120301T162231 RECID=2 STAMP=776795016
channel ORA_DISK_2: datafile copy complete, elapsed time: 00:01:01
channel ORA_DISK_2: starting datafile copy
input datafile file number=00003 name=C:\APP\PRABHU\ORADATA\ORACLE\UNDOTBS01.DBF

output file name=C:\APP\PRABHU\RMANBKP\DATA_D-ORACLE_I-1644963733_TS-EXAMPLE_FNO
-5_0BN4PSSB.DBF tag=TAG20120301T162231 RECID=4 STAMP=776795025
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:06
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=C:\APP\PRABHU\ORADATA\ORACLE\USERS01.DBF
output file name=C:\APP\PRABHU\RMANBKP\DATA_D-ORACLE_I-1644963733_TS-UNDOTBS1_FN
O-3_0CN4PSSC.DBF tag=TAG20120301T162231 RECID=5 STAMP=776795028
channel ORA_DISK_2: datafile copy complete, elapsed time: 00:00:03
output file name=C:\APP\PRABHU\RMANBKP\DATA_D-ORACLE_I-1644963733_TS-USERS_FNO-4
_0DN4PSSJ.DBF tag=TAG20120301T162231 RECID=6 STAMP=776795029
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 01-MAR-12

Starting Control File and SPFILE Autobackup at 01-MAR-12
piece handle=C:\APP\PRABHU\RMANBKP\C-1644963733-20120301-02.CTL comment=NONE
Finished Control File and SPFILE Autobackup at 01-MAR-12


RMAN> exit


Recovery Manager complete.

============Hope It will help you to learn about RMAN======================

No comments:

Post a Comment