Slides © 2004-2007 SkillBuilders.

Instructor's Notes

(If applicable)

  • Lesson 4 – Executing RMAN Commands
  • Author: Dave Anderson, SkillBuilders
  • www.skillbuilders.com
  • Last Update: October 17, 2007

  • This lesson will cover the following topics:
    • RMAN Command basics
    • Job Blocks
    • Oracle9i (and above) command syntax
    • Entering SQL statements through RMAN
    • Summary of Common commands

Other Text:
(Examples or comments displayed on slide, if any).

Slides © 2004-2007 SkillBuilders.

Instructor's Notes

(If applicable)

  • This lesson will demonstrate how to enter RMAN Commands, and provides an overview of common commands. Examples are included, of course!

Other Text:
(Examples or comments displayed on slide, if any).

Slides © 2004-2007 SkillBuilders.

Instructor's Notes

(If applicable)

  • Though the distinction has become less clear with Oracle9i, RMAN has two types of commands – stand-alone and “job” commands. Stand-alone RMAN commands are entered at the command prompt. Like SQL statements in SQL*Plus, the commands are terminated with a semi-colon. As demonstrated in the second example shown above, a single command can be entered on more than one line, simply press return before entering a semi-colon.

  • The REPORT command shown in this slide finds all datafiles in the database that are older than 7 days, i.e. that require more than 7 days of archived logs to recover.

Other Text:
(Examples or comments displayed on slide, if any).

RMAN> report need backup days = 7 database; <br> <br>Report of files whose recovery needs more than 7 days <br>File Days Name <br>---- ----- ------------------------------------------ <br>1 1 /opt/oracle/oradata/test/system01.dbf<br>RMAN> report need Backup <br>2> days = 7; <br> <br>Report of files whose recovery needs more . . .<br>RMAN commands are not case sensitive<br>Commands can span many lines<br>

Slides © 2004-2007 SkillBuilders.

Instructor's Notes

(If applicable)

  • The second example demonstrates the use of a job block – required in Oracle8i to execute a backup or recovery job. Job commands must be entered within a “job” block.
  • Note that job blocks can be coded like this:
  • RMAN> run { allocate channel d1 type disk; backup database; }
  • The RUN command serially executes the commands within brackets. The ALLOCATE command “allocates a channel”. Allocating a channel spawns a server session on the target database and connects an I/O (disk or tape) device to the session. Allocating a channel is necessary for any backup, restore or maintenance job. (See more in the Channels lesson.) It then backs-up the entire database. The channel is freed when the RUN block terminates.

Other Text:
(Examples or comments displayed on slide, if any).

RMAN> run { <br>2> allocate channel d1 type disk; <br>3> backup database; <br>4> } <br> <br>allocated channel: d1 <br>channel d1: sid=19 devtype=DISK <br>. . .<br>

Slides © 2004-2007 SkillBuilders.

Instructor's Notes

(If applicable)

  • Two of the new features in Oracle9i related to command execution are:
    • Automatic channel allocation - 9i will automatically allocate a default channel to a job if one is not manually allocated. See the section on “Automatic Channel Allocation” for more information.
    • Simplified command syntax - The RUN command block is no longer necessary for most commands.
  • So in Oracle9i and above, we can simply enter:
  • RMAN> backup database;
  • to do a full database backup. A pre-configured channel (disk or tape – the default is disk) will be automatically allocated for the job. See more in the lesson titled RMAN Channels.
  • Supplemental Notes
  • 9i RMAN uses the $ORACLE_HOME\database directory as the default location for backup sets. In addition to changing this by configuring your own channel(s) with the CONFIGURE command (see Lesson: RMAN Channels), you can override this with the FORMAT parameter of the BACKUP command:
  • RMAN> backup tablespace tools format 'c:\temp\%U';

Other Text:
(Examples or comments displayed on slide, if any).

RMAN> backup database; <br> <br>Starting backup at 19-NOV-03 <br>allocated channel: ORA_SBT_TAPE_1 <br>channel ORA_SBT_TAPE_1: sid=13 devtype=SBT_TAPE <br>channel ORA_SBT_TAPE_1: NMO v3.5.0.1 <br>channel ORA_SBT_TAPE_1: starting full datafile backupset<br>My pre-configured channel is tape device<br>

Slides © 2004-2007 SkillBuilders.

Instructor's Notes

(If applicable)

  • RMAN also supports the STARTUP and SHUTDOWN and ALTER DATABASE commands. (Semi-colon termination is not necessary for STARTUP and SHUTDOWN.)
  • As demonstrated here, RMAN also supports SQL statements (except SELECT) and procedure calls.

Other Text:
(Examples or comments displayed on slide, if any).

RMAN> shutdown immediate <br>RMAN> startup mount <br>RMAN> alter database open; <br>RMAN> sql 'alter tablespace users offline'; <br>RMAN> sql 'alter tablespace users online'; <br>RMAN> sql 'truncate table system.t'; <br>RMAN> sql ‘begin skill.upddb; end;’;<br>

