07 February, 2013

Backup and Recovery with intermediate NOARCHIVELOG

In a recent forums post, there was a question about whether one can taken an L0 backup, then switch the database to NOARCHIVELOG mode for transactions, switch back to ARCHIVELOG mode and take an L1 backup.  The query being whether the L0 and L1 backups could be used for a Recovery.

Here, I take an L0 backup :

[oracle@linux64 ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Thu Feb 7 21:30:18 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1229390655)

RMAN> backup database plus archivelog;


Starting backup at 07-FEB-13
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=196 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=25 RECID=57 STAMP=806794196
input archived log thread=1 sequence=26 RECID=58 STAMP=806794237
channel ORA_DISK_1: starting piece 1 at 07-FEB-13
channel ORA_DISK_1: finished piece 1 at 07-FEB-13
piece handle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2013_02_07/o1_mf_annnn_TAG20130207T213038_8k7c3y83_.bkp tag=TAG20130207T213038 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-FEB-13

Starting backup at 07-FEB-13
using channel ORA_DISK_1
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=/home/oracle/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00014 name=/oradata/orcl/add_tbs_01.dbf
input datafile file number=00015 name=/oradata/orcl/add_tbs_02.dbf
input datafile file number=00001 name=/home/oracle/app/oracle/oradata/orcl/system01.dbf
input datafile file number=00003 name=/home/oracle/app/oracle/oradata/orcl/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 07-FEB-13
...
...
...
Starting backup at 07-FEB-13
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=27 RECID=59 STAMP=806794355
channel ORA_DISK_1: starting piece 1 at 07-FEB-13
channel ORA_DISK_1: finished piece 1 at 07-FEB-13
piece handle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2013_02_07/o1_mf_annnn_TAG20130207T213235_8k7c7n08_.bkp tag=TAG20130207T213235 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-FEB-13

Starting Control File Autobackup at 07-FEB-13
piece handle=/home/oracle/app/oracle/flash_recovery_area/ORCL/autobackup/2013_02_07/o1_mf_n_806794357_8k7c7ofw_.bkp comment=NONE
Finished Control File Autobackup at 07-FEB-13

RMAN> 
Next, I take the database into NOARCHIVELOG mode and run some transactions.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  313860096 bytes
Fixed Size                  1336232 bytes
Variable Size             281021528 bytes
Database Buffers           25165824 bytes
Redo Buffers                6336512 bytes
Database mounted.
SQL> alter database noarchivelog;

Database altered.

SQL> alter database open;

Database altered.

SQL> 
SQL> connect hemant/hemant
Connected.
SQL> create table xyzabc as select * from dba_objects;

Table created.

SQL> alter system switch logfile;

System altered.

SQL> insert into xyzabc select * from xyzabc;

76637 rows created.

SQL> /

153274 rows created.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> delete xyzabc;

306548 rows deleted.

SQL> alter system switch logfile;

System altered.

SQL> rollback;

Rollback complete.

SQL> alter system switch logfile;

System altered.

SQL> 
I have forced multiple log switches to ensure that the online redo log files would not be sufficient for a Recovery.

I now switch the database back to ARCHIVELOG mode.

SQL> connect / as sysdba
Connected.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  313860096 bytes
Fixed Size                  1336232 bytes
Variable Size             281021528 bytes
Database Buffers           25165824 bytes
Redo Buffers                6336512 bytes
Database mounted.
SQL> alter database archivelog;

Database altered.

SQL> alter database open;

Database altered.

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     35
Next log sequence to archive   37
Current log sequence           37
SQL> 
The last ArchiveLog that I had backed up with the database was SEQUENCE#27. The oldest Online Redo Log is now SEQUENCE#35. All the intermediate Redo/ArchiveLogs are "lost". I now run an Incremental Backup.
[oracle@linux64 ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Thu Feb 7 21:42:25 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1229390655)

RMAN> backup incremental level 1 cumulative database;

