- •About the Authors
- •Contents at a Glance
- •Contents
- •Table of Exercises
- •Introduction
- •Assessment Test
- •Answers to Assessment Test
- •What Is ASM?
- •Working with the ASM Instance
- •Overview of ASM Data Dictionary Views
- •Using ASM Storage
- •Using RMAN with ASM
- •Summary
- •Exam Essentials
- •Review Questions
- •Answers to Review Questions
- •Understanding the Oracle Database as It Relates to Backup and Recovery
- •Performing Oracle Offline Backups
- •Performing Oracle Online Backups
- •Backing Up the Control File
- •Summary
- •Exam Essentials
- •Review Questions
- •Answers to Review Questions
- •Performing Incomplete Recoveries
- •Performing Other Types of Recoveries
- •Summary
- •Exam Essentials
- •Review Questions
- •Answers to Review Questions
- •Why Use RMAN?
- •Exploring the RMAN Architecture
- •Connecting to RMAN
- •Configuring RMAN for Use
- •Backing Up Your Database with RMAN
- •Summary
- •Exam Essentials
- •Review Questions
- •Answers to Review Questions
- •Introducing the Recovery Catalog
- •Creating the Recovery Catalog User and Schema Objects
- •Using a Recovery Catalog
- •Maintaining the Recovery Catalog
- •Using the RMAN Virtual Private Catalog
- •Summary
- •Exam Essentials
- •Review Questions
- •Answers to Review Questions
- •RMAN Database-Recovery Basics
- •Using Image Copies to Recover Your Database
- •Other Basic Recovery Topics
- •Summary
- •Exam Essentials
- •Review Questions
- •Answers to Review Questions
- •Summary
- •Exam Essentials
- •Review Questions
- •Answers to Review Questions
- •Switching Between RMAN Incarnations
- •Overview of RMAN Database Duplication
- •Performing an RMAN Tablespace Point-in-Time Recovery
- •Summary
- •Exam Essentials
- •Review Questions
- •Answers to Review Questions
- •Overview of Flashback Technology
- •Using Automatic Undo Management
- •Using Flashback Technologies
- •Using Additional Flashback Operations
- •Summary
- •Exam Essentials
- •Review Questions
- •Answers to Review Questions
- •Diagnosing the Database
- •Managing Database Performance
- •Summary
- •Exam Essentials
- •Review Questions
- •Answers to Review Questions
- •Managing Memory
- •Managing Space
- •Managing Resources
- •Summary
- •Exam Essentials
- •Review Questions
- •Answers to Review Questions
- •Automating Tasks with the Scheduler
- •Exploring the Scheduler Architecture
- •Exploring Common Administration Tools
- •Using Scheduler Jobs
- •Using Scheduler Programs
- •Using Schedules
- •Creating Lightweight Jobs
- •Using Job Chains
- •Using Scheduler Windows
- •Creating and Using Job Classes
- •Using Advanced Scheduler Concepts to Prioritize Jobs
- •Using Scheduler Views
- •Summary
- •Exam Essentials
- •Review Questions
- •Answers to Review Questions
- •An Overview of Globalization Support
- •Using NLS Parameters
- •Using Datetime Datatypes
- •Using Linguistic Sorts and Searches
- •Summary
- •Exam Essentials
- •Review Questions
- •Answers to Review Questions
- •Lab 1.1: Creating an ASM Instance
- •Lab 1.2: Creating ASM Disk Groups
- •Lab 1.3: Using ASM Disk Groups from a Database
- •Lab 2.2: Putting the Database in ARCHIVELOG Mode
- •Lab 2.3: Executing a Manual Online (Hot) Backup
- •Lab 3.1: Executing a Time-Based Point-in-Time Recovery
- •Lab 3.2: Recovering from Control-File Loss with a Backup Control File
- •Lab 3.3: Recovering from Loss of the Current Online Redo Log
- •Lab 4.1: Creating an RMAN Offline Backup
- •Lab 4.2: Creating an RMAN Incremental Backup
- •Lab 4.3: Creating an Image-Copy Backup
- •Lab 5.1: Implementing RVPC
- •Lab 6.1: Restoring a Datafile Online
- •Lab 6.2: Performing a Change-Based Recovery with RMAN
- •Lab 6.3: Restoring a Control File from an Autobackup
- •Lab 7.1: Monitoring RMAN Backups
- •Lab 7.2: One of My Backups Is Missing!
- •Lab 8.1: Duplicating a Database Using Active Database Duplication
- •Lab 8.2: Duplicating a Database Using Backup-Based Duplication to a Different Point in Time
- •Lab 9.1: Using the Recycle Bin
- •Lab 9.3: Using Flashback Data Archive
- •Lab 10.1: Using Support Workbench to Report a Problem to Oracle Support
- •Lab 11.1: Exporting a Transportable Tablespace
- •Lab 11.2: Testing Resumable Space Allocation
- •Lab 11.3: Manually Configuring the SGA
- •Lab 12.1: Creating a Local External Job
- •Lab 12.2: Creating a Job Window
- •Lab 13.1: Using the Locale Builder to Create a New Linguistic Sort
- •Lab 13.2: Setting NLS Parameters
- •Lab 13.3: Performing Linguistic Sorts
- •What You’ll Find on the CD
- •System Requirements
- •Using the CD
- •Troubleshooting
- •Glossary
- •Index
Backing Up Your Database with RMAN |
179 |
E x e r c i s e 4 .1 ( c o nt i n u e d )
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
5.Configure for compressed backup sets:
RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO COMPRESSED BACKUPSET;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO COMPRESSED BACKUPSET;
new RMAN configuration parameters are successfully stored
6.Create a directory to hold the snapshot control file (you will want to use your own directory paths, of course):
RMAN> host “mkdir \oracle01”; host command complete
RMAN> host “mkdir \oracle01\snapshot”; host command complete
7.Configure RMAN so the snapshot control file will be created in the new directory:
RMAN> CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘c:\oracle01\snapshot’; new RMAN configuration parameters:
CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘c:\oracle01\snapshot’; new RMAN configuration parameters are successfully stored
8.Exit RMAN:
RMAN> exit
Recovery Manager complete.
Backing Up Your Database with RMAN
We will discuss backups of your database using RMAN in the following sections. We will first talk about the different types of backups that you can make with RMAN. Then we will discuss what you can back up using RMAN, such as the database, archived redo logs, and so forth.
180 Chapter 4 n Configuring and Backing Up Using RMAN
Using the RMAN Command Line
Like SQL and SQL*Plus, RMAN has its own unique command set. You use these commands to do a number of things:
NN |
Configure RMAN |
|
|
NN |
Back up database structures (tablespaces, datafiles, control files, and so on) |
NN |
Restore and recover your database |
NN |
Produce various reports and lists that contain backup-related information. |
NN |
Create duplicate databases |
NN |
Restore specific tablespaces |
This is just a partial list of all the things RMAN can do for you. Table 4.3 describes the RMAN commands you will need to be aware of for the OCP exam.
Ta b l e 4 . 3 RMAN Commands
RMAN Command |
Description |
|
|
@ |
Run a command file. |
@@ |
Run a command file in the same directory as another com- |
|
mand file that is currently running. The @@ command differs |
|
from the @ command only when run from within a com- |
|
mand file. |
ALLOCATE CHANNEL |
Establish a channel, which is a connection between RMAN |
|
and a database instance. |
ALLOCATE CHANNEL FOR |
Allocate a channel in preparation for issuing maintenance |
MAINTENANCE |
commands such as DELETE. |
allocOperandList |
A subclause that specifies channel control options such as |
|
PARMS and FORMAT. |
ALTER DATABASE |
Mount or open a database. |
archivelogRecordSpecifier Specify a range of archived redo-log files.
BACKUP |
Back up database files, copies of database files, archived |
|
logs, or backup sets. |
BLOCKRECOVER |
Recover an individual data block or set of data blocks within |
|
one or more datafiles. |
CATALOG |
Add information about a datafile copy, archived redo log, or |
|
control file copy to the repository. |
|
Backing Up Your Database with RMAN |
181 |
Ta b l e 4 . 3 RMAN |
Commands (continued) |
|
|
|
|
RMAN Command |
Description |
|
|
|
|
CHANGE |
Mark a backup piece, image copy, or archived redo log as |
|
|
having the status UNAVAILABLE or AVAILABLE; remove the |
|
|
repository record for a backup or copy; override the reten- |
|
|
tion policy for a backup or copy. |
|
completedTimeSpec |
Specify a time range during which the backup or copy com- |
|
|
pleted. |
|
CONFIGURE |
Configure persistent RMAN settings. These settings apply |
|
|
to all RMAN sessions until explicitly changed or disabled. |
|
CONNECT |
Establish a connection between RMAN and a target, auxil- |
|
|
iary, or recovery catalog database. |
|
connectStringSpec |
Specify the username, password, and net service name for |
|
|
connecting to a target, recovery catalog, or auxiliary data- |
|
|
base. The connection is necessary to authenticate the user |
|
|
and identify the database. |
|
CONVERT |
Convert datafile formats for transporting tablespaces |
|
|
across platforms. |
|
CREATE CATALOG |
Create the schema for the recovery catalog. |
|
CREATE SCRIPT |
Create a stored script and store it in the recovery catalog. |
|
CROSSCHECK |
Determine whether files managed by RMAN, such as |
|
|
archived logs, datafile copies, and backup pieces, still exist |
|
|
on disk or tape. |
|
datafileSpec |
Specify a datafile by filename or absolute file number. |
|
DELETE |
Delete backups and copies, remove references to them |
|
|
from the recovery catalog, and update their control-file |
|
|
records to status DELETED. |
|
DELETE SCRIPT |
Delete a stored script from the recovery catalog. |
|
deviceSpecifier |
Specify the type of storage device for a backup or copy. |
|
DROP CATALOG |
Remove the schema from the recovery catalog. |
|
DROP DATABASE |
Delete the target database from disk and unregister it. |
|
182 |
Chapter 4 n Configuring and Backing Up Using RMAN |
|
Ta b l e 4 . 3 RMAN Commands (continued) |
||
|
|
|
RMAN Command |
Description |
|
|
|
|
DUPLICATE |
|
Use backups of the target database to create a duplicate |
|
|
database that you can use for testing purposes or to create |
|
|
a standby database. |
EXECUTE SCRIPT |
Run an RMAN stored script. |
|
EXIT |
|
Quit the RMAN executable. |
fileNameConversionSpec |
Specify patterns to transform source to target filenames |
|
|
|
during BACKUP AS COPY, CONVERT, and DUPLICATE. |
FLASHBACK |
|
Return the database to a previous state as defined by a pre- |
|
|
vious time or system change number (SCN). |
formatSpec |
Specify a filename format for a backup or copy. |
|
HOST |
|
Invoke an operating-system command-line subshell from |
|
|
within RMAN or run a specific operating-system command. |
keepOption |
Specify that a backup or copy should or should not be |
|
|
|
exempt from the current retention policy. |
LIST |
|
Produce a detailed listing of backup sets or copies. |
listObjList |
A subclause used to specify which items will be displayed |
|
|
|
by the LIST command. |
maintQualifier |
A subclause used to specify additional options for mainte- |
|
|
|
nance commands such as DELETE and CHANGE. |
maintSpec |
|
A subclause used to specify the files operated on by main- |
|
|
tenance commands such as CHANGE, CROSSCHECK, and |
|
|
DELETE. |
obsOperandList |
A subclause used to determine which backups and copies |
|
|
|
are obsolete. |
PRINT SCRIPT |
Display a stored script. |
|
QUIT |
|
Exit the RMAN executable. |
recordSpec |
A subclause used to specify the objects on which the main- |
|
|
|
tenance commands should operate. |
|
Backing Up Your Database with RMAN |
183 |
Ta b l e 4 . 2 RMAN |
Commands Description (continued) |
|
|
|
|
RMAN Command |
Description |
|
|
|
|
RECOVER |
Apply redo logs and incremental backups to datafiles |
|
|
restored from backup or datafile copies in order to update |
|
|
them to a specified time. |
|
REGISTER |
Register the target database in the recovery catalog. |
|
RELEASE CHANNEL |
Release a channel that was allocated with an ALLOCATE |
|
|
CHANNEL command. |
|
releaseForMaint |
Release a channel that was allocated with an ALLOCATE |
|
|
CHANNEL FOR MAINTENANCE command. |
|
REPLACE SCRIPT |
Replace an existing script stored in the recovery catalog. If |
|
|
the script does not exist, then REPLACE SCRIPT creates it. |
|
REPORT |
Perform detailed analyses of the content of the recovery |
|
|
catalog. |
|
RESET DATABASE |
Inform RMAN that the SQL statement ALTER DATABASE |
|
|
OPEN RESETLOGS has been executed and that a new incarna- |
|
|
tion of the target database has been created, or reset the |
|
|
target database to a prior incarnation. |
|
RESTORE |
Restore files from backup sets or from disk copies to the |
|
|
default or to a new location. |
|
RESYNC |
Perform a full resynchronization, which creates a snapshot |
|
|
control file and then copies any new or changed informa- |
|
|
tion from that snapshot control file to the recovery catalog. |
|
RUN |
Execute a sequence of one or more RMAN commands, |
|
|
which are one or more statements executed within the |
|
|
braces of a RUN block. |
|
SEND |
Send a vendor-specific quoted string to one or more spe- |
|
|
cific channels. |
|
SET |
Set the value of various attributes that affect RMAN behav- |
|
|
ior for the duration of a RUN block or a session. |
|
SHOW |
Display the current CONFIGURE settings. |
|
SHUTDOWN |
Shut down the target database. This command is equiva- |
|
|
lent to the SQL*Plus SHUTDOWN command. |
|
184 |
Chapter 4 n Configuring and Backing Up Using RMAN |
|
Ta b l e 4 . 2 RMAN |
Commands Description (continued) |
|
|
|
|
RMAN Command |
Description |
|
|
|
|
SPOOL |
|
Write RMAN output to a log file. |
SQL |
|
Execute a SQL statement from within RMAN. |
STARTUP |
|
Start up the target database. This command is equivalent to |
|
|
the SQL*Plus STARTUP command. |
SWITCH |
|
Specify that a datafile copy is now the current datafile; that |
|
|
is, the datafile pointed to by the control file. This command |
|
|
is equivalent to the SQL statement ALTER DATABASE RENAME |
|
|
FILE as it applies to datafiles. |
UNREGISTER DATABASE |
Unregister a database from the recovery catalog. |
|
untilClause |
A subclause specifying an upper limit by time, SCN, or log |
|
|
|
sequence number. This clause is usually used to specify the |
|
|
desired point in time for an incomplete recovery. |
UPGRADE CATALOG |
Upgrade the recovery-catalog schema from an older version |
|
|
|
to the version required by the RMAN executable. |
VALIDATE |
|
Examine a backup set and report whether its data is intact. |
|
|
RMAN scans all of the backup pieces in the specified backup |
|
|
sets and looks at the checksums to verify that the contents |
|
|
can be successfully restored. |
|
|
|
Types of RMAN Backups
There are two principle types of RMAN backups. The first type is called backup sets. Backup sets are a very flexible way of backing up your Oracle database. The downside is that backup sets are not direct copies of Oracle database datafiles. As a result, you need RMAN to put the backup sets back together to restore your database.
Oracle also supports image copies. Image copies are direct copies of database datafiles. Image copies offer faster recovery options but typically take up a great deal more space. In the following sections, we will address these two types of RMAN backups in more detail.
RMAN Backup Sets
By default, when you create a backup in RMAN, it writes the backups to physical files. These physical files are called backup set pieces (RMAN can also create backups called
Backing Up Your Database with RMAN |
185 |
image copies, which we will discuss later in this section). A given backup may create more than one backup set piece. A collection of related backup set pieces is called a backup set. A backup set is a logical entity that is used to maintain the association of independent backup set pieces.
In addition to multiple backup set pieces, you may have more than one backup set. This occurs when you parallelize a backup. Each channel will represent one backup set, each with its own backup set pieces. New backup sets will also be created on a channel if a backup set exceeds the backup set size limitations.
Note that a given datafile can span backup set pieces but cannot span backup sets. The ability of a given datafile to span backup set pieces is known as multiplexing. Multiplexing is another form of parallelization, as it allows RMAN to read from multiple datafiles in parallel and write them to a single backup set piece. Thus a given backup set piece may have data from many datafiles in it.
In the default RMAN configuration, a given tablespace/datafile backup may find itself in more than one backup set piece. However, each individual tablespace/datafile backup can be associated with only a single RMAN backup set and thus will be backed up by only one channel.
Oracle Database 11g has a new feature called multisection backups. Multisection backups allow you to parallelize the backup of large datafiles (bigfile tablespaces or normal tablespaces). You may well find questions on multisection backups on your OCP exam.
Figure 4.2 demonstrates the relationship between backups, backup sets, and backup set pieces.
F i g u r e 4 . 2 Relationship between RMAN backups, backup sets, and backup set pieces
Backup
|
|
|
|
|
|
|
|
|
|
|
|
Backup |
|
|
Logical |
|
|
|
Backup |
|
|
|
|
|
|
|
|
|||||
|
Set |
|
|
|
|
|
|
Set |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Backup |
|
Backup |
|
|
Physical |
|
|
Backup |
|
Backup |
|
|
|
|
|
|
|
|||||
|
Set |
|
Set |
|
|
Files |
|
|
Set |
|
Set |
|
Piece |
|
Piece |
|
|
|
|
|
Piece |
|
Piece |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 Chapter 4 n Configuring and Backing Up Using RMAN
RMAN Image Copies
RMAN image copies are one-to-one copies of database datafiles. When you do an imagecopy backup of your database, you will receive no benefits of compression, so the disk-space requirement is a one-to-one requirement. Image copies must be made to disk. Figure 4.3 shows the difference between image and regular backups.
F i g u r e 4 . 3 Image vs. regular backups
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Original Datafile |
Regular RMAN backupset |
|
|
Image Copy |
|
The upside to an image copy is that it can be much faster to restore. RMAN will always choose to restore image copies over backup sets if an image copy is available. In fact, using the switch to copy command makes it even faster, as RMAN will simply switch to the image copy on disk and start using that copy (applying redo as required). To make an image copy, use the backup as copy command, as shown in this example:
RMAN> Backup as copy database;
You can also make image copies of datafiles or tablespaces, as shown in these examples:
RMAN>backup as copy datafile 4;
RMAN>Backup as copy tablespace users;
If you prefer to always use image copies rather than backup sets, you can configure RMAN to do so by default with the configure command, as seen here:
configure device type disk backup type to copy;
RMAN can use a mixture of image copies, incremental backups, and archived redo logs when performing recovery (which we will discuss in more detail in Chapter 5). This can make total recovery of your database, a tablespace, or a datafile much quicker.
RMAN Offline Backups
We discussed manual offline backups in Chapter 2. Offline backups in RMAN are not much different except that you use the RMAN interface to actually do the backup rather than an OS file-copy utility. You will still need to close the database, but your backup will be done with the database in mount mode rather than completely shut down.
No parameter-file adjustments are required for an RMAN offline backup. We recommend that you configure and use the FRA (discussed earlier in this chapter) even if you are doing
Backing Up Your Database with RMAN |
187 |
offline backups. This makes for a standardized backup location and also allows the Oracle database to manage the overall backup space utilization more efficiently.
To perform an offline backup of your database with RMAN, follow these steps:
1.Start the RMAN client.
2.Shut down the database from the RMAN client, SQL*Plus, or OEM. The shutdown should be a consistent shutdown, so use the shutdown, shutdown immediate, or shutdown transactional command.
3.Start up the database in mount mode using the startup mount command.
4.Back up the database with the RMAN backup command:
RMAN>backup database;
5.When the backup is complete, open the database with the alter database open command.
RMAN Online Backups
For online backups in RMAN, the database must be configured in ARCHIVELOG mode (see Chapter 2 for more on configuring the database for ARCHIVELOG-mode operations). Once the database is configured properly, and RMAN is configured properly (as discussed earlier in this chapter), you can do online backups.
Online backups with RMAN are easy. You need to make sure the database and the archived redo logs are backed up; thus you issue the command backup database plus archivelog. That’s it. That command will create a recoverable backup of the database. This is known as a whole database backup.
If you want to delete the archived redo logs after the backup, you would append the delete input clause to the command. Other options are available depending on your needs.
In the following example we perform an online backup of our database using the backup as compressed backupset database plus archivelog delete input command. This will create a compressed backup of the database, backing up the archived redo logs and then deleting those backed-up archived redo logs after the backup is complete. Also note that we have configured control-file autobackups.
RMAN> backup as compressed backupset database plus archivelog delete input; Starting backup at 05-SEP-08
current log archived allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=131 device type=DISK
channel ORA_DISK_1: starting compressed archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=41 RECID=40 STAMP=664583178 input archived log thread=1 sequence=42 RECID=41 STAMP=664621168
188 Chapter 4 n Configuring and Backing Up Using RMAN
input archived log thread=1 sequence=43 RECID=42 STAMP=664650496 input archived log thread=1 sequence=44 RECID=43 STAMP=664655636 channel ORA_DISK_1: starting piece 1 at 05-SEP-08
channel ORA_DISK_1: finished piece 1 at 05-SEP-08
piece handle=C:\ORACLE\FLASH_RECOVERY_AREA\ORCL\BACKUPSET\2008_09_05\ O1_MF_ANNNN_TAG20080905T183357_4D3N085C_.BKP tag=TAG20080905T183357 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15 channel ORA_DISK_1: deleting archived log(s)
archived log file name=C:\ORACLE\ARCH\ORCL\ARC00041_0662757171.001 RECID=40 STAMP=664583178
archived log file name=C:\ORACLE\ARCH\ORCL\ARC00042_0662757171.001 RECID=41 STAMP=664621168
archived log file name=C:\ORACLE\ARCH\ORCL\ARC00043_0662757171.001 RECID=42 STAMP=664650496
archived log file name=C:\ORACLE\ARCH\ORCL\ARC00044_0662757171.001 RECID=43 STAMP=664655636
Finished backup at 05-SEP-08 Starting backup at 05-SEP-08 using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=C:\ORACLE\ORADATA\ORCL\SYSAUX01.DBF input datafile file number=00001 name=C:\ORACLE\ORADATA\ORCL\SYSTEM01.DBF input datafile file number=00005 name=C:\ORACLE\ORADATA\ORCL\UNDOTBS02.DBF input datafile file number=00004 name=C:\ORACLE\ORADATA\ORCL\USERS01.DBF channel ORA_DISK_1: starting piece 1 at 05-SEP-08
channel ORA_DISK_1: finished piece 1 at 05-SEP-08
piece handle=C:\ORACLE\FLASH_RECOVERY_AREA\ORCL\BACKUPSET\2008_09_05\ O1_MF_NNNDF_TAG20080905T183432_4D3N0Z0Z_.BKP tag=TAG20080905T183432 comment=NONE
channel ORA_DISK_1: starting piece 2 at 05-SEP-08 channel ORA_DISK_1: finished piece 2 at 05-SEP-08
piece handle=C:\ORACLE\FLASH_RECOVERY_AREA\ORCL\BACKUPSET\2008_09_05 \O1_MF_NNNDF_TAG20080905T183432_4D3N63Y8_.BKP tag=TAG20080905T183432 comment=NONE
channel ORA_DISK_1: starting piece 3 at 05-SEP-08 channel ORA_DISK_1: finished piece 3 at 05-SEP-08
Backing Up Your Database with RMAN |
189 |
piece handle=C:\ORACLE\FLASH_RECOVERY_AREA\ORCL\BACKUPSET\2008_09_05\ O1_MF_NNNDF_TAG20080905T183432_4D3N9PY8_.BKP tag=TAG20080905T183432 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:04:48 channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 05-SEP-08 channel ORA_DISK_1: finished piece 1 at 05-SEP-08
piece handle=C:\ORACLE\FLASH_RECOVERY_AREA\ORCL\BACKUPSET\2008_09_05\ O1_MF_NCSNF_TAG20080905T183432_4D3NBHXS_.BKP tag=TAG20080905T183432 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 05-SEP-08
Starting backup at 05-SEP-08 current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=45 RECID=44 STAMP=664655986 channel ORA_DISK_1: starting piece 1 at 05-SEP-08
channel ORA_DISK_1: finished piece 1 at 05-SEP-08
piece handle=C:\ORACLE\FLASH_RECOVERY_AREA\ORCL\BACKUPSET\2008_09_05\ O1_MF_ANNNN_TAG20080905T183946_4D3NBS89_.BKP tag=TAG20080905T183946 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 channel ORA_DISK_1: deleting archived log(s)
archived log file name=C:\ORACLE\ARCH\ORCL\ARC00045_0662757171.001 RECID=44 STAMP=664655986
Finished backup at 05-SEP-08
You can also do backups of tablespaces and datafiles using the backup command, as shown in these examples:
RMAN>Backup tablespace users;
RMAN>Backup datafile 3;
In Exercise 4.2, you’ll execute an online backup using RMAN.
190 Chapter 4 n Configuring and Backing Up Using RMAN
E x e r c i s e 4 . 2
Executing an Online Backup
In this exercise you will perform an online backup of your ARCHIVELOG mode database. Your database should already be in ARCHIVELOG mode (see Exercise 2.1). Once the database is in ARCHIVELOG mode you can do this exercise.
1.Log into the database using SQL*Plus:
C:\oracle\admin\ORCL\wallet>set oracle_sid=orcl C:\oracle\admin\ORCL\wallet>sqlplus “/ as sysdba”
SQL*Plus: Release 11.1.0.6.0 - Production on Thu Sep 11 18:56:27 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production With the Partitioning, OLAP, Data Mining and Real Application
Testing options SQL>
2.Query the LOG_MODE column of the V$DATABASE view to confirm that the database is in ARCHIVELOG mode. If the database is not in ARCHIVELOG mode, refer to Chapter 2 for information on how to put the database in ARCHIVELOG mode.
SQL> Select log_mode from v$database; LOG_MODE
------------
ARCHIVELOG
3.Exit SQL*Plus and start RMAN:
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
C:\oracle\admin\ORCL\wallet>rman target=/
Recovery Manager: Release 11.1.0.6.0 - Production on Thu Sep 11 18:58:55 2008
Copyright (c) 1982, 2007, Oracle. All rights reserved. connected to target database: ORCL (DBID=1190537904)
4.Execute the RMAN backup using the backup database command. Back up the archived redo logs at the same time with the plus archivelog option. Remove the archived redo logs after they are backed up using the delete input option.
RMAN> Backup database plus archivelog delete input;
Backing Up Your Database with RMAN |
191 |
E x e r c i s e 4 . 2 ( c o nt i n u e d )
5.Review the output, and make sure the backup was successful. Here is an example of our output. We bolded the messages that indicate a successful backup.
RMAN> Backup database plus archivelog delete input; Starting backup at 11-SEP-08
current log archived
using target database control file instead of recovery catalog allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=128 device type=DISK
channel ORA_DISK_1: starting compressed archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=87 RECID=86 STAMP=665092065 input archived log thread=1 sequence=88 RECID=87 STAMP=665138962 input archived log thread=1 sequence=89 RECID=88 STAMP=665172239 input archived log thread=1 sequence=90 RECID=89 STAMP=665172313 input archived log thread=1 sequence=91 RECID=90 STAMP=665172466 input archived log thread=1 sequence=92 RECID=91 STAMP=665175694 channel ORA_DISK_1: starting piece 1 at 11-SEP-08
channel ORA_DISK_1: finished piece 1 at 11-SEP-08 piece handle=C:\ORACLE\FLASH_RECOVERY_AREA\ORCL
\BACKUPSET\2008_09_11\O1_MF_ANNNN_TAG20080911T190135_4DMHVZFK_.BKP tag=TAG20080911T190135 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07 channel ORA_DISK_1: deleting archived log(s)
archived log file name=C:\ORACLE\ARCH\ORCL\ ARC00087_0662757171.001 RECID=86 STAMP=665092065 archived log file name=C:\ORACLE\ARCH\ORCL\ ARC00088_0662757171.001 RECID=87 STAMP=665138962 archived log file name=C:\ORACLE\ARCH\ORCL\ ARC00089_0662757171.001 RECID=88 STAMP=665172239 archived log file name=C:\ORACLE\ARCH\ORCL\ ARC00090_0662757171.001 RECID=89 STAMP=665172313 archived log file name=C:\ORACLE\ARCH\ORCL\ ARC00091_0662757171.001 RECID=90 STAMP=665172466 archived log file name=C:\ORACLE\ARCH\ORCL\ ARC00092_0662757171.001 RECID=91 STAMP=665175694
Finished backup at 11-SEP-08
Starting backup at 11-SEP-08 using channel ORA_DISK_1
192 Chapter 4 n Configuring and Backing Up Using RMAN
E x e r c i s e 4 . 2 ( c o nt i n u e d )
channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=C:\ORACLE\ORADATA\ORCL\SYSAUX01.DBF input datafile file number=00001 name=C:\ORACLE\ORADATA\ORCL\SYSTEM01.DBF input datafile file number=00005 name=C:\ORACLE\ORADATA\ORCL\UNDOTBS02.DBF input datafile file number=00004 name=C:\ORACLE\ORADATA\ORCL\USERS01.DBF
channel ORA_DISK_1: starting piece 1 at 11-SEP-08 channel ORA_DISK_1: finished piece 1 at 11-SEP-08 piece handle=C:\ORACLE\FLASH_RECOVERY_AREA\ORCL
\BACKUPSET\2008_09_11\O1_MF_NNNDF_TAG20080911T190200_4DMHWM1T_.BKP tag=TAG20080911T190200 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:05:36
Finished backup at 11-SEP-08 Starting backup at 11-SEP-08 current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=93 RECID=92 STAMP=665176062 channel ORA_DISK_1: starting piece 1 at 11-SEP-08
channel ORA_DISK_1: finished piece 1 at 11-SEP-08 piece handle=C:\ORACLE\FLASH_RECOVERY_AREA\ORCL
\BACKUPSET\2008_09_11\O1_MF_ANNNN_TAG20080911T190742_4DMJ7H29_.BKP tag=TAG20080911T190742 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 channel ORA_DISK_1: deleting archived log(s)
archived log file name=C:\ORACLE\ARCH\ORCL \ARC00093_0662757171.001 RECID=92 STAMP=665176062
Finished backup at 11-SEP-08
Starting Control File and SPFILE Autobackup at 11-SEP-08 piece handle=C:\ORACLE\FLASH_RECOVERY_AREA\ORCL
\AUTOBACKUP\2008_09_11\O1_MF_S_665176080_4DMJ7SOT_.BKP comment=NONE
Finished Control File and SPFILE Autobackup at 11-SEP-08
Backing Up Your Database with RMAN |
193 |
RMAN Incremental Backups
Incremental database backups are a way to quickly back up your database. In the following sections, we will discuss incremental backups. First you’ll learn about configuring for incremental backups, next we will look at the two different kinds of incremental backups that are available, and then you’ll learn how to actually do incremental backups.
Configuring for Incremental Backups
Technically, you don’t have to configure anything to do an incremental backup. RMAN will perform an incremental backup when you issue the appropriate backup command. However, without any configuration, RMAN must inspect each block and determine whether it has indeed changed since the last backup and if it must go into the backup image.
Optionally you can create a block-change tracking file that will keep track of blocks that have changed since the last full or incremental backup. This can significantly reduce the time it takes to perform an incremental backup of your database, because it removes the need for Oracle to inspect each data block to determine if it’s been changed since the last backup.
Figure 4.4 demonstrates the block-change tracking file.
F i g u r e 4 . 4 The block-change tracking file
RMAN |
Unchanged |
Changed |
|
Blocks |
Blocks |
||
|
Step 1 |
Query block- |
change tracking |
file to determine |
change blocks. |
Block Change
Tracking File
Step 2 Back up only the changed blocks
and skip the unchanged blocks.
Datafile |
The block-change tracking file can track only a maximum of seven different incremental level-1 backups. After the seventh backup, the initial level-0 backup records will be overwritten in the block-change tracking file. This will result in RMAN having to scan all database blocks on subsequent incremental backups. As a result, limit incremental backups without an intervening level 0 to a maximum of seven.
194 Chapter 4 n Configuring and Backing Up Using RMAN
To create the block-tracking file, use the alter database enable block change tracking command. By default, Oracle will create the block-change tracking file in the location defined by the DB_CREATE_FILE_DEST parameter. If that parameter is not set, Oracle will require that you provide a destination and filename for the block-change tracking file. Here is an example of the creation of a block-change tracking file:
SQL> alter database enable block change tracking using file ‘c:\oracle\block_change_tracking\orcl_block_change.fil’;
You can find the location of the current block-change tracking file by looking at the
FILENAME column of the V$BLOCK_CHANGE_TRACKING view. You can use the STATUS column of the V$BLOCK_CHANGE_TRACKING view to determine if block-change tracking is enabled.
You should perform a level 0 incremental backup after creating the blockchange tracking file. This is because the parent level-0 backup bitmap must be in the block-change tracking file.
Types of Incremental Backups
Two types of incremental backups are available for you to choose from:
NN |
Level-0 incremental backup |
NN |
Level-1 incremental backup |
The level-0 backup is like a full backup (sometimes it’s called a base backup), except that incremental backups can be based on it (they can not be based on a regular full backup).
The level-1 backup is the incremental backup that backs up changed blocks. There are two different kinds of level-1 backups:
NN |
Differential incremental backup |
NN |
Cumulative incremental backup |
The differential incremental backup will back up all changed blocks since the last level-1 backup. These images are typically smaller. The cumulative incremental backup is one where the data backed up is the data that changed since the last level-0 full backup. Thus it is a cumulative backup of all changed blocks since the last level-0 backup. This makes for faster recoveries since you don’t have to apply several incremental backups during the database restore. Figure 4.5 provides a visual example of the differences between these types of backups.
Performing Incremental Backups
Performing incremental backups is almost exactly like performing regular backups except that you include the incremental level option in the backup command. For example, to create a base, level-0 backup, you would issue this command:
RMAN> Backup as compressed backupset incremental level 0 database plus archivelog delete input;
Backing Up Your Database with RMAN |
195 |
When you are ready to run your first incremental backup you would use the backup command with the incremental level-1 option, as shown here:
RMAN> Backup as compressed backupset incremental level 1 database plus archivelog delete input;
F i g u r e 4 . 5 Differential vs. cumulative incremental backups |
|
|||||||||||||
Sun |
Mon |
Tues |
Wed |
Thur |
Fri |
Sat |
Sun |
Mon |
Tues |
Wed |
Thur |
Fri |
Sat |
Sun |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
|
|
|
|
|
Differential Backup |
|
|
|
|
|
Sun |
Mon |
Tues |
Wed |
Thur |
Fri |
Sat |
Sun |
Mon |
Tues |
Wed |
Thur |
Fri |
Sat |
Sun |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
|
|
|
|
|
Cumulative Backup |
|
|
|
|
|
Differential backups are the default type of incremental backup in Oracle. If you want to perform a cumulative backup, you will need to include the cumulative keyword, as shown here:
RMAN> Backup as compressed backupset incremental level 1 cumulative database plus archivelog delete input;
196 Chapter 4 n Configuring and Backing Up Using RMAN
Note that if you try to do a level-1 backup and a level-0 does not exist, RMAN will not generate an error. It will simply perform a level-0 backup for you instead.
RMAN Incrementally Updated Backups
Incrementally updated backups involve a combination of a full image backup of the database and then subsequent level-1 incremental backups of the database, which are applied to the image-copy backup. An incrementally updated backup makes for a quicker restore but for a bigger backup image.
To create an incrementally updated backup, all you need do is run the following script:
RUN { # the recover copy command does not really recover anything.
#it simply tells RMAN that the incremental to be executed should
#be applied to the database copy we made above.
Recover copy of database with tag ’Jacob_Jared_Lizzie’; Backup incremental level 1
for recover of copy with tag ’Jacob_Jared_Lizzie’ Database; }
On the first execution of this script, RMAN will detect that no backup copy exists. Warnings will be generated, but no errors. RMAN will proceed to create the initial copy of the database. No incremental copy will be created.
On subsequent executions, RMAN will detect that an image copy does exist, and it will then apply the previous level-1 incremental-and then execute another level-1 incremental backup. Note that on the second run, RMAN will detect that no incremental backup exists to apply to the datafile copy and a warning will be raised because of this. That is normal.
This method limits the recovery window for your database to one day. For example, if you executed this script on day 1, day 2, and day 3, after day 3’s execution you would not be able to restore your database to any point before day 3’s backup.
You could provide for longer recovery windows by including the until time clause. In this example, we allow for a recovery window of five days:
run { |
|
recover |
copy of database with tag ‘lisa’ until time ‘sysdate - 5’; |
backup |
incremental level 1 for recover of copy with tag ‘lisa’ database; |
} |
|
RMAN Multisection Backups
Prior to Oracle Database 11g, you could not parallelize the backup of a given database datafile. Since datafiles had to be contained wholly within a single backup set, this meant that the backup of that datafile was serialized. This can be a bit of a problem if your database consists of one or two huge datafiles and several smaller datafiles. Also, if you are using bigfile tablespaces, the lack of inner-file backup parallelization could be a big issue.
Backing Up Your Database with RMAN |
197 |
Oracle Database 11g provides a new feature called multisection backups that provides the ability to parallelize the backup of a single datafile. This feature is supported by the section size clause in the backup command followed by the desired section size. Here is an example:
RMAN> backup section size 40m database;
In this example, RMAN will chunk up each datafile into 40MB chunks, and each allocated channel can process those individual 40MB chunks. Note that if you allocate only one channel, only one chunk at a time will get backed up! Also note that the size parameter does not indicate the size of the resulting backup set piece. Rather, it is the equivalent amount of data within the datafile that each RMAN channel will process. The resulting pieces can vary wildly in size.
RMAN Backup of Archived Redo Logs
Backing up archived redo logs is an important task since it serves to protect the database’s principal recovery mechanism, which is redo. Backing up archived redo logs is done via the backup archivelog command. This command requires that you include keywords from the archivelog specifier clause, which is used to indicate the archived redo logs that you want to back up. Common keywords that you might use include the following:
NN All: Backs up all archived redo logs currently on disk
NNSequence between n and o: Backs up all archived redo logs available on disk between sequence number n and sequence number o
NNTime between t1 and t2: Backs up all archived redo logs available on disk between time t1 (the earlier time) and time t2 (the later time)
Here is an example of backing up all archived redo logs, still on disk, that were generated in the last 24 hours:
RMAN> backup archivelog time between “sysdate-1” and “sysdate”; Starting backup at 05-SEP-08
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=46 RECID=45 STAMP=664657241 channel ORA_DISK_1: starting piece 1 at 05-SEP-08
channel ORA_DISK_1: finished piece 1 at 05-SEP-08
piece handle=C:\ORACLE\FLASH_RECOVERY_AREA\ORCL\BACKUPSET\2008_09_05\ O1_MF_ANNNN_TAG20080905T190103_4D3OLO2G_.BKP tag=TAG20080905T190103 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 05-SEP-08.
198 Chapter 4 n Configuring and Backing Up Using RMAN
Be Careful What You Ask For...You Might Just Get It (Or Not)
Look at the example where we backed up the archived redo logs for the last 24 hours. The command was as follows:
backup archivelog time between “sysdate-1” and “sysdate”;
But guess what happens if you change this command just slightly:
RMAN> backup archivelog time between “sysdate” and “sysdate-1”; Starting backup at 05-SEP-08
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 09/05/2008 19:02:56 RMAN-20242: specification does not match any archived log in the recovery catalog
If you didn’t know any better, you might just think that there are no archived redo logs to back up and assume the backup archivelog command worked fine and dandy. In fact, the command failed because you had the from/to dates in the wrong order. This highlights how important it is to make sure you carefully review the syntax of the command you are getting ready to execute and then review the output of RMAN commands and make sure RMAN did what you thought you told it to do.
RMAN Backup of the Spfile and Control Files
We have already discussed control-file autobackups in this chapter. You may find that on occasion you want to do an individual backup of the control file or the spfile.
You have two options in RMAN for control-file backups, using the backup current controlfile command or the backup controlfilecopy command.
The backup as copy command will cause the current control file to be backed up. This is a copy of the control file, so it’s like a backup control file. Thus, you could just copy the file into place and treat it as a backup control file. By default the backup will be created in the FRA as would happen in this example:
RMAN> backup as copy current controlfile;