9.3 Maintaining the ZENworks Data Store on Oracle

The following sections provide instructions for backing up and recovering a ZENworks Data Store using Oracle:

9.3.1 Backup and Recovery Solutions

Oracle provides two methods of backup and recovery:

  • Recovery Manager (RMAN)

  • User-managed backup and recovery.

The RMAN utility is automatically installed with the database. It can back up an Oracle8 database and all later versions of an Oracle* database. RMAN uses server sessions on the database to perform backup and recovery. RMAN has its own syntax and is accessible either through a command-line interface or through the Oracle Enterprise Manager GUI. RMAN also provide APIs to interface with third-party media managers.

The advantage of RMAN is that it obtains and stores metadata about its operations in the control file of the database. An independent recovery catalog can be set up, which is a schema that contains metadata imported from the control file, in a separate recovery catalog database. RMAN performs the necessary record keeping for backups, archived logs, and so forth using the metadata, so restoration and recovery is greatly simplified.

An alternative method of performing recovery is to use operating system commands for backups and SQL*Plus for recovery. This method is called User-managed backup and recovery.

RMAN automates backup and recovery, but the User-managed method requires keeping track of all database files and backups. Therefore, because of its robustness and simplified database administration abilities, RMAN is a highly recommended tool for backup operations. The subsequent sections of this document explain the steps for using RMAN to perform a complete database backup and recovery.

9.3.2 Setting Environment Variables

  1. Set the following environment variables to the appropriate values before using RMAN:

    • ORACLE_HOME: The directory where the Oracle software is installed. For example:

      ORACLE_HOME=/home/oracle/product/9ir2

    • CLASSPATH: The paths to the libraries installed by Oracle. For example:

      CLASSPATH=$CLASSPATH:/oracle/opt/oracle/product/9ir2/JRE:/oracle/opt/oracle/product/9ir2/jlib:/oracle/opt/oracle/product/9ir2/rdbms/jlib:/oracle/opt/oracle/product/9ir2/network/jlib

    • PATH: The Oracle installation’s bin directory. For example:

      PATH=$PATH:/home/oracle/product/9ir2/bin

9.3.3 Connecting to the Database

You can use either of the following methods to connect to the Oracle database being used for the Data Store:

  • Start RMAN at the operating system command line without connecting to a database, by issuing the RMAN command without any connection options:

    $ rman RMAN> CONNECT TARGET /

  • Start the RMAN executable at the operating system command line while connecting to the database:

    $ rman TARGET /

If the database is already mounted or open, RMAN displays output similar to the following:

  Recovery Manager: Release 9.2.0.0.0  
connected to target database: RMAN (DBID=1237603294)

The DBID value displayed is the database identifier for the target database.

If the target database is not started, RMAN shows the following message:

  connected to target database (not started)  
RMAN>   # the RMAN prompt is displayed

9.3.4 Starting the Database

  1. Start the database using the following command:

    RMAN> startup mount

    This command starts an Oracle instance if it is not already started, and mounts the database but does not open it.

    If the mount was successful, then the following output is displayed:

      Oracle instance started
    database mounted
    

    Otherwise, appropriate error messages are displayed, indicating the causes of failure and suitable solutions.

9.3.5 Backing Up the Database

You can back up the database to the default disk location. The default location is OS-specific. On Linux, the default path where backup files are stored is $ORACLE_HOME/dbs.

To make a full backup of the data files, control files, and the current server parameter file to the default device type (which is the disk), use the following backup command at the RMAN prompt:

RMAN> BACKUP DATABASE;

In the above command, the FORMAT parameter is not specified, so RMAN automatically gives each backup piece a unique name and stores it in the OS-specific default location ($ORACLE_HOME/dbs on Linux).

To specify a filename for the backup piece, use the backup command with the FORMAT parameter:

RMAN> BACKUP DATABASE FORMAT’/tmp/%U’;

%U generates a unique filename.

The RMAN backup command creates a backup set, which is a logical object that contains one or more backup pieces.

The backup command output contains the essential information about the backup, as shown in the following example:

