Wednesday, January 2, 2013

Rman incremental backup and restore an example

its a simple demonstration of rman incremental backup and restore , any oracle enthusiast can follow this post and can understand how rman incremental backup will works.

C:\Users\Admin\mahi>set ORACLE_SID=idea
C:\Users\Admin\mahi>rman target sys/sys
Recovery Manager: Release 11.2.0.1.0 - Production on Thu Jan 3 10:39:31 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
connected to target database: IDEA (DBID=1142773416)

RMAN> show all;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name IDEA are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO 'C:\rman\%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   'c:\rman\idea_%U';
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO 'E:\APP\ADMIN\PRODUCT\11.2.0\DBHOME_1\DATABASE\SNCFIDEA.ORA'; # default

Here i took the full incremental level 0 backup,

RMAN>  BACKUP INCREMENTAL LEVEL 0 DATABASE TAG 'FULL_INC';
Starting backup at 03-JAN-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=160 device type=DISK
channel ORA_DISK_1: starting incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=E:\DATA\IDEA\SYSTEM01.DBF
input datafile file number=00002 name=E:\DATA\IDEA\SYSAUX01.DBF
input datafile file number=00009 name=E:\DATA\IDEA\USERS02.DBF
input datafile file number=00007 name=E:\DATA\IDEA\EXAMPLE02.DBF
input datafile file number=00008 name=E:\DATA\IDEA\EXAMPLE03.DBF
input datafile file number=00010 name=E:\DATA\IDEA\USERS03.DBF
input datafile file number=00005 name=E:\DATA\IDEA\EXAMPLE01.DBF
input datafile file number=00006 name=E:\DATA\IDEA\SYSTEM02.DBF
input datafile file number=00003 name=E:\DATA\IDEA\UNDOTBS01.DBF
input datafile file number=00004 name=E:\DATA\IDEA\USERS01.DBF
channel ORA_DISK_1: starting piece 1 at 03-JAN-13
channel ORA_DISK_1: finished piece 1 at 03-JAN-13
piece handle=C:\RMAN\IDEA_0TNUFTOB_1_1 tag=FULL_INC comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 03-JAN-13
Starting Control File and SPFILE Autobackup at 03-JAN-13
piece handle=C:\RMAN\C-1142773416-20130103-02 comment=NONE
Finished Control File and SPFILE Autobackup at 03-JAN-13
RMAN>

SQL> select * from v$log;
    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------
         1          1          1   52428800        512          1 YES INACTIVE               2107075 02-JAN-13      2136108 03-JAN-13
         2          1          2   52428800        512          1 NO  CURRENT                2136108 03-JAN-13   2.8147E+14
         3          1          0   52428800        512          1 YES UNUSED                       0              0

SQL>
SQL> select checkpoint_change# from v$database;

CHECKPOINT_CHANGE#
------------------
           2136108
SQL>

Now create a table and insert some values,

C:\Users\Admin\mahi>sqlplus

SQL*Plus: Release 11.2.0.1.0 Production on Thu Jan 3 10:42:58 2013

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

Enter user-name: hr/hr

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>  CREATE TABLE T1(C1 NUMBER);

Table created.

SQL> INSERT INTO T1 VALUES(1);

1 row created.

SQL> /

1 row created.

SQL> /

1 row created.

SQL> commit;

Commit complete.

SQL>

Now i took incremental level 1 backup and it is tagged as INC_1,

RMAN>  BACKUP INCREMENTAL LEVEL 1 DATABASE TAG 'INC_1';
Starting backup at 03-JAN-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=160 device type=DISK
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=E:\DATA\IDEA\SYSTEM01.DBF
input datafile file number=00002 name=E:\DATA\IDEA\SYSAUX01.DBF
input datafile file number=00009 name=E:\DATA\IDEA\USERS02.DBF
input datafile file number=00007 name=E:\DATA\IDEA\EXAMPLE02.DBF
input datafile file number=00008 name=E:\DATA\IDEA\EXAMPLE03.DBF
input datafile file number=00010 name=E:\DATA\IDEA\USERS03.DBF
input datafile file number=00005 name=E:\DATA\IDEA\EXAMPLE01.DBF
input datafile file number=00006 name=E:\DATA\IDEA\SYSTEM02.DBF
input datafile file number=00003 name=E:\DATA\IDEA\UNDOTBS01.DBF
input datafile file number=00004 name=E:\DATA\IDEA\USERS01.DBF
channel ORA_DISK_1: starting piece 1 at 03-JAN-13
channel ORA_DISK_1: finished piece 1 at 03-JAN-13
piece handle=C:\RMAN\IDEA_0VNUFU0U_1_1 tag=INC_1 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
Finished backup at 03-JAN-13
Starting Control File and SPFILE Autobackup at 03-JAN-13
piece handle=C:\RMAN\C-1142773416-20130103-03 comment=NONE
Finished Control File and SPFILE Autobackup at 03-JAN-13
RMAN>