Starting backup at 07-FEB-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=67 device type=DISK
no parent backup or copy of datafile 2 found
no parent backup or copy of datafile 1 found
no parent backup or copy of datafile 3 found
no parent backup or copy of datafile 4 found
no parent backup or copy of datafile 5 found
channel ORA_DISK_1: starting incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set

Oracle has smartly switched to a Level0 backup -- a full backup ! Question : What gives ? Why cannot I take an Incremental Backup ?
.
.
.


UPDATE : 
Re-running the scenario with a slight change :

[oracle@linux64 ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Fri Feb 8 23:41:40 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1229390655)

RMAN> backup incremental level 0 database plus archivelog;


Starting backup at 08-FEB-13
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=195 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=38 RECID=61 STAMP=806801256
input archived log thread=1 sequence=39 RECID=62 STAMP=806888537
channel ORA_DISK_1: starting piece 1 at 08-FEB-13
channel ORA_DISK_1: finished piece 1 at 08-FEB-13
piece handle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2013_02_08/o1_mf_annnn_TAG20130208T234218_8kb76v9g_.bkp tag=TAG20130208T234218 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 08-FEB-13

Starting backup at 08-FEB-13
using channel ORA_DISK_1
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=00002 name=/home/oracle/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00014 name=/oradata/orcl/add_tbs_01.dbf
input datafile file number=00015 name=/oradata/orcl/add_tbs_02.dbf
input datafile file number=00001 name=/home/oracle/app/oracle/oradata/orcl/system01.dbf
input datafile file number=00003 name=/home/oracle/app/oracle/oradata/orcl/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 08-FEB-13
...
...
...
Starting backup at 08-FEB-13
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=40 RECID=63 STAMP=806888681
channel ORA_DISK_1: starting piece 1 at 08-FEB-13
channel ORA_DISK_1: finished piece 1 at 08-FEB-13
piece handle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2013_02_08/o1_mf_annnn_TAG20130208T234442_8kb7cb6c_.bkp tag=TAG20130208T234442 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 08-FEB-13

Starting Control File Autobackup at 08-FEB-13
piece handle=/home/oracle/app/oracle/flash_recovery_area/ORCL/autobackup/2013_02_08/o1_mf_n_806888683_8kb7cdk7_.bkp comment=NONE
Finished Control File Autobackup at 08-FEB-13

RMAN> 



SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  313860096 bytes
Fixed Size                  1336232 bytes
Variable Size             281021528 bytes
Database Buffers           25165824 bytes
Redo Buffers                6336512 bytes
Database mounted.
SQL> alter database noarchivelog;

Database altered.

SQL> alter database open;

Database altered.

SQL> 

SQL> connect hemant/hemant
Connected.
SQL> drop table xyzabc;

Table dropped.

SQL> create table xyzabc as select * from dba_objects;

Table created.

SQL> alter system switch logfile;

System altered.

SQL> insert into xyzabc select * from xyzabc;

76637 rows created.

SQL> /

153274 rows created.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> delete xyzabc;

306548 rows deleted.

SQL> alter system switch logfile;

System altered.

SQL> rollback;

Rollback complete.

SQL> alter system switch logfile;

System altered.

SQL> 

SQL> connect / as sysdba
Connected.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  313860096 bytes
Fixed Size                  1336232 bytes
Variable Size             281021528 bytes
Database Buffers           25165824 bytes
Redo Buffers                6336512 bytes
Database mounted.
SQL> alter database archivelog;

Database altered.

SQL> alter database open;

Database altered.

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     48
Next log sequence to archive   50
Current log sequence           50
SQL> 


[oracle@linux64 ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Fri Feb 8 23:51:03 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1229390655)

RMAN> backup incremental level 1 database;