Starting backup at OCT 12 2001 19:09:48
using target database controlfile instead of recovery catalogal
located channel: ORA_DISK_1
channel ORA_DISK_1: sid=10 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current SPFILE in backupset
including current controlfile in backupset
input datafile fno=00001 name=/oracle/oradata/zenworks/system01.dbf
input datafile fno=00002 name=/oracle/oradata/zenworks/undotbs01.dbf
input datafile fno=00003 name=/oracle/oradata/zenworks/cwmlite01.dbf
input datafile fno=00004 name=/oracle/oradata/zenworks/drsys01.dbf
input datafile fno=00005 name=/oracle/oradata/zenworks/example01.dbf
input datafile fno=00006 name=/oracle/oradata/zenworks /indx01.dbf
input datafile fno=00007 name=/oracle/oradata/zenworks/tools01.dbf
input datafile fno=00008 name=/oracle/oradata/zenworks/users01.dbf
channel ORA_DISK_1: starting piece 1 at OCT 12 2001 19:09:56
channel ORA_DISK_1: finished piece 1 at OCT 12 2001 19:10:31
piece handle=/oracle/dbs/lvd6dtk1_1_1 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:39
Finished backup at OCT 12 2001 19:10:33

9.3.6 Recovering the Database

You can recover a restored data file by applying archived redo logs and online redo logs; that is, records of changes made to the database after the backup was taken. The following sections provide instructions for two methods you can use to recover the database:

Complete Recovery

Complete recovery involves using redo data or incremental backups combined with a backup of a database, tablespace, or data file, to update it to the most current point in time. This is called a complete recovery because Oracle applies all of the redo changes contained in the archived and online logs to the backup. Typically, a complete media recovery is performed after a media failure damages data files or the control file.

  1. Use the following sequence of commands to perform a complete recovery of the database:

    RMAN> connect target / RMAN> run { 2> startup mount; 3> restore database; 4> recover database; 5> alter database open; 6> }

    This results in all data files being restored and then recovered. RMAN applies archive logs as necessary until the recovery is complete.

  2. After the restore is complete, you need to ensure that the Data Store is synchronized with the Object Store. For instructions, see Section 9.4, Synchronizing the Object Store and Data Store.

Incomplete Recovery

RMAN can perform recovery of the whole database to a specified non-current time, SCN, or log sequence number. This type of recovery is called incomplete recovery because it does not completely use all of the available redo logs. Incomplete recovery of the whole database is also called database point-in-time recovery (DBPITR).

You should perform an incomplete recovery of the database in the following situations:

  • Media failure destroys some or all of the online redo logs.

  • A user error causes data loss, for example, a user inadvertently drops a table.

  • You cannot perform a complete recovery because an archived redo log is missing.

To perform an incomplete recovery, restore all data files from backups created prior to the time when a recovery is needed, and then open the database with the RESETLOGS option after recovery completes. The RESETLOGS operation creates a new instance of the database—in other words, a database with a new stream of log sequence numbers starting with log sequence 1.

The database must be closed to perform an incomplete recovery.

To perform an incomplete recovery:

  1. Set the time format environment variable:

    $ NLS_DATE_FORMAT="Mon DD YYYY HH24:MI:SS"

  2. Use the following sequence of steps:

    $ rman target /RMAN> startup mount; RMAN> run { 2> set until time "to_date(’Mar 16 2005 10:24:00’, ’MM DD YYYY HH24:MI:SS’)";3> restore database; 4> recover database; 5> }

    RMAN uses the last backup created before the time mentioned in the set until command to restore the files to their default locations. Then, it uses archived redo logs (if needed) to recover the database.

    Two other parameters that can be used with the set until command are SCN and log sequence numbers. You obtain SCNs from the alert logs. Find the SCN of an event and recover to a prior SCN. For example:

    SET UNTIL SCN 1000
    
  3. If recovery was successful, open the database and reset the online logs:

    ALTER DATABASE OPEN RESETLOGS;

  4. After the restore is complete, you need to ensure that the Data Store is synchronized with the Object Store. For instructions, see Section 9.4, Synchronizing the Object Store and Data Store.

We recommend that you back up the database immediately, preferably with the database mounted (to avoid possible data loss in an open database). Because the database is a new instance, the backups made before the RESETLOGS are not easily usable.

9.3.7 Shutting Down the Database

  1. Use the following command to shut down the database:

    RMAN> SHUTDOWN NORMAL;

    This command dismounts the database and stops the running Oracle instance.