Chapter 6. Restoring Data

In the event of data corruption or a disk crash, BusinesSuite Module for Oracle provides a means for the Enterprise Backup Utility to restore data backed up by NetWorker to your Oracle7 Server. BusinesSuite Module for Oracle allows you to perform on–demand restores of Oracle instances and individual database objects, using the Enterprise Backup Utility command-line interface.

For more information, refer to “Performing Restores” in the Oracle7 Enterprise Backup Utility Administrator's Guide, “Recovering from a Disk Crash” in the IRIX NetWorker Administrator's Guide, and the nsr_crash(1M) reference page.

Before Restoring Data

During backup, the NetWorker server makes entries in an online client file index and records the volume information in the online media index. These entries provide recovery information needed for every Oracle object backed up. The file index entry is maintained until the browse policy configured for the client's save set expires. The media index entry is maintained until the retention policy configured for the client's save set expires. Once the browse and retention policies expire, the backup media is eligible for recycling and may be overwritten.

NetWorker sends a record of the server's bootstrap generated during backups to your default printer, so you have a printed record of the dates, locations, and save set ID numbers for the server's online indexes needed for recovering data. Keep the bootstrap printouts in a notebook for quick reference in the event of a disaster, such as a disk crash or server malfunction.

Recovering From Disaster

This section describes how to recover from a crash in which one or more files of the target database has been damaged.

If the catalog database has been damaged, see the section titled “Bootstrap After Loss of Backup Catalog Database”.

Restore Versus Recovery

Oracle makes a distinction between restoring and recovering a database. Restore means the replacement of individual database files from backup media, whereas recover means applying redo logs to roll forward the redo log transactions to make the database consistent. By contrast, NetWorker uses recover for all retrieval activities, as distinguished from the UNIX restore command. This chapter follows the Oracle terminology.

Use obackup to restore missing database files. Then apply the redo logs to recover your target database through the standard Oracle recovery process.


Note: Database restores are always executed through obackup. The restore is executed by running the obackup command with a restore script. Restores driven through the NetWorker interface are not supported.


Determining the Problem

The first sign of a disk crash will usually be an I/O error. Oracle usually documents the I/O error in the trace file and might issue an alert. Look near the end of the trace file and try to determine which database files are affected. Here are some error messages that indicate the need for recovery:

ORA-01113    file name needs media recovery
ORA-01122    data file name - failed verification check
ORA-01162    block size num in file header does not match

If only one database file is affected, your database may have encountered a bad spot on the disk. This can be circumvented by reformatting the disk to make a new list of bad blocks. However, this can be time-consuming, so keep an extra disk on hand as a hot spare, in case a disk failure occurs. Format the spare disk and verify that it works. If a disk failure does occur, it is much faster to swap in a spare disk than it is to rename database files and update the control file accordingly.

If several database files (all on the same disk) are affected, you could have a disk controller problem or a disk head crash. A bad controller can be replaced, and data on the disk often remains in perfect shape. But after a head crash, you need to use that spare disk as a replacement disk.

Required DMO Variables for Data Restores

If you do not provide a setting for the required Networker BusinesSuite Module for Oracle variable, Enterprise Backup Utility restores may fail.

Setting the Value for NSR_CLIENT

Verify that the NSR_CLIENT environment variable is set during restores to the name of the client whose data was backed up. In most cases, this will be the name of the local machine, unless you are restoring data to a different host machine. By default, the BusinesSuite Module for Oracle will use the name of the local machine. To set the NSR_CLIENT environment variable, run the following command:

% setenv NSR_CLIENT networker_clientname 


Note: For an example of a restore scenario in which you need to set the NSR_CLIENT variable, see the section “Using obackup to Restore to a Different Host”.


Setting the Value for NSR_SERVER

The NSR_SERVER environment variable indicates which NetWorker server to use for restores. Set this variable to the name of the server that backed up the data to be restored. To properly set NSR_SERVER, replace the value networker_servername in the following example with the actual name of the server assigned for NetWorker restores of your Oracle7 Server:

% setenv NSR_SERVER networker_servername 


Tip: If you do not explicitly specify a value for the variable NSR_SERVER before issuing a restore command, NetWorker searches the network for a server to use. Setting the NSR_SERVER variable explicitly helps avoid a potential delay in the restore process.


Setting the Value for OBK_HOME

The NetWorker BusinesSuite Module for Oracle variable OBK_HOME is required by both the Enterprise Backup Utility program obackup and the BusinesSuite Module for Oracle. To set OBK_HOME, replace the value ebu_install_dir in the following example with the actual name of the directory where the Oracle7 Enterprise Backup Utility is installed on your system:

% setenv OBK_HOME ebu_install_dir 

Using obackup to Restore

After setting the required environment variables, you may use obackup to restore data.

Here is an example of a restore script, in case you lose all copies of the control file:

restore
db_name = "TARGET01"
oracle_sid = "TARGET01"
control_file
log = "/oracle/obackup/logs/restore.log"

