DbBackupAndRecov UsgCConf 2006
DbBackupAndRecov UsgCConf 2006
DbBackupAndRecov UsgCConf 2006
Mingguang Xu
STATUS
------------
OPEN
Backup Overviews
DB Backup
Logical Physical
• User managed: shutdown database, and copy the backup files by using OS
tools.
• Move the backup files off the disk to other permanent storage media
Why Use RMAN
1. RMAN is a database backup utility that comes with the Oracle database, at no extra
cost
2. RMAN is aware of the internal structure of Oracle datafiles and controlfiles, and knows
how to take consistent copies of data blocks even as they are being written to
3. For online backup, It does not require the database in backup mode. Therefore RMAN
does not cause a massive increase in generated redo
4. Backs up only those blocks that have held or currently hold data. RMAN backups of
datafiles are generally smaller than the datafiles themselves. In contrast, OS
copies of datafiles have the same size as the original datafiles
• In the former, backup information and RMAN scripts are stored in another
database known as the RMAN catalog.
• OIR uses nocatalog mode, as this is a perfectly valid choice for sites with a
small number of databases.
Start RMAN
RMAN can be invoked from the command line on the database host machine
RMAN>
RMAN Configuration
• Retention Policy: This instructs RMAN on the backups that are eligible for
deletion. For example: A retention policy with redundancy 2 would mean that
two backups - the latest and the one prior to that - should be retained. All
other backups are candidates for deletion. Retention policy can also be
configured based on time - check the docs for details on this option.
• Default Device Type: This can be "disk" or "sbt" (system backup to tape).
We will backup to disk and then have our OS backup utility copy the
completed backup, and other supporting files, to a permanent storage.
• Controlfile Autobackup: This can be set to "on" or "off". When set to "on",
RMAN takes a backup of the controlfile AND server parameter file each time
a backup is performed. "off" is the default.
• Parallelism: This tells RMAN how many server processes you want
dedicated to performing the backups.
• Device Type Format: This specifies the location and name of the backup
files. We need to specify the format for each channel. The "%U" ensures
that Oracle appends a unique identifier to the backup file name. The
MAXPIECESIZE attribute sets a maximum file size for each file in the
backup set.
• SCN Saarbruecken, Germany - Ensheim (Airport Code) • SCN Shipping Control Number
• SCN Saskatchewan Communications Network • SCN Ships Construction, Navy
• SCN Satellite Communications Network • SCN Software Change Notice
• SCN Satellite Control Network • SCN Southern Command Network
• SCN Scan • SCN Special Care Nursery
• SCN Schwarzkopf Coaster Net (website) • SCN Specification Change Notice
• SCN Scientology • SCN Spoken Called Number (Sprint - Voicecard)
• SCN Scottish Candidate Number (unique serial number • SCN Starting Cluster Number
given to each student sitting Scottish Examinations) • SCN Stock Code Number
• SCN Search Control Number • SCN Structured Cable Network
• SCN Sears Communications Network • SCN Student Center Network (forum)
• SCN Sensor Control Network • SCN Student Club Nights
• SCN Sequential Contact Number • SCN Subcontract Change Notice
• SCN Service Channel Network (Ciena) • SCN Subcutaneous Nodule
• SCN Service Circuit Node (AT&T) • SCN Supply Chain Navigator
• SCN Service Convergence Network (Pannaway • SCN Suprachiasmatic Nucleus
Technologies) • SCN Surrender Charge Notice (insurance)
• SCN Severe Congenital Neutropenia • SCN Sustainable Communities Network
• SCN Shanghai Cable Networks • SCN Switched Circuit Network
• SCN Shipbuilding & Conversion, Navy • SCN Symmetrical Condensed Node
• SCN Shipbuilding and Conversion, Navy • SCN System Change Notice
• SCN Shipping Control Note
• SCN System Change Number (Oracle)
Case Study Assumptions
DB Server
Case 1. Recovery From Missing/Corrupted Datafile
SQL> startup
ORACLE instance started.
Total System Global Area 131555128 bytes
Fixed Size 454456 bytes
Variable Size 88080384 bytes
Database Buffers 41943040 bytes
Redo Buffers 1077248 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
If you know the data file name, you can find out the file number by:
The database must be mounted before any datafile recovery can be done.
In the above scenario, the database is already in the mount state before the RMAN
session is initiated. If the database is not mounted, you should issue a "startup mount“
command before attempting to restore the missing datafile.
If the database is already open when datafile corruption is detected, you can recover the
datafile without shutting down the database. The only additional step is to take the
relevant tablespace offline before starting recovery. In this case you would perform
recovery at the tablespace level. The commands are:
Here we have used the SQL command, which allows us to execute arbitrary SQL from
within RMAN.
Case 2: Recovery From Block Corruption
If a redo log is missing, it should be restored from a multiplexed copy, if possible. This is the only
way to recover without any losses. Here's an example, where I attempt to startup from SQLPlus
when a redo log is missing:
SQL> startup
ORACLE instance started.
SQL>
Case 3 - continued
In this case an incomplete recovery is the best we can do. We will lose all transactions from the
missing log and all subsequent logs.
The error message indicates that members of log group 3 are missing. We don't have a copy of this
file, so we know that an incomplete recovery is required.
The first step is to determine how much can be recovered. In order to do this, we query the V$LOG
view (when in the mount state) to find the system change number (SCN) that we can recover to
(Reminder: the SCN is a monotonically increasing number that is incremented whenever a commit is
issued):
• The FIRST_CHANGE# is the first SCN stamped in the missing log. This implies that
the last SCN stamped in the previous log is 370254 (FIRST_CHANGE#-1). This is
the highest SCN that we can recover to. In order to do the recovery we must first
restore ALL datafiles to this SCN, followed by recovery (also up to this SCN). This is
an incomplete recovery, so we must open the database resetlogs after we're done.
Here's a transcript of the recovery session (typed commands in bold, comments in
italics, all other lines are RMAN feedback):
C:\>rman target /
Recovery Manager: Release 9.2.0.4.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database: ORCL (DBID=1507972899)
--Restore ENTIRE database to determined SCN
Case 4 - continued
--Recover database
• The entire database must be restored to the SCN that has been determined by
querying v$log.
• All changes beyond that SCN are lost. This method of recovery should be used
only if you are sure that you cannot do better. Be sure to multiplex your redo logs,
and (space permitting) your archived logs!
• The database must be opened with RESETLOGS, as a required log has not been
applied. This resets the log sequence to zero, thereby rendering all prior backups
worthless. Therefore, the first step after opening a database RESETLOGS is to
take a fresh backup. Note that the RESETLOGS option must be used for any
incomplete recovery.
Case 5. Recovery From Corrupted One Control File
• On startup Oracle must read the control file in order to find out
where the datafiles and online logs are located. Oracle expects to
find control files at locations specified in the CONTROL_FILE
initialisation parameter. The instance will fail to mount the database
if any one of the control files are missing or corrupt
SQL> startup
Solution:
• Requires that all logs (archived and current online logs) since the
last backup are available.
• The logs are required because all datafiles must also be restored
from backup.
• The database will then have to be recovered up to the time the
control files went missing.
• This can only be done if all intervening logs are available.
Case 6 - continued
• -- Connect to RMAN
C:\>rman target /
RMAN> set dbid 1507972899
• --restore controlfile from autobackup. The backup is not at the default
--location so the path must be specified
RMAN> restore controlfile from /‘backupDir/CTL_SP_BAK_C-1507972899-20050124-00';
• --Database must be recovered because all datafiles have been restored from
-- backup
RMAN> recover database;
• After recovery using a backup controlfile, all temporary files associated with locally-
managed tablespaces are no longer available. You can check that this is so by
querying the view V$TEMPFILE - no rows will be returned. Therefore tempfiles must
be added (or recreated) before the database is made available for general use. In the
case at hand, the tempfile already exists so we merely add it to the temporary
tablespace. This can be done using SQLPlus or any tool of your choice:
SQL> alter tablespace temp add tempfile
‘/DBfileDir/TEMP01.DBF';
Case 7. Recovery From Missing spfile
1. Set DBID
RMAN> set dbid 1507972899
2. To restore the spfile, you first need to startup the database in the nomount state. This
starts up the database using a dummy parameter file.
4. Restart database