Instructor's Notes
(If applicable)
- Lesson 19: Introduction to RMAN
- In this lesson you’ll learn what RMAN is and how to make use of basic, critical backup and recovery techniques.
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- Recovery Manager (usually called “RMAN”) is a utility for the backup and recovery of Oracle 8.0, 8.1 and 9.x databases. RMAN provides server-managed backup and recovery.
- RMAN can be used in place of OS backup techniques (note that Oracle documentation now refers to OS copy backup techniques as “user-managed”). And, RMAN will automate many tasks. For example, RMAN eliminates the need to locate the files needed to recover - RMAN keeps track of this automatically. RMAN also allows administrators to create and save scripts that perform repeated tasks.
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- RMAN is shipped with all versions of Oracle. A separate purchase and install is NOT necessary, unless you need to backup directly to tape. In this case you will need additional software Oracle calls “media manager libraries”. Legato supplies a free reduced feature version (supports only 1 local tape device). Purchasing full feature versions from Legato or Veritas can be very expensive.
- Visit http://www.oracle.com/ip/deploy/database/features/recovery/index.html?mediapartner.html for a list of vendors supplying MML’s.
- RMAN was first introduced in Oracle8.0. It is not compatible with Oracle7 databases. It replaces the version 7 Enterprise Backup utility, which is now obsolete.
- RMAN commands can be executed via a command line utility (much like Server Manager) or through the graphical user interface in Oracle Enterprise Manager.
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- An RMAN environment is comprised of several components, each of which has a release (or version) number.
- The RMAN executable is an Oracle client application. This client application spawns server sessions on the target database to do the work of backup or recovery. It is similar in some ways to SQL*Plus in that it allows connections to databases and provides a line mode command interface. It is different in that it allows multiple concurrent connections (one to the target, one to the catalog database) and it does not support SELECT statements. (RMAN actually spawns multiple sessions on the target database, but supports one CONNECT to the target.)
- The Target database is the database to be backed up or recovered. It is where the server sessions spawned by the RMAN executable run. The target database’s control file contains recovery metadata - that is, information about backups that have been taken. This information is needed to perform recovery using RMAN.
- Notes continue on the next page…
Other Text:
(Examples or comments displayed on slide, if any).
What’s been backed up and when – what hasn’t?
Where are the backup "sets"?
Optional, but cannot restore to an old “incarnation” of the database
Instructor's Notes
(If applicable)
- RMAN creates and maintains a repository of metadata about the target databases. (“Target” in RMAN parlance simply means the database that you are backing up.) This is not an optional feature. The repository provides the intelligence in RMAN. For example, this allows RMAN to keep track of backups. RMAN knows what has been backed up, what has not and where the backup sets (one or more OS files) are located, plus much more. The repository is always stored in the control file of the target database. It can optionally also be stored in a “catalog database". The catalog database is a separate database created to hold a copy –albeit a more robust copy – of the recovery catalog. A benefit of the recovery catalog is that it keeps all historical information; the control file history of backup sets eventually gets written over – see the CONTROL_FILE_RECORD_KEEP_TIME parameter.
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- Oracle and RMAN do not come with the ability to directly read and write to tape. You must install compliant software, called a “media management library”, from a tape software vendor. Oracle ships with a reduced feature MML from Legato.
- Supplemental Notes
- Each component in the RMAN environment has a release – and often they are not the same. For example, you may have a group of release 8.1.x production (target) databases that you would like to back up with RMAN. You would like to create a new database to hold your recovery catalog and choose to install Oracle9i. Finally, to take advantage of the new 9i RMAN features, you would like to use 9i RMAN to backup your 8.1.x databases. However, this is not valid! You will need to backup your 8.1.x databases with a 8.1.x version of the RMAN executable. Oracle documentation states “The versions of the RMAN executable and the target database should be the same.” So, in fact, you will need multiple copies of RMAN to backup your mixed release environment. See the RMAN compatibility guide for more information. Login to Metalink and search on RMAN compatibility.
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- The RMAN line-mode utility is started from the OS command prompt. The command shown in the slide starts RMAN without a separate catalog database, i.e. nocatalog mode. The command:
- C:\>rman target=sys/change_on_install@prod catalog=rman/rman@recovery
- starts RMAN and connects to both databases, the target and the recovery database. Both “prod” and “recovery” need to be valid entries in the TNSNAMES.ORA file. The userid used to connect to the TARGET database must have SYSDBA privilege. RMAN automatically adds “AS SYSDBA” to the connection attempt.
- Use the LOG (or LOGFILE) option to cause RMAN to write all output to the specified logfile. Perhaps unfortunately, it does not also write the output to the screen. Optional LOGFILE option:
- C:\>rman . . . LOG=c:\oracle\backups\rman.log
- You can also start with command files:
- C:\>rman …cmdfile "c:\rman\backup.rmn"
- The “CMDFILE” option allows you to specify a text file that contains the RMAN commands. If the last command is EXIT;, then you can create schedulable batch jobs.
Other Text:
(Examples or comments displayed on slide, if any).
C:\>rman target system/dave
Recovery Manager: Release 9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rig
connected to target database: DAVE (DBID=549349079)
RMAN>
User must have SYSDBA privilege
Instructor's Notes
(If applicable)
- We can see in this slide that starting RMAN can be done differently. For example, RMAN starts without any parameters; connections to the databases can be done separately with the CONNECT command after entering this RMAN environment.
- This is a more secure connection method because it prevents password discovery with the Unix “ps” command (the "ps" command reports on all active processes). The output of the following command:
- $ ps –ef | grep rman
- would show the entire RMAN command, passwords and all, if passwords were used on the initial RMAN command.
Other Text:
(Examples or comments displayed on slide, if any).
C:\>rman
RMAN> connect target system/dave
connected to target database: DAVE (DBID=549349079)
RMAN>
Instructor's Notes
(If applicable)
- Common commands include:
- BACKUP - Backup a database, tablespace, datafile, archived log file, backupset or control file.
- RESTORE - Restore files from backup sets. A backup set is in proprietary format; the RESTORE command is the only way of restoring its contents. Often the RECOVER command is executed after a restore to apply changes contained in redo logs.
- RECOVER - Recover a database, tablespace, datafile or one or more blocks (9i only) by applying archived and online redo log files.
- ALLOCATE CHANNEL - Create a connection to the target database for the purpose of executing backup and recovery operations. Each channel spawns a server session on the target database. That server session does the work, i.e. the backing up, copying, restoring or recovering of datafiles. Each server session can be connected to one device, e.g. disk or tape.
Other Text:
(Examples or comments displayed on slide, if any).
Oracle9i allocates automatically
Instructor's Notes
(If applicable)
- Common commands continued:
- CONFIGURE – This allows us to tailor the RMAN environment by configuring persistent (session to session) settings that affect backup, restore and maintenance jobs.
- REPORT - Report information about the state of the target database such as which files require backup, which backups are obsolete, structure of the database schema and more.
- LIST - List information about database incarnations, backup sets (backup files) and image copies (see the “copy” command).
- create script - save a series of commands in the recovery catalog as a script.
- SHOW – Oracle9i introduced the CONFIGURE command to tailor your RMAN environment to your needs. The SHOW command displays current configuration settings.
- STARTUP, SHUTDOWN and ALTER DATABASE – Oracle recognizes that these are frequent operations within the context of backup and recovery and therefore supports these directly from RMAN. Only the Target database is affected. E.g. alter database open;
- Continues…
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- Common stand-alone commands continued:
- SQL – Any SQL statement (except SELECT ) can be executed from within RMAN. E.g. sql ‘alter tablespace test offline’;
- HOST – Submit a command to the operating system. For example, host 'DIR';
- Additional useful commands not shown in the slide.
- COPY - Create an image copy of a file. An image copy is an exact block-for-block copy of a file. It speeds recovery greatly by allowing the DBA to simply point at the image copy in the event of failure of the primary file.
- DUPLICATE - Create a duplicate copy of a database.
- SWITCH - A form of recovery; switch the target database to point at an image copy of a file. Faster than restore/recover but uses more disk resources to store the image copies.
- VALIDATE BACKUPSET – Determines if the backupset will work in a recovery operation by reading the backup pieces within the set and checking for corruption.
- Refer to the Oracle Recovery Manager Reference manual for a complete list of commands.
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- Backups are accomplished with the RMAN BACKUP command. The output of a backup operation is one or more backup sets. The backup sets are used by RMAN in RESTORE operations. RMAN remembers what backup sets are available and where they are located. It does this by storing this information in the target database control file and, if available, the recovery catalog. (Review: A benefit of the recovery catalog is that it keeps all historical information; the control file history of backup sets eventually gets written over – see the CONTROL_FILE_RECORD_KEEP_TIME parameter.)
- Each channel that is allocated when the backup is performed will create at least 1 backup set. A single channel will create more than 1 set if you have limited the number of files per set (see the FILESPERSET example later) and there are more files than the number of channels * files per set.
- RMAN can backup directly to tape - if you have acquired and installed an MML on the target database. The Media Management Library is vendor-supplied software that the server sessions performing the backup can communicate with. So the server sessions created on behalf of RMAN can not talk directly to the tape; they require this intervening software. A list of Oracle-validated MML software can be found at www.oracle.com.
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- A backup set consists of one or more backup pieces. So the backup set is a logical group of backup pieces. Each backup piece is equivalent to a single operating system file. The backup piece (or OS file) contains the blocks from the datafiles that were backed up. It is in an Oracle proprietary format and can only be restored with the RMAN RESTORE command.
- RMAN requires that the database be either mounted or open – it cannot be entirely closed. This is because RMAN needs to update the target database control file with the backup information. (Remember, mounted means that the control file is open.) The exception to this is a database running in NOARCHIVELOG mode; in this case the database must be mounted, but cannot be open.
- What can RMAN backup? Essentially RMAN backs up datafiles, control files and archive logs. But RMAN backup options allow many levels of granularity. For example, we can back up the whole database (all datafiles and the control file), a single tablespace, or even a specific datafile. RMAN also allows backup of the control file, archive logs and backup sets. Backup of backup sets can be useful to move the backup set to tape. (Though RMAN can backup directly to tape, perhaps the write to tape is too slow to do during the backup itself.)
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- A full backup copies all ever-used datafile blocks to the backup set. Blocks never used will not be written to the backup set. (Do not confuse this with the high-water mark. Blocks that were once used but now perhaps above the HWM will be included in the backup. This is because RMAN must be able to do the backup with the database closed – so it can only rely on the data found in the data block headers. If the data block header was formatted – even if it is above the HWM, it will be backed up.)
- The database must be at least mounted. If the database is running in ARCHIVELOG mode, the database can be open. In this situation, there is no need to put the database in hot backup mode. RMAN will automatically detect fractured blocks (I.e. blocks that are currently being updated) and re-read those blocks until a consistent block is read.
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- The BACKUP DATABASE command will, by default, do a FULL backup - all datafiles except TEMPORARY tablespace datafiles. A control file AUTOBACKUP will also occur if CONFIGURE CONTROLFILE AUTOBACKUP is ON.
- The example shown above works only in a 9i environment. Assuming that the default channel is defined with:
- CONFIGURE DEFAULT DEVICE TYPE TO disk;
- The backup is made to the default disk location.
Other Text:
(Examples or comments displayed on slide, if any).
RMAN> configure controlfile autobackup on;
old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
RMAN> backup database plus archivelog;
backup started. . .
Automatic backup of control file and server parameter file. Do this one time only.
Instructor's Notes
(If applicable)
- The example shown above makes use of the Automatic Channel Allocation feature of Oracle9i. Note that RMAN uses a standard channel name for automatically allocated channels: ORA_DISK_n, where n starts at 1 and goes up by 1 for each additional channel allocated.
- Note that “TEST” is a reserved word and thus must be enclosed in quotes in the example above. Since it is enclosed in quotes, the name is also case sensitive.
- Multiple tablespaces can be backed up in a single command:
- RMAN> backup tablespace 'TEST', skill_indexes;
Other Text:
(Examples or comments displayed on slide, if any).
RMAN> backup tablespace 'TEST';
Starting backup at 11-MAY-02
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backu
input datafile fno=00004 name=C:\ORACLE\ORADATA\DAVE
channel ORA_DISK_1: starting piece 1 at 11-MAY-02
channel ORA_DISK_1: finished piece 1 at 11-MAY-02
piece handle=C:\ORACLE\ORA81\DATABASE\0IDO69D4_1_1
channel ORA_DISK_1: backup set complete, elapsed ti
Finished backup at 11-MAY-02
Instructor's Notes
(If applicable)
- In addition to tablespaces, you can also backup specific datafiles.
- Note that RMAN converts BACKUP TABLESPACE commands into a series of datafile names; BACKUP TABLESPACE is a convenience for the DBA.
- Note also that the datafile name contains special characters ( \ ), and therefore must be enclosed in quotes. The OS determines if the filename is case sensitive.
Other Text:
(Examples or comments displayed on slide, if any).
RMAN> backup datafile 'C:\ORACLE\ORADATA\PROD\TEST.DBF';
RMAN> backup datafile 'C:\ORACLE\ORADATA\PROD\TEST.DBF',
2> 'C:\ORACLE\ORADATA\PROD\TOOLS01.DBF';
Instructor's Notes
(If applicable)
- Incremental backups only write changed blocks to the backup set (note that the entire datafile is read). This can save considerable time, I/O channel bandwidth and disk (or tape) space.
- The method RMAN uses to create incremental backups is to incorporate multiple “levels” of backup. A level 0 backup backs up all blocks; a level 1 backs up only changed blocks, I.e. only blocks that have been changed since the last incremental backup.
- Incremental backups are either differential (the default) or cumulative. A differential backup backs up blocks changed since the last backup at the same or lower level. So for example, a level 1 backs up blocks changed since the last level 1 or level 0.
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- Differential incremental backups (the default) read the entire datafile(s), but only write (i.e. backup) blocks that have been changed since the last backup at the same or lower level. So for example, a level 2 backs up blocks changed since the last level 2, 1 or 0.
- You must start with a level 0 backup – a full backup does not count in the incremental scheme. If you have never taken a level 0 backup and run a higher level, RMAN automatically takes a level 0 for you.
Other Text:
(Examples or comments displayed on slide, if any).
RMAN> backup incremental level 0 tablespace example;
Starting backup at 16-OCT-03
. . .
Finished Control File and SPFILE Autobackup at 16-OCT-03
RMAN>
RMAN> backup incremental level 2 tablespace example;
Starting backup at 16-OCT-03
Instructor's Notes
(If applicable)
- There is lots more to know about backups. Here are (in the slide) more subjects you should learn.
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- The two most basic commands for recovering a database in RMAN are RESTORE and RECOVER. The RESTORE command reads the backup sets containing the datafiles needed and writes the datafiles back to the same or different location (see the “SET NEWNAME” command.) RMAN will overwrite files without warning.
- For best performance, RMAN will use image copies of the datafiles instead of backup sets, if image copies are available.
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- The RECOVER command then applies incremental backups or redo (it favors incremental backups, for speed) to bring the restore files up to the most recent commit, or whatever you specify in the SET UNTIL command. Redo is supplied by archived logs. If you have backed up and deleted the original archive logs, RMAN will automatically restore