Monday, July 1, 2013

Backup & Recovery using RMAN

Objective:  Clone Database from Machine 1 to Machine 2
Environment: Oracle 10g
O/s: Windows XP

Online Backup from Machine 1
1.    Create new database MRBD using Database configuration assistant
o   Default password is MRBD
2.    Login in SQLPLUS as sys user
o   Connect sys/mrbd@mrbd as sysdba
3.    Create folder D:\oradata
4.    Create New tablespace
o   CREATE TABLESPACE tbs1 DATAFILE 'D:\oradata\tbs1.dbf' SIZE 50M
5.    Create New user named ituser
o   create user ituser identified by ituser default tablespace tbs1 ;
6.    GRANT rights to user
o   grant dba to ituser;
7.    Creating table and insert records.
o   connect ituser/ituser;
o   create table emp (empid number,empname varchar2(100)) tablespace tbs1 ;
o   insert into emp values(1,'koko');
o   insert into emp values(2,'momo');
o   insert into emp values(3,'nono');
o   commit;
8.    Create backup folder as d:\bupnew
9.    Go to RMAN
o   Connect sys/mrbd@mrbd
10. Create backup
run {  
allocate channel ch1 type Disk maxpiecesize = 1900M FORMAT 'd:\bupnew\data_%t_set%s_piece%p_dbid%I.rman';
backup as compressed backupset
incremental level 0
tag mrbdbup_1
filesperset 1
(database);
backup archivelog all delete all input FORMAT       'd:\bupnew\arch_%t_set%s_piece%p_dbid%I.rman';
backup current controlfile format 'd:\bupnew\ctl_%t_dbid%I.rman';
}

11. Backup command will creates files

12.   Get DBID
o   Connect sys/mrbd@mrbd as sysdba
o   Select dbid from v$database

Restore Backup on Machine 2
1.    Create new database MRBD using Database configuration assistant
o   Default password is MRBD
2.    Copy folder bupnew from machine 1 to Machine 2
o   Backup folder location must be same.\
3.    Create folder D:\oradata
4.    Login in SQLPLUS as sys user
o   Connect sys/mrbd@mrbd as sysdba
5.    Get database in no mount state by running following command
o   Shutdown immediate
o   Startup nomount
6.    Connect to RMAN
o   Set dbid  1714560268
o   Connect target sys/mrbd@mrbd
7.    Restore control file
o   restore controlfile from ‘D:\bupnew\CTL_819202842_DBID1714560268.RMAN’
8.    Mount the database from sqlplus
o   alter database mount;
9.    Register backup  from RMAN
·         run {
    catalog backuppiece 'D:\bupnew\CTL_819202842_DBID1714560268.RMAN';

}

10. Validate files from RMAN
·           crosscheck archivelog all;
·           crosscheck backup;

11. Get datafiles name from SQLPLUS
·         select file#,name from v$datafile;
12. Run restore command from RMAN
run
{
   set newname for datafile  1 to
 "c:\ORACLE\PRODUCT\10.2.0\ORADATA\MRBD\SYSTEM01.DBF";
   set newname for datafile  2 to
 "c:\ORACLE\PRODUCT\10.2.0\ORADATA\MRBD\UNDOTBS01.DBF";
   set newname for datafile  3 to
 "c:\ORACLE\PRODUCT\10.2.0\ORADATA\MRBD\SYSAUX01.DBF";
   set newname for datafile  4 to
 "c:\ORACLE\PRODUCT\10.2.0\ORADATA\MRBD\USERS01.DBF";
   set newname for datafile  5 to
 "D:\ORADATA\TBS1.DBF";
 RESTORE DATABASE;
    SWITCH DATAFILE ALL;
 }

13. Change all redo log files path in control file (Refer redo log files at C:\oracle\product\10.2.0\oradata\mrbd)
·         alter database rename file 'D:\ORACLE10G\PRODUCT\10.2.0\ORADATA\MRBD\REDO01.LOG' to 'c:\ORACLE\PRODUCT\10.2.0\ORADATA\MRBD\REDO01.LOG';
·         alter database rename file 'D:\ORACLE10G\PRODUCT\10.2.0\ORADATA\MRBD\REDO02.LOG' to 'c:\ORACLE\PRODUCT\10.2.0\ORADATA\MRBD\REDO02.LOG';
·         alter database rename file 'D:\ORACLE10G\PRODUCT\10.2.0\ORADATA\MRBD\REDO03.LOG' to 'c:\ORACLE\PRODUCT\10.2.0\ORADATA\MRBD\REDO03.LOG';


14. recover database from rman
·         RECOVER DATABASE;
·         It shows following exception
o   If it give ORA-19698 then
o   Shutdown database from sqlplus
o   Copy all redo log files to C:\oracle\product\10.2.0\oradata\mrbd from machine 1
o   Startup mount
o   Recover database
15. Open database from sqlplus
·         alter database open resetlogs;

16. Validate the restore using sqlplus
·         Conn ituser/ituser@mrbd

·         Select count(*) from emp  //it should be greater than 0

No comments:

Post a Comment