Slides © 2004-2007 SkillBuilders.

Instructor's Notes

(If applicable)

  • Oracle8i divided commands into “stand-alone” and “job” commands. Job commands need to be executed within the JOB { } syntax. Though for the most part this is no longer true in Oracle9i and above, I will still segregate them that way for those of us still supporting Oracle8i environments. Examples of these commands can be found throughout this book and in the Oracle documentation. Standalone commands are shown on the next page.
  • Common job commands include:
    • ALLOCATE CHANNEL - Create a connection to the target database for the purpose of executing backup, recovery and maintenance 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.
    • 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.

Other Text:
(Examples or comments displayed on slide, if any).

9i supports stand-alone backup, restore and recovery<br>

Slides © 2004-2007 SkillBuilders.

Instructor's Notes

(If applicable)

  • Common stand-alone commands (i.e. can be run from the RMAN prompt) include:
    • SHOW – Oracle9i introduced the CONFIGURE command to tailor your RMAN environment to your needs. The SHOW command displays current configuration settings.
    • CONFIGURE – This allows us to tailor the RMAN environment by configuring persistent (across session) settings that affect backup, restore and maintenance jobs. The example shown in the slide demonstrates how to pre-configure a tape channel. Note that this requires installation of a media management library (MML).
  • Continues…

Other Text:
(Examples or comments displayed on slide, if any).

RMAN> configure default device type to tape; <br> <br>old RMAN configuration parameters: <br>CONFIGURE DEFAULT DEVICE TYPE TO DISK; <br>new RMAN configuration parameters: <br>CONFIGURE DEFAULT DEVICE TYPE TO 'TAPE'; <br>new RMAN configuration parameters are successfully stored<br>RMAN> show default device type; <br>RMAN configuration parameters are: <br>CONFIGURE DEFAULT DEVICE TYPE TO DISK;<br>

Slides © 2004-2007 SkillBuilders.

Instructor's Notes

(If applicable)

  • Continued from previous page:
    • 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. Refer to the lesson on Reporting for more information.
    • LIST - List information about database incarnations, backup sets (backup files) and image copies (see the “copy” command). Refer to the lesson on Reporting for more information.
    • 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;
    • SQL – Any SQL statement (except SELECT ) can be executed from within RMAN. E.g.:
      • RMAN> sql ‘alter tablespace test offline’;
    • HOST – Submit a command to the operating system. For example:
      • RMAN> host 'dir';
    • CREATE SCRIPT - save a series of commands in the recovery catalog as a script. Refer to the lesson on RMAN Scripting for more information.

Other Text:
(Examples or comments displayed on slide, if any).

RMAN> report schema; <br>RMAN> report need backup;<br>RMAN> list backupset summary; <br>RMAN> list backupset verbose;<br>

Slides © 2004-2007 SkillBuilders.

Instructor's Notes

(If applicable)

  • Use the VALIDATE BACKUPSET if you are concerned that a backupset may have become damaged or, simply for extra piece of mind, to double-check that your overnight backup worked perfectly. It causes the entire backupset to be read (which requires a tape or disk channel to be allocated) and each block validated.
  • Additional useful commands not shown in the slides:
    • 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.
  • Refer to the Oracle Database 10g Backup and Recovery Reference manual for a complete list of commands.

Other Text:
(Examples or comments displayed on slide, if any).

RMAN> run { <br>2> allocate channel x type sbt; <br>3> validate backupset 144; <br>4> } <br> <br>released channel: ORA_DISK_1 <br>allocated channel: x <br>channel x: sid=13 devtype=SBT_TAPE <br>channel x: NMO v3.5.0.1 <br> <br>channel x: starting validation of datafile backupset<br>

Slides © 2004-2007 SkillBuilders.

Instructor's Notes

(If applicable)

  • This workshop is designed to give you an opportunity to enter basic RMAN commands. Except when starting RMAN from the OS command prompt, all commands should be entered at the RMAN command prompt while connected to your catalog and target databases. Start RMAN. Connect to the catalog and target databases.
    1. Shutdown and restart your database.
    2. Exit RMAN and re-enter RMAN. Connect to the catalog and target databases.
    3. Create a report of all datafiles that have never been backed up. Use the REPORT NEED BACKUP command (no parameters are necessary). Write down the number of datafiles in the report. If the REPORT command did not find any datafiles that required backup, create a tablespace and re-run the command.
    4. Write and execute a RUN block to allocate one disk channel and backup your database.
    5. Re-execute the REPORT NEED BACKUP command. How many datafiles now appear?
    6. Execute the LIST BACKUP command to view information about the backup sets created in step 3 of this workshop. Execute the LIST BACKUP SUMMARY command. Study the differences between the output of LIST BACKUP and LIST BACKUP SUMMARY.

Other Text:
(Examples or comments displayed on slide, if any).