Professional Documents
Culture Documents
• By Rajendra Gutta
Having the right backup and recovery procedures is crucial to the operation of any
database. It is the responsibility of the database administrator to protect the database from
system faults, crashes, and natural calamities resulting from a variety of circumstances.
Learn how to choose the best backup and recovery mechanism for your Oracle system.
Having the right backup and recovery procedures is the lifeblood of
any database. Companies live on data, and, if that data is not
available, the whole company collapses. As a result, it is the
responsibility of the database administrator to protect the database
from system faults, crashes, and natural calamities resulting from a
variety of circumstances.
The choice of a backup and recovery mechanism depends mainly on the
following factors:
• Database mode (ARCHIVELOG, NOARCHIVELOG)
• Size of the database
• Backup and recovery time
• uptime
• Type of data (OLTP, DSS, Data Warehouse).
The types of backup are
• Offline backup (Cold or closed database backup)
• Online backup (Hot or open database backup)
• Logical export
Logical exports create an export file that contains a list of SQL statements to recreate the
database. Export is performed when the database is open and does not affect users work. Offline
backups can only be performed when the database is shut down cleanly, and the database will be
unavailable to users while the offline backup is being performed. Online backups are performed
when the database is open, and it does not affect users work. The database needs to run in
ARCHIVELOG mode to perform online backups.
The database can run in either ARCHIVELOG mode or NOARCHIVELOG mode. In ARCHIVELOG
mode, the archiver (ARCH) process archives the redo log files to the archive destination directory.
These archive files can be used to recover the database in the case of a failure. In
NOARCHIVELOG mode, the redo log files are not archived.
When the database is running in ARCHIVELOG mode, the choice can be one or more of the
following:
• Export
• Hot backup
• Cold backup
When the database is running in NOARCHIVELOG mode, the choice of backup is as follows:
• Export
• Cold backup
Cold Backup
Offline or cold backups are performed when the database is completely shutdown. The
disadvantage of an offline backup is that it cannot be done if the database needs to be run 24/7.
Additionally, you can only recover the database up to the point when the last backup was made
unless the database is running in ARCHIVELOG mode.
The general steps involved in performing a cold backup are shown in Figure 3.1. These general
steps are used in writing cold backup scripts for Unix and Windows NT.
Figure 3.1 Steps for cold backup.
The steps in Figure 3.1 are explained as follows.
Step 1—Generating File List
An offline backup consists of physically copying the following files:
• Data files
• Control files
• Init.ora and config.ora files
CAUTION
Backing up online redo log files is not advised in all cases, except when performing cold backup
with the database running in NOARCHIVELOG mode. If you make a cold backup in ARCHIVELOG
mode do not backup redo log files. There is a chance that you may accidentally overwrite your real
online redo logs, preventing you from doing a complete recovery.
If your database is running in ARCHIVELOG mode, when you perform cold backup you should
also backup archive logs that exist.
Before performing a cold backup, you need to know the location of the files that need to be backed
up. Because the database structure changes day to day as more files get added or moved
between directories, it is always better to query the database to get the physical structure of
database before making a cold backup.
To get the structure of the database, query the following dynamic data dictionary tables:
• V$datafile Lists all the data files used in the database
SQL>select name from v$datafile;
• Backup the control file and perform a trace of the control file using
SQL>alter database backup controlfile to '/u10/backup/control.ctl';
SQL>alter database backup controlfile to trace;
• Init.ora and config.ora Located under $ORACLE_HOME/dbs directory
Hot Backup
An online backup or hot backup is also referred to as ARCHIVE LOG backup. An online backup
can only be done when the database is running in ARCHIVELOG mode and the database is open.
When the database is running in ARCHIVELOG mode, the archiver (ARCH) background process
will make a copy of the online redo log file to archive backup location.
An online backup consists of backing up the following files. But, because the database is open
while performing a backup, you have to follow the procedure shown in Figure 3.2 to backup the
files:
• Data files of each tablespace
• Archived redo log files
• Control file
• Init.ora and config.ora files
Step 1—Put the tablespace in the Backup mode and copy the data files.
Assume that your database has two tablespaces, USERS and TOOLS. To back up the files for
these two tablespaces, first put the tablespace in backup mode by using the ALTER statement as
follows:
SQL>alter tablespace USERS begin backup;
After the tablespace is in Backup mode, you can use the SELECT statement to list the data files
for the USERS tablespace, and the copy (cp) command to copy the files to the backup location.
Assume that the USERS tablespace has two data files—users01.dbf and users02.dbf.
SQL>select file_name from dba_data_files
where tablespace_name='USERS';
$cp /u01/oracle/users01.dbf /u10/backup
$cp /u01/oracle/users01.dbf /u10/backup
The following command ends the backup process and puts the tablespace back in normal mode.
SQL>alter tablespace USERS end backup;
You have to repeat this process for all tablespaces. You can get the list of tablespaces by using the
following SQL statement:
SQL>select tablespace_name from dba_tablespaces;
Logical Export
Export is the single most versatile utility available to perform a backup of the database, de-
fragment the database, and port the database or individual objects from one operating system to
another operating system.
Understand scripting
This chapter requires understanding of basic Unix shell and DOS batch programming techniques
that are described in Chapter 2 "Building Blocks." That chapter explained some of the common
routines that will be used across most of the scripts presented here.
This book could have provided much more simple scripts. But, considering standardization across
all scripts and the reusability of individual sections for your own writing of scripts, I am focusing on
providing a comprehensive script, rather than a temporary fix. After you understand one script, it is
easy to follow the flow for the rest of the scripts.