Oracle8i Backup and Recovery Guide Release 2 (8.1.6) A67773-01 |
|
This chapter offers guidelines and considerations for developing an effective backup and recovery strategy. It includes the following topics:
Before you create an Oracle database, decide how to protect the database against potential media failures. If you do not develop a backup strategy before creating your database, you may not be able to perform recovery if a disk failure damages the datafiles, online redo log files, or control files.
This section describes general guidelines that can help you decide when to perform database backups and which parts of a database you should back up. Of course, the specifics of your strategy depend on the constraints under which you are operating. No matter which backup strategy you implement, however, follow these guidelines whenever possible:
The set of files needed to recover from the failure of any Oracle database file--a datafile, control file, or online redo log--is called the redundancy set. The redundancy set contains:
tnsnames.ora
, and listener.ora
The golden rule of backup and recovery is: the set of disks or other media that contain the redundancy set should be separate from the disks that contain the datafiles, online redo logs, and control files. This strategy ensures that the failure of a disk that contains a datafile does not also cause the loss of the backups or redo logs needed to recover the datafile. Consequently, a minimal production-level database requires at least two disk drives: one to hold the files in the redundancy set and one to hold the main database files.
Always keep the redundancy set separated from the primary files in every way possible: on separate volumes, separate file systems, and separate RAID devices. These systems are very reliable, but they can and do fail. Keeping the redundancy set separate ensures that you can recover from a failure without losing committed transactions.
You can implement a system that follows the golden rule in several different ways. Oracle recommends following these guidelines:
If the redundancy copy is generated by splitting a mirror, then it is not as good as a backup generated through operating system or RMAN commands because it relies on the mirroring subsystem for both the primary files and redundancy set copy. The last real file backup, such as the last backup to tape, is the redundancy set copy. Therefore, keep archived redo logs starting with this copy.
Before you create an Oracle database, decide how you plan to protect it against potential failures. Answer the following questions:
Once you have answered these questions and have determined which mode to use, follow the guidelines for either:
If you operate your database in NOARCHIVELOG mode, Oracle does not archive filled groups of online redo log files. Therefore, the only protection against a disk failure is the most recent whole backup of the database. Follow these guidelines:
If you run your database in ARCHIVELOG mode, ARCn archives groups of online redo log files. Therefore, the archived redo log coupled with the online redo log and datafile backups can protect the database from a disk failure, providing for complete recovery from a disk failure to the instant that the failure occurred (or, to the desired non-current time). Following are common backup strategies for a database operating in ARCHIVELOG mode:
Whether you should take open or closed datafile backups depends on the availability requirements of the data. Open datafile backups are the only choice if the data being backed up must always be available.
You can also use a datafile copy taken while the database is open and the tablespace is online to restore datafiles. You must apply the appropriate redo log files to these restored datafiles to make the data consistent and bring it forward to the specified point in time.
The control file, online redo log, and archived redo log are crucial files for backup and recovery operations. The loss of any of these files can cause you to lose data irrevocably. You should maintain:
Chapter 2, "Managing Data Structures" to learn how to integrate data structure management into your backup and recovery strategy, and Oracle8i Concepts for a thorough conceptual overview of all Oracle data structures.
See Also:
Frequent backups are essential for any recovery scheme. Base the frequency of backups on the rate or frequency of database changes such as:
If users generate a significant amount of DML, database backup frequency should be proportionally high. Alternatively, if a database is mainly read-only, and updates are issued only infrequently, you can back up the database less frequently.
Use either Recovery Manager or operating system methods to create backup scripts. RMAN scripts, which are stored in the recovery catalog, are an especially efficient method for performing routine, repetitive backup operations.
See Also:
Oracle8i Recovery Manager User's Guide and Reference to learn how to create, delete, replace, and print stored scripts. |
Administrators as well as users make changes to a database. If you make any of the following structural changes, then perform a backup of the appropriate portion of your database immediately before and after completing the alteration:
The part of the database that you should back up depends on your archiving mode:
Many administrators find that regular whole database backups are not in themselves sufficient for a robust backup strategy. If you run in ARCHIVELOG mode, then you can back up the datafiles of an individual tablespace or even a single datafile. This option is useful if a portion of a database is used more extensively than others, for example, the SYSTEM tablespace and tablespaces that contain rollback segments.
By making more frequent backups of the extensively used datafiles of a database, you avoid a long recovery time. For example, you may make a whole database backup once a week on Sunday. If your database experiences heavy traffic during the week, a media failure on Friday can force you to apply a tremendous amount of redo data during recovery. If you had backed up your most frequently accessed tablespaces three times a week, you can apply a smaller number of changes to roll the restored file forward to the time of the failure.
If users are creating tables or indexes using the UNRECOVERABLE option, make backups after the objects are created. When tables and indexes are created as UNRECOVERABLE, Oracle does not log redo data, which means that you cannot recover these objects from existing backups.
See Also:
Oracle8i SQL Reference for information about the UNRECOVERABLE option of the CREATE TABLE ... AS SELECT and CREATE INDEX statements. |
After you have opened a database with the RESETLOGS option, Oracle recommends that you immediately perform a whole database backup. If you do not, and a disaster occurs, then you lose all changes made after opening the database.
See Also:
"What Is a RESETLOGS Operation?" for more information about RESETLOGS operations, and "Recovering a Pre-RESETLOGS Backup" to learn the special circumstances that allow you to recover a pre-RESETLOGS backup. |
You should store older backups for two basic reasons:
If you want to recover to a non-current time, then you need a database backup that completed before the desired time. For example, if you make backups on the 1st and 14th of February, then decide at the end of the month to recover your database to February 7th, you must use the February 1st backup.
For a database operating in NOARCHIVELOG mode, the backup that you use should be a consistent whole database backup. Of course, you cannot perform media recovery using this backup. For a database operating in ARCHIVELOG mode, your whole database backup:
For added protection, keep two or more database backups (with associated archived redo logs) previous to the current backup. Thus, if your most recent backups are not usable, you will not lose all of your data.
If your database is a node in a distributed database, all databases in the distributed database system should operate in the same archiving mode. Note the following consequences and constraints:
See Also:
"Opening the Database After Media Recovery" to learn about performing media recovery in distributed systems, and Oracle8i Distributed Database Systems for concepts and administration relating to distributed systems. |
Because the Oracle Export utility can selectively export specific objects, consider exporting portions or all of a database for supplemental protection and flexibility in a database's backup strategy. This strategy is especially useful for recovery catalog backups when using RMAN.
Note that Database exports are not a substitute for whole database backups and cannot provide the same complete recovery advantages that the built-in functionality of Oracle offers.
Although it may seem that you should back up online redo logs along with the datafiles and control file, this technique is dangerous. You should not back up online redo logs for the following reasons:
The danger in backing up online redo logs is that you may accidentally restore them while not intending to. A number of situations are possible in which restoring the online logs cause significant problems to the database. Following are two scenarios that illustrate how restoring backed up online logs severely compromises recovery.
When a crisis occurs, it is easy to make a simple mistake. DBAs and system administrators frequently encounter dangers during a database restore. When restoring the whole database, you can accidentally restore the online redo logs, thus overwriting the current logs with the older, useless backups. This action forces you to perform an incomplete recovery instead of the intended complete recovery, thereby losing the ability to recover valuable transactions contained in the overwritten redo logs.
You can unintentionally create multiple parallel redo log timelines for a single instance database. You can avoid this mistake, however, by making it so that the online logs cannot be restored. You must open the database with the RESETLOGS option, which effectively creates the new redo logs, and also a new database incarnation.
If you face a problem where the best course of action is to restore the database from a consistent backup and not perform any recovery, then you may think it is safe to restore the online logs and thereby avoid opening the database with the RESETLOGS option. The problem is that the database eventually generates a log sequence number that was already generated by the database during the previous timeline.
If you then face another disaster and need to restore from this backup and roll forward, you will find it difficult to identify which log sequence number is the correct one. If you had reset the logs, then you would have created a new incarnation of the database. You could only apply archived redo logs created by this new incarnation to this incarnation.
For example, say that the most recent archived log for database PROD has a log sequence number of 100. Assume that you restore a backup of the database along with backed up online redo logs and then do not open with the RESETLOGS option. Assume also that the restored online log is at log sequence 50. Eventually, the database archives a log with the log sequence number of 100--so you now have two copies of log 100 with completely different contents. If you are forced to recover this database, then you may inadvertently restore the wrong series of archived logs, thereby corrupting the database.
Oracle provides a variety of procedures and tools to assist you with recovery. To develop an effective recovery strategy, do the following:
Practice backup and recovery techniques in a test environment before and after you move to a production system. In this way, you can measure the thoroughness of your strategies and minimize problems before they occur in a real situation. Performing test recoveries regularly ensures that your archiving, backup, and recovery procedures work. It also helps you stay familiar with recovery procedures, so that you are less likely to make a mistake in a crisis.
If you use Recovery Manager, use the duplicate command to create a test database using backups of your production database. To learn how to duplicate a database, see Oracle8i Recovery Manager User's Guide and Reference.
Although media recovery is your primary concern when developing your recovery strategy, you should understand the basic types of non-media failures as well as the causes and solutions for each:
A statement failure is a logical failure in the handling of a statement in an Oracle program. The Oracle database server or the operating system usually returns an error code and a message when a statement failure occurs. Table 3-1 shows typical causes and resolutions for statement failures.
A user process failure is any failure in a user program accessing an Oracle database. User processes can fail for a wide variety of reasons. Some typical scenarios include:
In most cases, you do not need to act to resolve user process failures: the user process simply fails to function but does not affect Oracle and other user process. The PMON background process is usually sufficient for cleaning up after an abnormally terminated user process.
Users errors are any mistakes that users make in adding data to or deleting data from the database. Typical causes of user error are:
If you have a logical backup of a table from which data has been lost, sometimes you can simply import it back into the table. Depending on the scenario, however, you may have to perform some type of incomplete media recovery to correct such errors.
You can perform either database point-in-time recovery (DBPITR) or tablespace point-in-time recovery (TSPITR). The following table explains the difference between these types of incomplete recovery:
Type | Description | Procedure |
---|---|---|
DBPITR |
For operating system recovery, see "Performing Incomplete Media Recovery". See Also: For RMAN recovery, see Oracle8i Recovery Manager User's Guide and Reference. |
|
TSPITR |
For operating system TSPITR, see Chapter 7, "Performing Operating System Tablespace Point-in-Time Recovery". See Also: For RMAN TSPITR, see Oracle8i Recovery Manager User's Guide and Reference. |
Instance failure occurs when an instance abnormally terminates. An instance failure can occur because:
Fortunately, Oracle performs instance recovery automatically: all you need to do is restart the database. Oracle automatically detects that the database was not shut down cleanly, then applies committed and uncommitted redo records in the redo log to the datafiles and rolls back uncommitted data. Finally, Oracle synchronizes the datafiles and control file and opens the database.
Media failure is the biggest threat to your data. A media failure is a physical problem that occurs when a computer unsuccessfully attempts to read from or write to a file necessary to operate the database. Common types of media problems include:
The technique you use to recover from media failure depends heavily on the type of media failure that occurred. For example, the strategy you use to recover from a corrupted datafile is different from the strategy for recovering from the loss of your control file.
The basic steps for media recovery are:
Oracle8i Recovery Manager User's Guide and Reference to learn how to perform media recovery using RMAN, and Chapter 5, "Performing Media Recovery" to learn how to perform media recovery using operating system methods.
See Also:
The first step is to determine what to recover. Some types of failure are obvious: for example, the hardware crashes and you need to recover the entire database. In other cases, a single datafile becomes corrupted. Often you can use the table V$RECOVER_FILE to determine what requires recovery.
When you perform media recovery, you choose either complete recovery or incomplete recovery. Following is a list of media recovery operations:
Complete media recovery includes the application of all necessary redo or incremental backups ever generated for the particular incarnation of the database being recovered. Complete media recovery can be performed on offline datafiles while the database is open. Types of complete media recovery are:
Incomplete media recovery, also called point-in-time recovery (PITR), produces a version of the database as it was at some time in the past. Incomplete media recovery must either continue on to become complete media recovery, or be terminated by a RESETLOGS operation that creates a new incarnation of the database. The database must be closed for incomplete media recovery operations. You can perform:
One important and special type media recovery is tablespace point-in-time recovery (TSPITR). TSPITR enables you to recover one or more tablespaces to a point-in-time that is different from the rest of the database.
The type of recovery method you use depends on the situation. Table 3-2 displays typical scenarios and strategies.
The method you use to restore backups depends on whether you use RMAN or operating system methods to back up your data. If you use operating system methods, then you need to identify which files need to be restored and manually copy the backups to their necessary location. If you use RMAN, then issue a restore command and let RMAN take over the transfer of data.
If the database is shut down and you restore one of the datafiles with a backup, either because of a media failure or because for some reason you want to recover the database to a non-current time, Oracle detects an inconsistency between the checkpoint SCN in the datafile headers and the datafile header checkpoint SCNs recorded in the control file at database open time. Oracle then selects the lowest checkpoint SCN recorded in the control file and datafile headers and asks you to begin media recovery starting from a specified log sequence number. You cannot open the database if any of the online datafiles needs media recovery.
There is only one case in which Oracle will tell you that you need to perform media recovery when you do not. If a tablespace is in hot backup mode because you issued the ALTER TABLESPACE ... BEGIN BACKUP statement and the system crashes, then on the next startup Oracle will issue a message stating that media recovery is required. Media recovery is not really required here, however, since you did not restore a backup; in this case, avoid media recovery by issuing the ALTER DATAFILE ... END BACKUP statement. Note that RMAN backups do not have this problem.
See Also:
Oracle8i Recovery Manager User's Guide and Reference to learn how to restore backups using RMAN, "Restoring Files" to learn how to restore datafiles using operating system methods. |
You have a choice between two basic methods for recovering physical files. You can:
Obviously, the recovery method you choose is contingent on which backup method you use. For example, if you backed up your files using:
RMAN is a powerful tool that can aid in backup and recovery operations. Using RMAN for recovery allows you to:
Oracle8i Recovery Manager User's Guide and Reference to learn how to perform RMAN recovery.
See Also:
If you do not use RMAN, then you can use operating system methods to restore your backups and SQL*Plus statements to perform media recovery. You can use SQL*Plus statements to:
You can use three basic SQL*Plus statements for recovery:
Note that each of these is also a sub-clause of an ALTER DATABASE statement. Oracle recommends using the SQL*Plus RECOVER statement rather than the ALTER DATABASE statement with the RECOVER clause. For more information about the SQL*Plus RECOVER statement, see SQL*Plus User's Guide and Reference.
Each statement uses the same criteria to determine whether files are recoverable. If Oracle cannot get the lock for a file it is attempting to recover, it signals an error. This signal prevents two recovery sessions from recovering the same file and prevents media recovery of a file that is in use.
See Also:
"Using Media Recovery Statements" to learn about the differences between the SQL ALTER DATABASE RECOVER and SQL*Plus RECOVER statements. |
|
![]() Copyright © 1999 Oracle Corporation. All Rights Reserved. |
|