You can use the restore database script to restore the entire database, It is likely that only a few database files are damaged and that you can restore them with a partial restore script. (Notice that restore means partial restore.)


Note: To ensure optimal restore performance, set the parallel parameter in the restore command script to be equal to the parallel parameter used during backup.

This is an example of a restore database command script:

restore database
db_name = "TARGET01"
oracle_sid = "TARGET01"
log = "/oracle/obackup/logs/restore_db.log"
parallel=4

You can perform a restore database regardless of the kind of backups you performed. The Oracle Enterprise Backup Utility restores the most recent copies of all files involved. Note that after a restore database, the state of the database is inconsistent and you have to perform a standard Oracle recover. For more information, see the Oracle7 Server for UNIX Administrator's Reference Guide.

You may restore either tablespaces or datafiles as a unit. You may want to create various restore scripts, but be prepared to modify them in an actual disaster recovery situation.

As another example, assume you have a damaged disk named /disk2 and that all you have on this disk is the tablespace TOOLS, composed of many datafiles. Perform the following steps to properly restore the tablespace:

  1. Set the required NetWorker environment variables:

    % setenv NSR_SERVER networker_servername
    % setenv NSR_CLIENT networker_clientname
    

  2. Create an obackup restore command script:

    restore
    db_name = "TARGET01"
    oracle_sid = "TARGET01"
    tablespace = "TOOLS"
    log = "/oracle/obackup/logs/restore_ts.log"
    parallel=2
    

  3. Run the obackup restore command script:

    % obackup restore 
    

    When the restore command script completes successfully, it displays the following type of output:

    Oracle7 Enterprise Backup Utility: Release 2.0.12.4.0
    Copyright (c) Oracle Corporation 1979, 1994.  All rights reserved.
    CORE Version 3.5.2.0.0 - Production
    NLSRTL Version 3.2.2.0.0 - Production
    RESTORE job SUCCESSFUL
    

  4. Connect to the database and issue a recover command:

    % svrmgrl 
    SVRMGR> connect internal 
    SVRMGR> recover tablespace tablespace_name 
    

To restore individual datafiles instead of an entire tablespace, use the keyword dbfile instead of tablespace:

dbfile = "/disk2/oradata/target01/tools01.dbf",
         "/disk2/oradata/target01/tools02.dbf"

If a replacement disk for /disk2 is not available, you can restore datafiles to a different location with the remap option. For example, if /disk3 is available and has enough free space, you can restore a datafile to /disk3 instead of /disk2 by using the following type of command script:

restore
db_name = "TARGET01"
oracle_sid = "TARGET01"
dbfile = "/disk2/oradata/target01/tools01.dbf"
remap = "/disk2/oradata/target01/tools01.dbf" to
        "/disk3/oradata/target01/tools01.dbf"

Using obackup to Restore to a Different Host

In some circumstances, you might need to restore your database onto a machine other than the one from which it was backed up.

In order to execute this recovery plan, the BusinesSuite Module for Oracle and the Enterprise Backup Utility must be installed and configured on the secondary machine where you will be restoring your data.

To restore data onto a different host, set the NSR_CLIENT environment variable to the name of the machine where the database was originally backed up. NSR_CLIENT allows the secondary host to recover savesets backed up by the original client.

You must also set the backup_host parameter in the obackup command script to the name of the original backup host, in the same way that NSR_CLIENT is set. This specifier identifies the backup set in the Backup Catalog. Here is a summary of steps to perform:

  1. Install the BusinesSuite Module for Oracle on the secondary host.

  2. Install the Enterprise Backup Utility on the secondary host.

  3. Set NSR_SERVER to specify the backup server.

  4. Set NSR_CLIENT to specify the original NetWorker client.

  5. Create an Enterprise Backup Utility restore command file.

  6. Set the backup_host parameter in the command file to specify the original backup host (the same value used for NSR_CLIENT).

  7. Execute the obackup command with the restore command file.


Note: If you believe you might need to restore databases to a secondary client, Silicon Graphics strongly recommends installing and configuring both the BusinesSuite Module for Oracle and Enterprise Backup Utility on the secondary machine well in advance.


Applying the Redo Logs

After restoring corrupted database files, you must apply the redo logs to bring your database up to date. To do this, refer to the sections on database recovery in the Oracle7 Server for UNIX Administrator's Reference Guide.

Bootstrap After Loss of Backup Catalog Database

Should the Backup Catalog database become lost, the Backup Catalog becomes unavailable until you restore the database. The information contained in the Backup Catalog is vital to the Enterprise Backup Utility. If you have backed up the Catalog after every backup series (full or partial), then you can restore the Backup Catalog from a backup using the NetWorker client-side GUI.

If you did not back up the Backup Catalog, your only alternative is to recreate the Backup Catalog database and apply its redo logs.

If the Backup Catalog becomes corrupted, you must start by restoring the Backup Catalog database using the nwrecover program. Then run the Oracle import command. If the Backup Catalog is intact, this step is not necessary. The obkimp.sh shell script is provided to import the catalog database from an export done with the obkexp.sh script.