C:\Users\Admin\mahi>sqlplus

SQL*Plus: Release 11.2.0.1.0 Production on Thu Jan 3 10:46:02 2013

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

Enter user-name: hr
Enter password:

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>  INSERT INTO T1 VALUES(2);

1 row created.

SQL> /

1 row created.

SQL> /

1 row created.

SQL> commit;

Commit complete.

SQL>

Now take incremental level 2 backup and it also tagged as INC_2,

RMAN> BACKUP INCREMENTAL LEVEL 2 DATABASE TAG 'INC_2';
Starting backup at 03-JAN-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=160 device type=DISK
channel ORA_DISK_1: starting incremental level 2 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=E:\DATA\IDEA\SYSTEM01.DBF
input datafile file number=00002 name=E:\DATA\IDEA\SYSAUX01.DBF
input datafile file number=00009 name=E:\DATA\IDEA\USERS02.DBF
input datafile file number=00007 name=E:\DATA\IDEA\EXAMPLE02.DBF
input datafile file number=00008 name=E:\DATA\IDEA\EXAMPLE03.DBF
input datafile file number=00010 name=E:\DATA\IDEA\USERS03.DBF
input datafile file number=00005 name=E:\DATA\IDEA\EXAMPLE01.DBF
input datafile file number=00006 name=E:\DATA\IDEA\SYSTEM02.DBF
input datafile file number=00003 name=E:\DATA\IDEA\UNDOTBS01.DBF
input datafile file number=00004 name=E:\DATA\IDEA\USERS01.DBF
channel ORA_DISK_1: starting piece 1 at 03-JAN-13
channel ORA_DISK_1: finished piece 1 at 03-JAN-13
piece handle=C:\RMAN\IDEA_11NUFU6A_1_1 tag=INC_2 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
Finished backup at 03-JAN-13
Starting Control File and SPFILE Autobackup at 03-JAN-13
piece handle=C:\RMAN\C-1142773416-20130103-04 comment=NONE
Finished Control File and SPFILE Autobackup at 03-JAN-13
RMAN>

C:\Users\Admin\mahi>sqlplus

SQL*Plus: Release 11.2.0.1.0 Production on Thu Jan 3 10:49:13 2013

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

Enter user-name: hr/hr

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> INSERT INTO T1 VALUES(3);

1 row created.

SQL> /

1 row created.

SQL> /

1 row created.

SQL> commit;

Commit complete.

SQL>  select * from v$log;
    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------
         1          1          1   52428800        512          1 YES INACTIVE               2107075 02-JAN-13      2136108 03-JAN-13
         2          1          2   52428800        512          1 NO  CURRENT                2136108 03-JAN-13   2.8147E+14
         3          1          0   52428800        512          1 YES UNUSED                       0              0

SQL>

SQL> select checkpoint_change# from v$database;

CHECKPOINT_CHANGE#
------------------
           2136108
SQL>
SQL> conn sys as sysdba
Enter password:
Connected.
SQL> shut abort;
ORACLE instance shut down.
SQL>

Here all the changes since the last backup has been stored in the redo logs. Now delete the controlfile ,

SQL> host del E:\data\idea\*.CTL

RMAN> startup;
Oracle instance started
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 01/03/2013 10:56:44
ORA-00205: error in identifying control file, check alert log for more info
RMAN>

RMAN> SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO  'C:\rman\%F';

executing command: SET CONTROLFILE AUTOBACKUP FORMAT

RMAN> RESTORE CONTROLFILE FROM AUTOBACKUP;

Starting restore at 03-JAN-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=156 device type=DISK
AUTOBACKUP search with format "C:\rman\%F" not attempted because DBID was not set
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 01/03/2013 10:57:59
RMAN-06172: no AUTOBACKUP found or specified handle is not a valid copy or piece

Take the dbid from controlfile autobackup,

RMAN> set DBID=1142773416

executing command: SET DBID

RMAN> RESTORE CONTROLFILE FROM AUTOBACKUP;
Starting restore at 03-JAN-13
using channel ORA_DISK_1
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20130103
channel ORA_DISK_1: AUTOBACKUP found: C:\rman\c-1142773416-20130103-04
channel ORA_DISK_1: restoring control file from AUTOBACKUP C:\rman\c-1142773416-20130103-04
channel ORA_DISK_1: control file restore from AUTOBACKUP complete
output file name=E:\DATA\IDEA\CONTROL01.CTL
output file name=E:\DATA\IDEA\CONTROL02.CTL
Finished restore at 03-JAN-13

RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1