Starting backup at 08-FEB-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=67 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=00002 name=/home/oracle/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00014 name=/oradata/orcl/add_tbs_01.dbf
input datafile file number=00015 name=/oradata/orcl/add_tbs_02.dbf
input datafile file number=00001 name=/home/oracle/app/oracle/oradata/orcl/system01.dbf
input datafile file number=00003 name=/home/oracle/app/oracle/oradata/orcl/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 08-FEB-13
...
...
...
Starting Control File Autobackup at 08-FEB-13
piece handle=/home/oracle/app/oracle/flash_recovery_area/ORCL/autobackup/2013_02_08/o1_mf_n_806889118_8kb7rys6_.bkp comment=NONE
Finished Control File Autobackup at 08-FEB-13

RMAN> sql 'alter system archive log current';

sql statement: alter system archive log current

RMAN> backup archivelog all;

Starting backup at 09-FEB-13
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=38 RECID=61 STAMP=806801256
input archived log thread=1 sequence=39 RECID=62 STAMP=806888537
input archived log thread=1 sequence=40 RECID=63 STAMP=806888681
input archived log thread=1 sequence=50 RECID=64 STAMP=806890242
input archived log thread=1 sequence=51 RECID=65 STAMP=806890246
channel ORA_DISK_1: starting piece 1 at 09-FEB-13
channel ORA_DISK_1: finished piece 1 at 09-FEB-13
piece handle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2013_02_09/o1_mf_annnn_TAG20130209T001046_8kb8w6jp_.bkp tag=TAG20130209T001046 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 09-FEB-13

Starting Control File Autobackup at 09-FEB-13
piece handle=/home/oracle/app/oracle/flash_recovery_area/ORCL/autobackup/2013_02_09/o1_mf_n_806890247_8kb8w7pv_.bkp comment=NONE
Finished Control File Autobackup at 09-FEB-13

RMAN> 
This time, I *am* able to take a Level 1 Incremental Backup. The difference : In the first run, although I began by saying that I took an L0 backup, what I did was a Full Backup. In the second run, I did start with an L0 backup. Oracle does not recognise a Full Backup as a backup that can be the base for an L1 backup. !

7 comments:

Narendra said...

Hemant,

Nice scenario. Never thought somebody would be doing this.
I am not sure how to provide technical evidance (like SCNs and etc.) but my understanding is when you ask for an incremental level 1 backup, the database verifies whether there exists a valid level 0 backup AND whether that level 0 backup, combined with all archived logs available, can be used to, say, restore/recover DB at any point in time from when level 0 was taken till date. In this case, while DB finds a level 0 backup, it can not use it to restore/recover to any point in time when the DB was in NOARCHIVED log mode. Hence it goes for a level 0 backup.
Makes any sense at all?

Emre Baransel said...

I guess incarnation changes when archived loge mode is disabled.

Unknown said...

didn't mention incremental level 0 in first command
RMAN> backup database plus archivelog;

Anonymous said...

Hi Hemant,
Back to the definition of inxremental backups are backups taken on blocks that have been modified since the last backup.
How Oracle knows about modified blocks without redo information?

Wissem said...

Backup to the definition of incremental backups: There are backups that are taken on blocks that have been modified since the last backup and Cumulative incremental backups include all blocks that were changed since the last backup at a lower level.
You have lost all redo information by running enough transactions and thus Oracle can't have changed blocks since last level 0. If you have simply list of changed blocks, then Oracle will run incremental level 1 without issues.

Hope it is true :)
Wissem

Suresh said...

A level 0 incremental backup is physically identical to a full backup. The only difference is that the level 0 backup is recorded as an incremental backup in the RMAN repository, so it can be used as the parent for a level 1 backup.

As you have used backup database plus archivelog instead of backup incremental level 0 database. Thats why rman is unable to find the parent backup

-Thanks
Suresh

Hemant K Chitale said...

All : See the update on 08-Feb.

Oracle does not treat a BACKUP [FULL] DATABASE as a base from which it can take L1 Backups.


Hemant K Chitale