viernes, 25 de septiembre de 2009

RMAN Performing Complete Recovery

VERIFICAR EL ESTADO DE LA INSTANCIA

Oracle would determine whether crash recovery is required:

SELECT
a.thread#, b.open_mode, a.status,
CASE
WHEN ((b.open_mode='MOUNTED') AND (a.status='OPEN')) THEN 'Crash Recovery req.'
WHEN ((b.open_mode='MOUNTED') AND (a.status='CLOSED')) THEN 'No Crash Rec. req.'
WHEN ((b.open_mode='READ WRITE') AND (a.status='OPEN')) THEN 'Inst. already open'
ELSE 'huh?'
END STATUS
FROM v$thread a,
v$database b,
v$instance c
WHERE a.thread# = c.thread#
/

THREAD# OPEN_MODE STATUS STATUS
---------- ---------- ------ --------------------------------
1 READ WRITE OPEN Inst. already open

The following SQL query demonstrates the internal checks that Oracle performs to determine
whether media recovery is required:


SELECT
a.name,
a.checkpoint_change#,
b.checkpoint_change#,
CASE
WHEN ((a.checkpoint_change# - b.checkpoint_change#) = 0) THEN 'Startup Normal'
WHEN ((a.checkpoint_change# - b.checkpoint_change#) > 0) THEN 'Media Recovery'
WHEN ((a.checkpoint_change# - b.checkpoint_change#) < 0) THEN 'Old Control File'
ELSE 'what the ?'
END STATUS
FROM v$datafile a, -- control file SCN for datafile
v$datafile_header b -- datafile header SCN
WHERE a.file# = b.file#;


RMAN> startup mount;
RMAN> restore database until time
2> "to_date('05-oct-2006 14:00:00', dd-mon-rrrr hh24:mi:ss')";
RMAN> recover database;
RMAN> alter database open;
RMAN> recover database;
RMAN> alter database open;




Determining How to Restore and Recover

RMAN> connect target /
RMAN> startup;
ORA-01157: cannot identify/lock data file 4 – see DBWR trace file
ORA-01110: data file 4: 'C:\ORACLE\BRDSTN\USERS01.DBF'
Errors in file c:\oracle\product\10.2.0\admin\orcl\bdump\orcl_dbw0_5416.trc:
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: 'C:\ORACLE\BRDSTN\USERS01.DBF'
ORA-27041: unable to open file
OSD-04002: unable to open file
O/S-Error: (OS 2) The system cannot find the file specified.

Validar the datafile headers and reports in the ERROR

SQL> select file#, status, error,recover from v$datafile_header;


The V$RECOVER_FILE reads from the control file and displays information about files
needing media recovery:

SQL> select file#, error from v$recover_file;
FILE# ERROR
---------- -------------------------
4 FILE NOT FOUND


Previewing Backups Needed for Restore

Problem
Before you perform a restore and recovery, you would like to view which backups will be required for the restore operation.

Solution
Use the restore ... preview command to query the RMAN repository for the most recent
backup sets and corresponding files that will be used for a restore operation. Three restore

... preview modes are available:

• Normal
• Summarized
• Recall (MML only)
Normal Mode

In normal mode, you’ll get a full listing of the information contained in the repository. The following
example shows how to preview the restore of the system tablespace:

RMAN> restore tablespace system preview;

The following examples show how to use the preview command with a variety of restore
operations:

RMAN> restore database preview;
RMAN> restore database from tag TAG20060927T183743 preview;
RMAN> restore datafile 1, 2, 3, 4 preview;
RMAN> restore archivelog all preview;
RMAN> restore archivelog from time 'sysdate - 1' preview;
RMAN> restore archivelog from scn 3243256 preview;
RMAN> restore archivelog from sequence 29 preview;

RESTORE DATABASE UNTIL SEQUENCE 13243;

EJEMPLO RESTAURACION DESDE VERITAS TAPE PARA SECUENCIAS

connect catalog rman/rman@cat9i;
set dbid=4007731659;
connect target;

run {
ALLOCATE CHANNEL ch00
TYPE 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=sg-fa-ccol04-bck,NB_ORA_POLICY=Arc_NETCOOL_sg-fa-ccol04,NB_ORA_SERV=bksrv01,NB_ORA_SCHED=Default-Application-Backup)';
restore archivelog from logseq=613 until logseq=614;

RELEASE CHANNEL ch00;
}





Summarized Mode
You can use the preview summary command to summarize the lengthy output. This next example shows summarized information about the backup set(s) RMAN will use to restore your entire database:

RMAN> restore database preview summary;


Recall Mode
If you use a media manager that supports vaulted backups, then you can use preview recall to recall media from remote storage. This next example will request that any media needed to restore the database be recalled from remote storage.

RMAN> restore database preview recall;

Verifying Integrity of Backups

RMAN> restore database validate;
RMAN> restore database from tag MON_BCK validate;
RMAN> restore datafile 1 validate;
RMAN> restore archivelog all validate;
RMAN> restore controlfile validate;
RMAN> restore tablespace users validate;

By default, RMAN checks only for physical corruption when validating. You can also
instruct RMAN to check for logical corruption with the check logical clause:

RMAN> restore database validate check logical;

RMAN> validate backupset 193;
RMAN> validate backupset 193 check logical;
RMAN> validate recovery area;

You can instruct RMAN to check for logical corruption with the check logical clause of the restore command. When RMAN detects logical corruption, it will write relevant error messages to your target database’s alert.log file and also reflect this information in the V$DATABASE_BLOCK_CORRUPTION view.

Testing Media Recovery

Problem
You need to perform a database recovery, but you suspect one of your archived redo log files is bad. You want to perform a test to see whether all of the redo is available and can be applied.

Solution
The recover ... test command instructs Oracle to apply the redo necessary to perform
recovery but does not make the changes permanent in the datafiles. When you recover in test mode, Oracle applies the required redo but rolls back the changes at the end of the process.
This example starts up the database in mount mode, restores the entire database, and
then does a test recovery:

RMAN> connect target /
RMAN> startup mount;
RMAN> restore database;
RMAN> recover database test;

■Note Before performing a test recovery, ensure that the datafiles being recovered are offline. Oracle will
throw an ORA-01124 error for any one line datafiles being recovered in test mode.

RMAN> recover tablespace users, tools test;
RMAN> recover datafile 1 test;

RMAN> recover database until time 'sysdate – 1/48' test;
RMAN> recover database until scn 2328888 test;
RMAN> recover database until sequence 343 test;

In Oracle Database 10g and lower, the syntax recover ... test allow n corruption does not work from within RMAN. If you want to run the test command with the allow n corruption clause, then you must issue that command from inside SQL*Plus, as shown here:

SQL> connect sys/muft as sysdba
SQL> recover tablespace system test allow 5 corruption;

Performing Database-Level Recovery


RMAN> connect target /
RMAN> startup mount;
RMAN> restore database;
RMAN> recover database;
RMAN> alter database open;


Recover While Database Not Open
This solution works for any tablespace in your database. In this example, we restore the user_data and user_index tablespaces:

RMAN> connect target /
RMAN> startup mount;
RMAN> restore tablespace user_data, user_index;
RMAN> recover tablespace user_data, user_index;
RMAN> alter database open;

Use Backup Control File
RMAN> connect target /
RMAN> startup nomount;
RMAN> restore controlfile from autobackup;
RMAN> alter database mount;
RMAN> restore database;
RMAN> recover database;
RMAN> alter database open resetlogs;

Recover While Database Is Open
You can take a tablespace offline, restore, and recover it while your database is open. This works for any tablespace except the system and undo tablespaces. This example takes data_ts offline and then restores and recovers before bringing it back online:

RMAN> connect target /
RMAN> sql 'alter tablespace data_ts offline immediate';
RMAN> restore tablespace data_ts;
RMAN> recover tablespace data_ts;
RMAN> sql 'alter tablespace data_ts online';


Performing Datafile-Level Recovery

RMAN> connect target /
RMAN> startup mount;
RMAN> restore datafile 1;
RMAN> recover datafile 1;
RMAN> alter database open;

Recover While Database Open
For nonsystem and non-undo datafiles, you have the option of keeping the database open while performing the recovery. When your database is open, you’re required to take offline any datafiles you’re attempting to restore and recover.

RMAN> connect target /
RMAN> sql 'alter database datafile 3, 4 offline';
RMAN> restore datafile 3, 4;
RMAN> recover datafile 3, 4;
RMAN> sql 'alter database datafile 3, 4 online';

Restoring Datafiles to Nondefault Locations

RMAN> connect target /
RMAN> startup mount;
RMAN> run{
2> set newname for datafile 4 to '/ora01/BRDSTN/data_ts01.dbf';
3> set newname for datafile 5 to '/ora01/BRDSTN/data_ts02.dbf';
4> restore tablespace data_ts;
5> switch datafile all; # Updates repository with new datafile location.
6> recover tablespace data_ts;
7> alter database open;
8> }


If the database is open, you can place the datafiles offline and then set their new names
for restore and recovery:

RMAN> run{
2> sql 'alter database datafile 4, 5 offline';
3> set newname for datafile 4 to '/ora01/BRDSTN/data_ts01.dbf';
4> set newname for datafile 5 to '/ora01/BRDSTN/data_ts02.dbf';
5> restore datafile 4, 5;
5> switch datafile all; # Updates repository with new datafile location.
6> recover datafile 4, 5;
7> sql 'alter database datafile 4, 5 online';

You can also use datafile names instead of numbers. However, you have to be careful about which name you use and where it comes in the script. This is because the control file doesn’t consider the new location to be the current location until you issue the switch command.

RMAN> run{
2> sql "alter database datafile ''/ora02/BRDSTN/data_ts01.dbf'' offline';
3> set newname for datafile '/ora02/BRDSTN/data_ts01.dbf'
4> to '/ora01/BRDSTN/data_ts01.dbf';
5> restore datafile '/ora02/BRDSTN/data_ts01.dbf';
6> switch datafile all; # Updates repository with new datafile location.
7> recover datafile '/ora01/BRDSTN/data_ts01.dbf';
8> sql "alter database datafile ''/ora01/BRDSTN/data_ts01.dbf'' online";
9> }

Performing Block-Level Recovery

RMAN> recover corruption list;

RMAN will automatically detect corruption in blocks whenever a backup or backup
validate command is issued. These blocks are reported as corrupt in the alert.log file and the V$DATABASE_BLOCK_CORRUPTION view

The other way to recover blocks is to specify particular datafiles and blocks. Here are several

examples:

RMAN> recover datafile 5 block 24;
RMAN> recover datafile 7 block 22 datafile 8 block 43;
RMAN> recover datafile 5 block 24 from tag=tues_backup;
RMAN> recover datafile 6 block 89 restore until sequence 546;
RMAN> recover datafile 5 block 32 restore until 'sysdate-1';
RMAN> recover datafile 5 block 65 restore until scn 23453;

Recovering Read-Only Tablespaces

Problem
You issued a restore database command and notice that the datafiles associated with readonly
tablespaces were not restored.

Solution
Use the check readonly command to instruct RMAN to restore datafiles associated with readonly
tablespaces.

RMAN> connect target /
RMAN> startup mount;
RMAN> restore database check readonly;
RMAN> recover database;
RMAN> alter database open;

RMAN> connect target /
RMAN> startup mount;
RMAN> restore database;
RMAN> restore tablespace MAR05DATA, JUN05DATA;
RMAN> recover database;
RMAN> alter database open;


Restoring Temporary Tablespaces

SQL> CREATE TEMPORARY TABLESPACE temp TEMPFILE
2 '/ora03/oradata/BRDSTN/temp01.dbf' SIZE 5000M REUSE
3 EXTENT MANAGEMENT LOCAL UNIFORM SIZE 512K;

SQL> alter tablespace temp
2 add tempfile '/ora03/oradata/BRDSTN/temp01.dbf' SIZE 5000M REUSE;

Forcing RMAN to Restore a File

Problem

As part of a test exercise, you attempt to restore a datafile twice and receive this RMAN message: restore not done; all files readonly, offline, or already restored

Solution
Use the force command to restore datafiles and archived redo log files even if they already exist in a location. This command forces RMAN to restore files, even if RMAN determines that they don’t need to be restored. This first example uses the force to restore the obiwan01.dbf
datafile:

RMAN> restore datafile '/ora01/yoda/obiwan01.dbf' force;
You should see a message similar to this at the bottom of your RMAN messages stack:
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 09-FEB-07
Or if you know the particular datafile number, you can use the force command this way:

RMAN> restore datafile 42 force;
Similarly, you can use the force command on a tablespace. Here we use the force command to restore all datafiles associated with the star_wars tablespace:

RMAN> restore tablespace star_wars force;
RMAN> restore database force;
RMAN> restore archivelog from sequence 343 force;

Restoring from an Older Backup

Problem

You want to specifically instruct RMAN to restore from a backup set that is older than the last backup that was taken.

Specify a Tag Name

RMAN> startup mount;
RMAN> restore database from tag MON_BACK;
RMAN> recover database;
RMAN> alter database open;

RMAN> restore tablespace users from tag INCUPDATE;
RMAN> restore datafile 2, 3 from tag AUG_FULL;

Until

RMAN> startup mount;
RMAN> restore database until SCN 1254174;

Or if you know the log sequence number that you want to restore up to, the syntax is as follows:

RMAN> startup mount;
RMAN> restore database until sequence 17;
RMAN> recover database;
RMAN> alter database open;

If you’ve created restore points, then you can also use the restore point name as follows:

RMAN> startup mount;
RMAN> restore database until restore point FRI_RS;
RMAN> recover database;
RMAN> alter database open;

You can also specify a point in time from which you want RMAN to restore an older
backup. This example instructs RMAN to retrieve the first backup it finds that is more than 10 days old:

RMAN> startup mount;
RMAN> restore database until time 'sysdate – 10';
RMAN> recover database;
RMAN> alter database open;

Here we’re specifically instructing RMAN to restore from a date and time. Since we don’t
instruct RMAN to recover to a point in time, this example will perform a complete recovery:

RMAN> startup mount;
RMAN> restore database until time
2> "to_date('05-oct-2006 14:00:00', dd-mon-rrrr hh24:mi:ss')";
RMAN> recover database;
RMAN> alter database open;
RMAN> recover database;
RMAN> alter database open;

Recovering Through Resetlogs

RMAN> connect target /
RMAN> startup nomount;
RMAN> restore controlfile from autobackup;
RMAN> alter database mount;
RMAN> restore database;
RMAN> recover database;
RMAN> alter database open resetlogs;

Restoring the Spfile

Using a Recovery Catalog

If you’re using a recovery catalog, then restoring the spfile is fairly straightforward. This example
connects to the recovery catalog and then restores the spfile:

RMAN> connect target /
RMAN> connect catalog rmancat/rmancat@rcat
RMAN> startup nomount;
starting Oracle instance without parameter file for retrieval of spfile
RMAN> restore spfile;
RMAN> startup force; # startup using restored spfile


Not Using a Recovery Catalog, RMAN Autobackup in Default Location

RMAN> connect target /
RMAN> shutdown immediate;
RMAN> startup force nomount; # start instance for retrieval of spfile
RMAN> set dbid 260150593;
RMAN> restore spfile from autobackup;
RMAN> startup force; # startup using restored spfile

Not Using a Recovery Catalog, RMAN Autobackup Not in Default Location

RMAN> connect target /
RMAN> shutdown immediate;
RMAN> set dbid 260150593;
RMAN> startup force nomount; # start instance for retrieval of spfile
RMAN> restore spfile from '/ora02/FRA/BRDSTN/autobackup/2006_10_02/o1_mf_s_62.bkp';
RMAN> startup force; # startup using restored spfile

Restoring Archived Redo Log Files

RMAN> restore archivelog all;
RMAN> restore archivelog from sequence 50;

If you want to restore a range of archived redo log files, use the from sequence and until sequence clauses or the sequence between clause, as shown here. These commands restore archived redo log files from sequence 5170 through 5178 using thread 1.

RMAN> restore archivelog from sequence 5170 until sequence 5178 thread 1;
RMAN> restore archivelog sequence between 5170 and 5178 thread 1;

By default, RMAN won’t restore an archived redo log file if it is already on disk. You can override this behavior via the force option:

RMAN> restore archivelog from sequence 1 force;
Restoring to Nondefault Location
Use the set archivelog destination clause if you want to restore archived redo log files to a different location than the default. The following example restores to the nondefault location
of /ora01/archrest. The set command must be run from within the RMAN run{} block.

RMAN> run{
2> set archivelog destination to '/ora01/archrest';
3> restore archivelog from sequence 5200;
4> }

Recovering Datafiles Not Backed Up

RMAN> connect target /
RMAN> startup mount;
RMAN> restore tablespace user_idx;

Using a Backup Control File
This scenario is applicable anytime you use a backup control file to restore and recover a
datafile that has not yet been backed up. First, we restore a control file from an older backup:

RMAN> connect target /
RMAN> startup nomount;
RMAN> restore controlfile from '/orafra/BRDSTN/autobackup/2006_10_11/01_mfn_.bkp';

Deleting Archived Redo Log Files During Recovery

RMAN> recover database delete archivelog;

RMAN> recover database delete archivelog maxsize 500m;

Restoring from Uncataloged Backup Pieces in Oracle
Database 10g and Newer


Problem
You had to re-create your control file and you are not using a recovery catalog. Afterward, you
attempted to restore datafiles using RMAN but received the following errors:
RMAN-06026: some targets not found - aborting restore
RMAN-06023: no backup or copy of datafile 10 found to restore
RMAN-06023: no backup or copy of datafile 5 found to restore
RMAN-06023: no backup or copy of datafile 3 found to restore
RMAN-06023: no backup or copy of datafile 2 found to restore
RMAN-06023: no backup or copy of datafile 1 found to restore

Solution
Use the catalog command to add RMAN metadata directly to your control file about backup pieces. Using a Flash Recovery Area
You can have RMAN repopulate the control file with all file information in the flash recovery. The following command will catalog all backup sets, datafile copies, and archived redo log files located in the flash recovery area:

RMAN> catalog recovery area;


Using a Directory
You can also instruct RMAN to catalog all the backup pieces and image copies located under a starting directory path. This example instructs RMAN to record metadata in the repository for any backup pieces and image copies located under the /oradump01/FRA directory:

RMAN> catalog start with '/oradump01/FRA';

Restoring from Uncataloged Backup Pieces in Oracle9i Database and Older

Problem

You had to re-create your control file, and you are not using a recovery catalog. You want to restore control files, datafiles, and archived redo logs from RMAN backup pieces, but your control file now contains no information whatsoever about previously taken backups.

Solution

Use the DBMS_BACKUP_RESTORE package to restore files from backup pieces. This recipe
has several examples:
• Restoring a control file
• Restoring datafiles contained in a single backup piece
• Restoring datafiles contained in several backup pieces
• Applying incremental backups to datafiles

Restoring a Control File
You can use the PL/SQL package DBMS_BACKUP_RESTORE to restore a control file. You need
to know the name of the backup piece that contains the backup of the control file before you
begin. Modify the following anonymous block of PL/SQL to use your backup piece name and
control file name:
DECLARE
finished BOOLEAN;
v_dev_name VARCHAR2(75);
BEGIN
-- Allocate a channel, when disk then type = null, if tape then type = sbt_tape.
v_dev_name := dbms_backup_restore.deviceAllocate(type=>null, ident=>'d1');
--
dbms_backup_restore.restoreSetDatafile;
dbms_backup_restore.restoreControlFileTo(
cfname=>'C:\oracle\product\10.2.0\oradata\ORCL\CONTROL01.CTL');
--
dbms_backup_restore.restoreBackupPiece(
'C:\oracle\product\10.2.0\flash_recovery_area\ORCL\AUTOBACKUP\
2006_12_06\O1_MF_N_608466281_2QFZ6TNJ_.BKP', finished);
--
if finished then
dbms_output.put_line('Control file restored.');
else
dbms_output.put_line('Problem');
end if;
--
dbms_backup_restore.deviceDeallocate('d1');
END;
/

If the previous code was stored in a file named rc.sql, then you would execute it as follows:
SQL> connect / as sysdba
SQL> startup nomount;
SQL> @rc.sql

Restoring Datafiles in a Single Backup Piece
If you have output logs from your backups, then you can visually inspect those and determine the names of the datafiles within a backup piece. If you don’t have any output logs, then you’ll have to figure out through trial and error which datafiles are in which backup piece.

In this example, we know from our RMAN backup output logs that there are four datafiles contained within this backup piece. You’ll need to modify this anonymous block of PL/SQL

code to specify the files in your environment:

SET SERVEROUTPUT ON
DECLARE
finished BOOLEAN;
v_dev_name VARCHAR2(75);
BEGIN
-- Allocate channels, when disk then type = null, if tape then type = sbt_tape.
v_dev_name := dbms_backup_restore.deviceAllocate(type=>null, ident=> 'd1');
--
-- Set beginning of restore operation (does not restore anything yet).
dbms_backup_restore.restoreSetDatafile;
--
-- Define datafiles and their locations for datafiles in first backup piece.
dbms_backup_restore.restoreDatafileTo(dfnumber=>1,toname=>'C:\ORCL\SYSTEM01.DBF');
dbms_backup_restore.restoreDatafileTo(dfnumber=>3,toname=>'C:\ORCL\SYSAUX01.DBF');
dbms_backup_restore.restoreDatafileTo(dfnumber=>4,toname=>'C:\ORCL\USERS08.DBF');
dbms_backup_restore.restoreDatafileTo(dfnumber=>9,toname=>'C:\ORCL\ORA02.DBF');
--
-- Restore the datafiles in this backup piece.
dbms_backup_restore.restoreBackupPiece(done => finished,
handle=>'C:\FRA\ORCL\BACKUPSET\2006_12_26\
O1_MF_NNNDF_TAG20061226T174632_2S3JM9NJ_.BKP', params=>null);
--
IF finished THEN
dbms_output.put_line('Datafiles restored');
ELSE
dbms_output.put_line('Problem');
END IF;
--
dbms_backup_restore.deviceDeallocate('d1');
END;
/
• Restoring archived redo log files

If you put the prior code into a file named dbr.sql, then you would run it as follows:
SQL> connect / as sysdba
SQL> startup mount;
SQL> @dbr.sql

SET SERVEROUTPUT ON
DECLARE
finished BOOLEAN;
v_dev_name VARCHAR2(75);
TYPE v_filestable IS TABLE OF varchar2(500) INDEX BY BINARY_INTEGER;
v_filename V_FILESTABLE;
v_num_pieces NUMBER;
BEGIN
-- Allocate channels, when disk then type = null, if tape then type = sbt_tape.
v_dev_name := dbms_backup_restore.deviceAllocate(type=>null, ident=> 'd1');
--
-- Set beginning of restore operation (does not restore anything yet).
dbms_backup_restore.restoreSetDatafile;
--
-- Define backup pieces in backup set.
v_filename(1) :=
'C:\FRA\ORCL\BACKUPSET\2006_12_29\O1_MF_NNNDF_TAG20061229T175720_2SCGCR59_.BKP';
v_filename(2) :=
'C:\FRA\ORCL\BACKUPSET\2006_12_29\O1_MF_NNNDF_TAG20061229T175720_2SCGG2J0_.BKP';
v_filename(3) :=
'C:\FRA\ORCL\BACKUPSET\2006_12_29\O1_MF_NNNDF_TAG20061229T175720_2SCGHSC4_.BKP';
-- There are 3 backup pieces in this backup set.
v_num_pieces := 3;
-- Define datafiles and locations.
dbms_backup_restore.restoreDatafileTo(dfnumber=>1,toname=>'C:\ORCL\SYSTEM01.DBF');
dbms_backup_restore.restoreDatafileTo(dfnumber=>10,toname=>'C:\ORCL\DS_TS01.DBF');
-- Restore the datafiles in this backup set.
FOR i IN 1..v_num_pieces LOOP
dbms_backup_restore.restoreBackupPiece(done => finished, handle=> v_filename(i),
params=>null);

END LOOP;
--
IF finished THEN
dbms_output.put_line('Datafiles restored');
ELSE
dbms_output.put_line('Problem');
END IF;
--
dbms_backup_restore.deviceDeallocate('d1');
END;
/

If you put the prior code into a file named dbr.sql, then you would run it as follows:
SQL> connect / as sysdba
SQL> startup mount;
SQL> @dbr.sql


Applying Incremental Backups
Here’s an example that shows how to apply an incremental backup. This example assumes
that the datafile has already been restored and is now ready to have an incremental backup
applied to it. You’ll need to modify this anonymous block of PL/SQL to specify the filenames
in your environment.
SET SERVEROUTPUT ON
DECLARE
finished BOOLEAN;
v_dev_name VARCHAR2(75);
BEGIN
-- Allocate channels, when disk then type = null, if tape then type = sbt_tape.
v_dev_name := dbms_backup_restore.deviceAllocate(type=>null, ident=> 'd1');
--
-- Set beginning of apply operation (does not restore anything yet).
dbms_backup_restore.applySetDatafile;
--
-- Define file to apply incremental to.
dbms_backup_restore.applyDatafileTo(dfnumber=>10,toname=>'C:\ORCL\DATA_TS.DBF');
--
-- Apply incremental backup to datafile.
dbms_backup_restore.applyBackupPiece(done=>finished,
handle=>'C:\FRA\ORCL\BACKUPSET\2006_12_31\O1_MF_NNND1_TAG20061231T130613_2SJ61T4S_.B
KP');
--
IF finished THEN
dbms_output.put_line('Incremental applied.');
ELSE
dbms_output.put_line('Problem');

END IF;
--
dbms_backup_restore.deviceDeallocate('d1');
END;
/
If you put the prior code into a file named dbr.sql, then you would run it as follows:
SQL> connect / as sysdba
SQL> startup mount;
SQL> @dbr.sql

Restoring Archived Redo Log Files

Here is an anonymous block of PL/SQL that shows how to restore archived redo log files using DBMS_BACKUP_RESTORE. Before using this, you’ll have to change this code to match your environment. This example restores two archived redo log files that are stored in one backup piece.

SET SERVEROUTPUT ON
DECLARE
finished BOOLEAN;
v_dev_name VARCHAR2(75);
BEGIN
-- Allocate channels, when disk then type = null, if tape then type = sbt_tape.
v_dev_name := dbms_backup_restore.deviceAllocate(type=>null, ident=> 'd1');
--
-- Set beginning of restore operation (does not restore anything yet).
dbms_backup_restore.restoreSetArchivedlog;
--
-- Define archived redo log files to be restored.
dbms_backup_restore.restoreArchivedlog(thread=>1, sequence=> 354);
dbms_backup_restore.restoreArchivedlog(thread=>1, sequence=> 355);
--
dbms_backup_restore.restoreBackupPiece(done=>finished, handle=>
'C:\FRA\ORCL\BACKUPSET\2006_12_30\O1_MF_ANNNN_TAG20061230T100354_2SF7055R_.BKP',
params=>null);
--
IF finished THEN
dbms_output.put_line('Archived redo log files restored');
ELSE
dbms_output.put_line('Problem');
END IF;
--
dbms_backup_restore.deviceDeallocate('d1');
END;
/

SQL> connect / as sysdba
SQL> @dbr.sql