Some oracle customers use SAN based technologies to keep a backup copy of the database in sync (Think EMC Timefinder and BCV’s). The typical backup strategy tends to be, to keep a full copy of the database, and on a daily basis to update this backup copy of the database (Typically a BCV synchronize operation), with only the incremental changes that have happened at the disk level.
In case off a loss of file system in the primary disks, they can switch the database to run from another copy which is maintained as a backup by the Storage subsystem.
A similar strategy can be implemented for oracle databases, using RMAN incrementally updated backups (Without requiring any expensive SAN level software for maintaining these copies). These backup copies can be updated on a daily basis using just the incremental changes in the database. In case of a loss in the database, you can switch to this copy to be used as the database. You can also generate clones from these backups using the rman duplicate command.
At a high level the steps involved are
- Configure the database to run in archivelog mode
- Configure block change tracking at the database level
- Create a level 0 full image copy of the database using rman
- Create level 1 incremental backups of the database and update the level 0 copy with this incremental backup
- In case of need, use the rman switch command to switch the database to this incrementally updated backup.
Below is an example of how this is done.
Enable Archivelog and Block Change Tracking
sqlplus / as sysdbastartup mount;alter database archivelog;alter system set log_archive_dest_1=’LOCATION=/u01/orarch/rk01′ scope=spfile;alter database open;ALTER DATABASE ENABLE BLOCK CHANGE TRACKINGUSING FILE ‘/u01/orarch/rk01/rman/rman_change_track.f’ REUSE;
Run a level 0 full image copy backup of the database.
#!/bin/bashrman target=”sys/manager@rk01″ log=/u01/oraback/fullcopy.log << EOFRUN {ALLOCATE CHANNEL ch1 TYPEDISK FORMAT ‘/u01/oraback/%b’;BACKUP INCREMENTAL LEVEL 0 as copy DATABASE TAG ‘fullcopy’;RELEASE CHANNEL ch1;}RUN {ALLOCATE CHANNEL ch1 TYPEDISK FORMAT ‘/u01/oraback/%U’;BACKUP as copy ARCHIVELOG ALL;BACKUP as copy CURRENT CONTROLFILE;RELEASE CHANNEL ch1;}EXIT;EOF
Now perform some updates in the database. (This simulates database changes, after which we can run an incremental backup).
#!/bin/bashsqlplus hr/hr@rk01 <<EOCset echo on;select employee_id,first_name,last_name fromemployeeswhereemployee_id = 194/update employees set last_name=’Adams’whereemployee_id=194/select employee_id,first_name,last_name fromemployeeswhereemployee_id = 194/EOC
Now perform an incremental level 1 backup of the database
#!/bin/bashrman target=”sys/manager@rk01″ log=/u01/oraback/incr.log << EOFRUN {ALLOCATE CHANNEL ch1 TYPEDISK FORMAT ‘/u01/oraback/%U’;BACKUPINCREMENTAL LEVEL 1FOR RECOVER OF COPY WITH TAG ‘fullcopy’DATABASE;RELEASE CHANNEL ch1;}EXIT;EOF
Now Apply the incremental backup to the original level 0 image copy
#!/bin/bashrman target=”sys/manager@rk01″ log=/u01/oraback/incrapply.log << EOFRUN {ALLOCATE CHANNEL ch1 TYPEDISK FORMAT ‘/u01/oraback/%U’;RECOVER COPY OF DATABASE WITH TAG ‘fullcopy’;RELEASE CHANNEL ch1;}EXIT;EOF
SQL> select file_name from dba_data_files;FILE_NAME——————————————————————————–/u01/oradata/rk01/users01.dbf/u01/oradata/rk01/undotbs01.dbf/u01/oradata/rk01/sysaux01.dbf/u01/oradata/rk01/system01.dbf/u01/oradata/rk01/example01.dbf
Now switch the database to run from the copy
oracle@rramads-us2:~$ rman target /Recovery Manager: Release 11.2.0.2.0 – Production on Sat Nov 6 17:44:40 2010Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: RK01 (DBID=2035601811, not open)RMAN> switch database to copy;using target database control file instead of recovery catalogdatafile 1 switched to datafile copy “/u01/oraback/system01.dbf”datafile 2 switched to datafile copy “/u01/oraback/sysaux01.dbf”datafile 3 switched to datafile copy “/u01/oraback/undotbs01.dbf”datafile 4 switched to datafile copy “/u01/oraback/users01.dbf”datafile 5 switched to datafile copy “/u01/oraback/example01.dbf”RMAN> recover database;Starting recover at 06-NOV-10allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=133 device type=DISKchannel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setdestination for restore of datafile 00001: /u01/oraback/system01.dbfdestination for restore of datafile 00002: /u01/oraback/sysaux01.dbfdestination for restore of datafile 00003: /u01/oraback/undotbs01.dbfdestination for restore of datafile 00004: /u01/oraback/users01.dbfdestination for restore of datafile 00005: /u01/oraback/example01.dbfchannel ORA_DISK_1: reading from backup piece /u01/oraback/14lsbd4b_1_1channel ORA_DISK_1: piece handle=/u01/oraback/14lsbd4b_1_1 tag=FULLCOPYchannel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:00:07starting media recoverymedia recovery complete, elapsed time: 00:00:01Finished recover at 06-NOV-10RMAN> alter database open;database opened
SQL> select file_name from dba_data_files;FILE_NAME——————————————————————————–/u01/oraback/users01.dbf/u01/oraback/undotbs01.dbf/u01/oraback/sysaux01.dbf/u01/oraback/system01.dbf/u01/oraback/example01.dbfCheck if the changes we made to the hr.employees table are still there (To ensure that the incremental backup did work).SQL> select last_name from hr.employees where employee_id = 194;LAST_NAME————————-Adams