Enterprise Backup Utility version 2.1 automates the backup and restore of the Backup Catalog. As the last step of any backup, EBU 2.1 automatically saves the Backup Catalog information to the backup media, unless you disable this feature.

If the Backup Catalog becomes corrupted or deleted, as when the disk drive containing the catalog experiences a hardware failure, you can recover with the following steps. Before beginning, ensure that the Backup Catalog was successfully backed up with the combination of EBU 2.1 and BusinesSuite Module for Oracle. In this example, the Backup Catalog ORACLE_SID is obk.

  1. Replace your disk drive.

  2. Recreate the obk Backup Catalog database.

  3. Using your preferred text editor, create an obackup restore catalog script for obk called restore-catalog, containing the following:

    restore catalog = "obk"
    

  4. Set the NetWorker environment variables NSR_CLIENT and NSR_SERVER.

  5. Run obackup with the restore-catalog script:

    # obackup restore-catalog 
    

  6. When the restore-catalog scripts complete successfully, EBU displays this output:

    Starting Catalog restoration
    Ending Catalog restoration
    RESTORE job SUCCESSFUL
    

Restore and Recover Procedures

If you experience any of the following three types of problems, use NetWorker for assistance:

  • tablespace corruption including SYSTEM table

  • datafile corruption

  • user error

Silicon Graphics recommends using complete media recovery after a datafile is lost or the SYSTEM table is corrupted, and using incomplete media recovery after a user error occurs (such as a dropped table).

Your database will be easier to recover when it is closed because there is less contention for system resources. You must close the database in any case if the SYSTEM table was corrupted.

However, if only a few datafiles were affected and the database must remain available for business reasons, leave it open and perform an open database recovery with the affected tablespaces offline. In this case, it might be helpful to remap restored files to a neutral location. For details, refer to Chapter 4, “Performing Restores,” in the Oracle7 Enterprise Backup Utility Administrator's Guide Release 2.0.

Offline Complete Media Recovery

Follow these steps to perform a closed database recovery:

  1. Connect to the database as INTERNAL.

  2. Find out what datafiles are corrupted by looking at the message logs or by issuing the SQL command:

    SELECT file#, online, error FROM v$recover_file
    

  3. Issue a SHUTDOWN command.

  4. Correct the hardware problem. For example, replace the disk.

  5. Restore damaged datafiles with obackup by executing obackup from the command line with a restore script.

  6. Start sqldba or Server Manager and connect as INTERNAL, then issue a STARTUP MOUNT command.

  7. Issue a RECOVER {DATABASE,TABLESPACE,DATAFILE} command.

  8. Supply archived redo logs as requested. When the recovery is complete, this message appears:

    Media recovery complete.
    

  9. Issue an ALTER DATABASE OPEN command.

Online Partial Media Recovery

Follow these steps to perform an open database recovery:

  1. Connect to the database as INTERNAL.

  2. With an open database, remap or take the tablespace with damaged datafiles offline by issuing the SQL command:

    ALTER TABLESPACE tblsp-name OFFLINE
    

  3. Correct the hardware problem. For example, replace the disk.

  4. Restore damaged datafiles with obackup by running obackup from the command line with a restore script.

  5. Issue a RECOVER {DATABASE,TABLESPACE,DATAFILE} command.

  6. Supply archived redo logs as requested. When the recovery is complete, this message appears:

    Media recovery complete.
    

  7. Bring the affected tablespace online with the command:

    ALTER TABLESPACE tblsp-name ONLINE
    

Offline Incomplete Media Recovery

Follow these steps to perform an incomplete media recovery, for example after a user drops (deletes) a table by mistake. It is called “incomplete” because not all available media are used.

  1. Connect to the database as INTERNAL.

  2. Find out what datafiles are corrupted by looking at message logs or by issuing this SQL command:

    SELECT file#, online, error FROM v$recover_file
    

  3. Issue a SHUTDOWN ABORT command.

  4. If the control files do not match the desired database structure, restore old control files as appropriate or use the TO option of the RESTORE command.

  5. Restore datafiles from backups taken at appropriate times. For example, if a user error occurred during redo log #112, restore the data files from backups taken before #112. Restore damaged datafiles with obackup by running obackup from the command line with a restore script.

  6. Start sqldba or Server Manager and connect as INTERNAL, then issue a STARTUP MOUNT command.

  7. Issue a RECOVER DATABASE UNTIL {CANCEL,TIME,CHANGE} command.

  8. Supply archived redo logs as requested.

    If you chose the CANCEL option, stop applying redo logs at the desired point and enter CANCEL.

    When the recovery is complete, these messages appear:

    Incomplete recovery done UNTIL CHANGE scn. 
    Media recovery complete.
    

  9. Issue an ALTER DATABASE OPEN {RESETLOGS,NORESETLOGS} command.

    Refer to the Oracle7 Server for UNIX Administrator's Reference Guide, to determine if you should use the RESETLOGS option. If you do use RESETLOGS, shut down the database and perform another full backup.