RMAN> RESTORE DATABASE;
Starting restore at 03-JAN-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=156 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to E:\DATA\IDEA\SYSTEM01.DBF
channel ORA_DISK_1: restoring datafile 00002 to E:\DATA\IDEA\SYSAUX01.DBF
channel ORA_DISK_1: restoring datafile 00003 to E:\DATA\IDEA\UNDOTBS01.DBF
channel ORA_DISK_1: restoring datafile 00004 to E:\DATA\IDEA\USERS01.DBF
channel ORA_DISK_1: restoring datafile 00005 to E:\DATA\IDEA\EXAMPLE01.DBF
channel ORA_DISK_1: restoring datafile 00006 to E:\DATA\IDEA\SYSTEM02.DBF
channel ORA_DISK_1: restoring datafile 00007 to E:\DATA\IDEA\EXAMPLE02.DBF
channel ORA_DISK_1: restoring datafile 00008 to E:\DATA\IDEA\EXAMPLE03.DBF
channel ORA_DISK_1: restoring datafile 00009 to E:\DATA\IDEA\USERS02.DBF
channel ORA_DISK_1: restoring datafile 00010 to E:\DATA\IDEA\USERS03.DBF
channel ORA_DISK_1: reading from backup piece C:\RMAN\IDEA_0TNUFTOB_1_1
channel ORA_DISK_1: piece handle=C:\RMAN\IDEA_0TNUFTOB_1_1 tag=FULL_INC
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:55
Finished restore at 03-JAN-13
RMAN>

Note:- The database was restored using level 0 full backup tagged as FULL_INC

RMAN> RECOVER DATABASE;

Starting recover at 03-JAN-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: E:\DATA\IDEA\SYSTEM01.DBF
destination for restore of datafile 00002: E:\DATA\IDEA\SYSAUX01.DBF
destination for restore of datafile 00003: E:\DATA\IDEA\UNDOTBS01.DBF
destination for restore of datafile 00004: E:\DATA\IDEA\USERS01.DBF
destination for restore of datafile 00005: E:\DATA\IDEA\EXAMPLE01.DBF
destination for restore of datafile 00006: E:\DATA\IDEA\SYSTEM02.DBF
destination for restore of datafile 00007: E:\DATA\IDEA\EXAMPLE02.DBF
destination for restore of datafile 00008: E:\DATA\IDEA\EXAMPLE03.DBF
destination for restore of datafile 00009: E:\DATA\IDEA\USERS02.DBF
destination for restore of datafile 00010: E:\DATA\IDEA\USERS03.DBF
channel ORA_DISK_1: reading from backup piece C:\RMAN\IDEA_0VNUFU0U_1_1
channel ORA_DISK_1: piece handle=C:\RMAN\IDEA_0VNUFU0U_1_1 tag=INC_1
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: E:\DATA\IDEA\SYSTEM01.DBF
destination for restore of datafile 00002: E:\DATA\IDEA\SYSAUX01.DBF
destination for restore of datafile 00003: E:\DATA\IDEA\UNDOTBS01.DBF
destination for restore of datafile 00004: E:\DATA\IDEA\USERS01.DBF
destination for restore of datafile 00005: E:\DATA\IDEA\EXAMPLE01.DBF
destination for restore of datafile 00006: E:\DATA\IDEA\SYSTEM02.DBF
destination for restore of datafile 00007: E:\DATA\IDEA\EXAMPLE02.DBF
destination for restore of datafile 00008: E:\DATA\IDEA\EXAMPLE03.DBF
destination for restore of datafile 00009: E:\DATA\IDEA\USERS02.DBF
destination for restore of datafile 00010: E:\DATA\IDEA\USERS03.DBF
channel ORA_DISK_1: reading from backup piece C:\RMAN\IDEA_11NUFU6A_1_1
channel ORA_DISK_1: piece handle=C:\RMAN\IDEA_11NUFU6A_1_1 tag=INC_2
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03

starting media recovery

archived log for thread 1 with sequence 2 is already on disk as file E:\DATA\IDEA\REDO02.LOG
archived log file name=E:\DATA\IDEA\REDO02.LOG thread=1 sequence=2
media recovery complete, elapsed time: 00:00:01
Finished recover at 03-JAN-13

Note:- Watch the output carefully. You can recognise various backups that are being applied. Look for the tags that you have given to backupsets. It will applies all the incrementals one by one. First it will apply level 1 incremental, and then level 2. Then it will search for appropriate log sequence and applies the same if found.

RMAN>  ALTER DATABASE OPEN RESETLOGS;

database opened

RMAN> exit

Recovery Manager complete.

C:\Users\Admin\mahi>sqlplus hr/hr

SQL*Plus: Release 11.2.0.1.0 Production on Thu Jan 3 11:03:39 2013

Copyright (c) 1982, 2010, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select * from t1;

        C1
----------
         2
         2
         2
         3
         3
         3
         1
         1
         1

9 rows selected.

Hope its helps to somebody.. :)



SQL>

No comments:

Post a Comment