This feature is available from Oracle 10g onwards. This is a very nice feature that can reduce the time of the recovery to a great extent.
Image copies are not new to Oracle but recoverable copies are for sure.
In Oracle there are generally two types of backups available
a) Full database backups. (Level 0 backups)
b) Incremental backups (eg Level 1 backups)
For having incremental backups, we need to have a full backup of the database. Once we have full backup of the database, we can have incremental backups after that reducing the amount of time and space involved in the backup operation.
So, whats new with the “Recoverable Image Copies”?
This is a feature in which image copies of the database file will be getting updated with the new changes in the database using Incremental backups.
As we know that image copies are same as our datafiles and same as we take a copy of datafile using Os command with only difference is that they are in RMAN format so better managed by Oracle.
SO coming to the feature, if you take a image copy of say datafile 3 today and there is an incremental backup occurring every day, now you are having an option to update the datafile 3 copy with latest changes that have happened in database using the latest incremental backup.
Lets do a small demo explaining this feature..
Brief description about the demo
I will create a tablespace and will create a table in that tablespace. We will then have a full database backup and an image copy of the database which will also include the new tablespace.
Then we will make changes to the newly created table and have an incremental backup capturing those changes.
We will update the image copy taken in the step 1 using the incremental backups.
Then we will be dropping the datafile of the new tablespace and will perform a recovery of that datafile using the image copy.
So here we start….
- Start with creating a new tablespace say “test_tb” with one datafile.
[code]
Enter user-name: / as sysdba
Connected to:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 – Production
With the Partitioning, OLAP and Data Mining options
SQL> select name from v$tablespace;
NAME
——————————
SYSTEM
UNDOTBS1
SYSAUX
USERS
TEMP
APEX
FLOW_1050410553792418
7 rows selected.
SQL> select name from v$datafile;
NAME
——————————————————————————–
D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF
D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DBF
D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF
D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF
D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\APEX01.DBF
D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\FLOW_1050410553792418.DBF
6 rows selected.
SQL> create tablespace test_tb datafile ‘D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\test_tb01.dbf’ size 100m;
Tablespace created.
Now we will create a table in this newly creates tablespace
SQL> create table emp_test tablespace test_tb as select * from scott.emp;
Table created.
SQL> select count(*) from emp_test;
COUNT(*)
———-
14
[/code]
- Now we will take a full database backup using new backup command.
[code]
RMAN> backup incremental level 1 for recover of copy tag ‘test_tb_incr’ database;
Starting backup at 10-SEP-10
using channel ORA_DISK_1
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 2 found
no parent backup or copy of datafile 5 found
no parent backup or copy of datafile 6 found
no parent backup or copy of datafile 7 found
no parent backup or copy of datafile 4 found
channel ORA_DISK_1: starting datafile copy
input datafile fno=00001:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF
output filename=D:\ORACLE\BACKUP\ORCL_3_DATA_D-ORCL_I-1252589722_TS-SYSTEM_FNO-1_03LNHQV3.BAK tag=TEST_TB_INCR recid=1 stamp=729345025
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile copy
input datafile fno=00003:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF
output filename=D:\ORACLE\BACKUP\ORCL_4_DATA_D-ORCL_I-1252589722_TS-SYSAUX_FNO-3_04LNHR06.BAK tag=TEST_TB_INCR recid=2 stamp=729345049
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile fno=00002:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DBF
output filename=D:\ORACLE\BACKUP\ORCL_5_DATA_D-ORCL_I-1252589722_TS-UNDOTBS1_FNO-2_05LNHR0V.BAK tag=TEST_TB_INCR recid=3 stamp=729345065
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile fno=00005:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\APEX01.DBF
output filename=D:\ORACLE\BACKUP\ORCL_6_DATA_D-ORCL_I-1252589722_TS-APEX_FNO-5_06LNHR1E.BAK tag=TEST_TB_INCR recid=4 stamp=729345079
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile fno=00006:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\FLOW_1050410553792418.DBF
output filename=D:\ORACLE\BACKUP\ORCL_7_DATA_D-ORCL_I-1252589722_TS-FLOW_1050410553792418_FNO-6_07LNHR1T.BAK tag=TEST_TB_INCR recid=5 stamp=729345090
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:08
channel ORA_DISK_1: starting datafile copy
input datafile fno=00007:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEST_TB01.DBF
output filename=D:\ORACLE\BACKUP\ORCL_8_DATA_D-ORCL_I-1252589722_TS-TEST_TB_FNO-7_08LNHR25.BAK tag=TEST_TB_INCR recid=6 stamp=729345098
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile fno=00004:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF
output filename=D:\ORACLE\BACKUP\ORCL_9_DATA_D-ORCL_I-1252589722_TS-USERS_FNO-4_09LNHR2C.BAK tag=TEST_TB_INCR recid=7 stamp=729345100
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting incremental level 1 datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 10-SEP-10
channel ORA_DISK_1: finished piece 1 at 10-SEP-10
piece handle=D:\ORACLE\BACKUP\ORCL_10_0ALNHR2D_1_1.BAK tag=TEST_TB_INCR comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 10-SEP-10
RMAN> list backup of database;
RMAN> list backup
2> ;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— —————
3 Incr 1 6.89M DISK 00:00:02 10-SEP-10
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TEST_TB_INCR
Piece Name: D:\ORACLE\BACKUP\ORCL_10_0ALNHR2D_1_1.BAK
Control File Included: Ckp SCN: 4036645 Ckp time: 10-SEP-10
SPFILE Included: Modification time: 10-SEP-10
[/code]
PS: We have not used the conventional “Backup database command this time instead we are using “Backup incremental level 1 for recover as copy tag…”, when we also don’t have any full database backup.
So when we don’t have any level 0 (full backup), this command will take a Level 0 (full backup) this time and also image copies for all the datafiles will be created. But from next time, incremental backups will be created but image copies will not be created.
- Check the database copies.
[code]
RMAN> list copy of tablespace test_tb;
List of Datafile Copies
Key File S Completion Time Ckp SCN Ckp Time Name
——- —- – ————— ———- ————— —-
6 7 A 10-SEP-10 4036634 10-SEP-10 D:\ORACLE\BACKUP\ORCL_8_DATA_D-ORCL_I-1252589722_TS-TEST_TB_FNO-7_08LNHR25.BAK
[/code]
Image copies created for all the datafile but I just displayed for tablespace we are taking in demo.
- No we will insert some more data into the table (emp_test) to test the scenario.
[code]
SQL> insert into emp_test select * from emp_test;
14 rows created.
SQL> /
28 rows created.
SQL> /
.
.
.
56 rows created.
SQL> /
7168 rows created.
SQL> /
14336 rows created.
SQL> /
28672 rows created.
SQL> /
57344 rows created.
SQL> commit;
Commit complete.
SQL> select count(*) from emp_test;
COUNT(*)
———-
114688
[/code]
So we have added quite number of rows in the table.
- Now we will run the incremental backup once again.
[code]
RMAN> backup incremental level 1 for recover of copy tag ‘test_tb_incr’ database;
Starting backup at 10-SEP-10
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF
input datafile fno=00003:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF
input datafile fno=00002:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DBF
input datafile fno=00005:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\APEX01.DBF
input datafile fno=00006:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\FLOW_1050410553792418.DBF
input datafile fno=00007:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEST_TB01.DBF
input datafile fno=00004:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF
channel ORA_DISK_1: starting piece 1 at 10-SEP-10
channel ORA_DISK_1: finished piece 1 at 10-SEP-10
piece handle=D:\ORACLE\BACKUP\ORCL_11_0BLNHRAU_1_1.BAK tag=TEST_TB_INCR comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting incremental level 1 datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 10-SEP-10
channel ORA_DISK_1: finished piece 1 at 10-SEP-10
piece handle=D:\ORACLE\BACKUP\ORCL_12_0CLNHRC1_1_1.BAK tag=TEST_TB_INCR comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 10-SEP-10
RMAN> list backup;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— —————
3 Incr 1 6.89M DISK 00:00:02 10-SEP-10
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TEST_TB_INCR
Piece Name: D:\ORACLE\BACKUP\ORCL_10_0ALNHR2D_1_1.BAK
Control File Included: Ckp SCN: 4036645 Ckp time: 10-SEP-10
SPFILE Included: Modification time: 10-SEP-10
BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— —————
4 Incr 1 6.55M DISK 00:00:26 10-SEP-10
BP Key: 4 Status: AVAILABLE Compressed: NO Tag: TEST_TB_INCR
Piece Name: D:\ORACLE\BACKUP\ORCL_11_0BLNHRAU_1_1.BAK
List of Datafiles in backup set 4
File LV Type Ckp SCN Ckp Time Name
—- — —- ———- ——— —-
1 1 Incr 4037059 10-SEP-10 D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF
2 1 Incr 4037059 10-SEP-10 D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DBF
3 1 Incr 4037059 10-SEP-10 D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF
4 1 Incr 4037059 10-SEP-10 D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF
5 1 Incr 4037059 10-SEP-10 D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\APEX01.DBF
6 1 Incr 4037059 10-SEP-10 D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\FLOW_1050410553792418.DBF
7 1 Incr 4037059 10-SEP-10 D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEST_TB01.DBF
BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— —————
5 Incr 1 6.89M DISK 00:00:02 10-SEP-10
BP Key: 5 Status: AVAILABLE Compressed: NO Tag: TEST_TB_INCR
Piece Name: D:\ORACLE\BACKUP\ORCL_12_0CLNHRC1_1_1.BAK
Control File Included: Ckp SCN: 4037083 Ckp time: 10-SEP-10
SPFILE Included: Modification time: 10-SEP-10
[/code]
So we have done incremental backup now.
- Now we will check the Checkpoint SCN for tablespace “test_tb” in the backupset and in the image copy.
[code]</strong>
RMAN> list backup of tablespace test_tb;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— —————
4 Incr 1 6.55M DISK 00:00:26 10-SEP-10
BP Key: 4 Status: AVAILABLE Compressed: NO Tag: TEST_TB_INCR
Piece Name: D:\ORACLE\BACKUP\ORCL_11_0BLNHRAU_1_1.BAK
List of Datafiles in backup set 4
File LV Type Ckp SCN Ckp Time Name
—- — —- ———- ——— —-
7 1 Incr 4037059 10-SEP-10 D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEST_TB01.DBF
RMAN> list copy of tablespace test_tb;
List of Datafile Copies
Key File S Completion Time Ckp SCN Ckp Time Name
——- —- – ————— ———- ————— —-
6 7 A 10-SEP-10 4036634 10-SEP-10 D:\ORACLE\BACKUP\ORCL_8_DATA_D-ORCL_I-1252589722_TS-TEST_TB_FNO-7_08LNHR25.BAK
[/code]
Now notice that, checkpoint SCN of tablespace “test_tb’ is 4037059 in the incremental backup which is higher than 4036634 in the image copy as I indicated in red.
So it suggests that image copy needs to be updated to make it in updated till time of incremental backup.
- Now we will update the image copy by applying the incremental backups to it to bring it to the current SCN of the tablespace as stored in incremental backup.
[code]</strong>
RMAN> recover copy of tablespace test_tb with tag ‘test_tb_incr’;
Starting recover at 10-SEP-10
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental datafile backupset restore
channel ORA_DISK_1: specifying datafile copies to recover
recovering datafile copy fno=00007:\ORACLE\BACKUP\ORCL_8_DATA_D-ORCL_I-1252589722_TS-TEST_TB_FNO-7_08LNHR25.BAK
channel ORA_DISK_1: reading from backup piece D:\ORACLE\BACKUP\ORCL_11_0BLNHRAU_1_1.BAK
channel ORA_DISK_1: restored backup piece 1
piece handle=D:\ORACLE\BACKUP\ORCL_11_0BLNHRAU_1_1.BAK tag=TEST_TB_INCR
channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
Finished recover at 10-SEP-10
[/code]
One thing to keep in mind is that tag in this scenario is very important.
- Now check the SCN number again.
[code]
RMAN> list backup of tablespace test_tb;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— —————
4 Incr 1 6.55M DISK 00:00:26 10-SEP-10
BP Key: 4 Status: AVAILABLE Compressed: NO Tag: TEST_TB_INCR
Piece Name: D:\ORACLE\BACKUP\ORCL_11_0BLNHRAU_1_1.BAK
List of Datafiles in backup set 4
File LV Type Ckp SCN Ckp Time Name
—- — —- ———- ——— —-
7 1 Incr 4037059 10-SEP-10 D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEST_TB01.DBF
RMAN> list copy of tablespace test_tb;
List of Datafile Copies
Key File S Completion Time Ckp SCN Ckp Time Name
——- —- – ————— ———- ————— —-
8 7 A 10-SEP-10 4037059 10-SEP-10 D:\ORACLE\BACKUP\ORCL_8_DATA_D-ORCL_I-1252589722_TS-TEST_TB_FNO-7_08LNHR25.BAK
RMAN> exit
[/code]
So it shows that now SCN number is same in image copy and incremental backup..
Now, when we are done with the image update, time is to test the usage of these image copies……..
What we are going to do is drop the datafile of that tablespace “test_tb”..
Lets go…
As I am testing it on windows environment, to drop a file I need to shutdown the database first…as windows will not allow changing/dropping file while its being used by some other program…
- So I started with shutting down my database…
[code]
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
Then using the OS command I dropped the datafile.
Startup the database.
SQL> startup
ORACLE instance started.
Total System Global Area 612368384 bytes
Fixed Size 1250428 bytes
Variable Size 171969412 bytes
Database Buffers 432013312 bytes
Redo Buffers 7135232 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 7 – see DBWR trace file
ORA-01110: data file 7: ‘D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEST_TB01.DBF’
As expected, I got the error about the datafile 7.
So I made it offline for once and opened the database.
SQL> alter database datafile 7 offline;
Database altered.
SQL> alter database open;
Database altered.
SQL> select count(*) from emp_test;
select count(*) from emp_test
*
ERROR at line 1:
ORA-00376: file 7 cannot be read at this time
ORA-01110: data file 7: ‘D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEST_TB01.DBF’
<span id="_marker">[/code]
- Now the time is to restore the datafile using RMAN.
Here comes an interesting fact/benefit of “Recoverable Image copies”. In any previous release we would have required to restore the datafile from the backup to the original location and then recovered that file…BUT in this case we can simply change the controlfile pointer pointing to the datafile 7 from current location to the location where Image copy for datafile 7 is place…using RMAN switch command…
[code]
RMAN> report schema;
using target database control file instead of recovery catalog
Report of database schema
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
—- ——– ——————– ——- ————————
1 590 SYSTEM *** D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF
2 180 UNDOTBS1 *** D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DBF
3 360 SYSAUX *** D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF
4 5 USERS *** D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF
5 155 APEX *** D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\APEX01.DBF
6 100 FLOW_1050410553792418 *** D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\FLOW_1050410553792418.DBF
7 0 TEST_TB *** D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEST_TB01.DBF
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
—- ——– ——————– ———– ——————–
1 20 TEMP 32767 D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEMP01.DBF
RMAN> switch datafile 7 to copy;
datafile 7 switched to datafile copy "D:\ORACLE\BACKUP\ORCL_8_DATA_D-ORCL_I-1252589722_TS-TEST_TB_FNO-7_08LNHR25.BAK"
RMAN> report schema;
Report of database schema
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
—- ——– ——————– ——- ————————
1 590 SYSTEM *** D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF
2 180 UNDOTBS1 *** D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DBF
3 360 SYSAUX *** D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF
4 5 USERS *** D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF
5 155 APEX *** D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\APEX01.DBF
6 100 FLOW_1050410553792418 *** D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\FLOW_1050410553792418.DBF
7 100 TEST_TB *** D:\ORACLE\BACKUP\ORCL_8_DATA_D-ORCL_I-1252589722_TS-TEST_TB_FNO-7_08LNHR25.BAK
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
—- ——– ——————– ———– ——————–
1 20 TEMP 32767 D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEMP01.DBF
Now recover the datafile.
RMAN> recover datafile 7;
Starting recover at 10-SEP-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=130 devtype=DISK
starting media recovery
media recovery complete, elapsed time: 00:00:05
Finished recover at 10-SEP-10
Now bring the datafile online and test the results from the table.
SQL> alter database datafile 7 online;
Database altered.
SQL> select name from v$datafile;
NAME
——————————————————————————–
D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF
D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DBF
D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF
D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF
D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\APEX01.DBF
D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\FLOW_1050410553792418.DBF
D:\ORACLE\BACKUP\ORCL_8_DATA_D-ORCL_I-1252589722_TS-TEST_TB_FNO-7_08LNHR25.BAK
7 rows selected.
SQL> select count(*) from emp_test;
COUNT(*)
———-
114688
[/code]
So as expected we have recovered the tablespace using the Image Copy.
Thank you so much for this precious informations.