Oracle RMAN 11g Backup and Recovery (141 page)

BOOK: Oracle RMAN 11g Backup and Recovery
6.27Mb size Format: txt, pdf, ePub

Chapter 16: Maintaining RMAN
419

RMAN offers another option, which is to store scripts in the recovery catalog. As you might guess, this requires that you use a recovery catalog, so if you are not using one, you will not be able to store RMAN scripts. This section shows you how to store scripts in the recovery catalog and how to manage those scripts.

Creating Stored Scripts

To store a script in the recovery catalog, you use the
create script
RMAN command. Each stored script is assigned a name when you create it. You can create scripts that do backups, recoveries, and maintenance of your databases. To create a script, you must be connected to the recovery catalog. Here is an example of using the
create script
command to create a backup script. RMAN

also allows you to store comments related to your stored scripts by using the
comment
parameter: create script my backup script

comment 'This script backs up the database'

{ backup database plus archivelog;}

Oracle Database 11
g
supports the use of substitution variables. Each substitution variable is denoted with an ampersand and a number that makes each variable unique. For example, you could rewrite this script as follows:

create script my backup script

comment 'This script backs up the database'

{ backup database tag '&1' plus archivelog;}

When you execute this command, RMAN will prompt you for initial values for the substitution variables.

Querying the Recovery Catalog for Stored Script Information

You can use the recovery catalog views to determine the name of scripts stored in the recovery catalog by querying the RC_STORED_SCRIPT view. You can see the contents of a given script by querying the RC_STORED_SCRIPT_LINE view.

Changing Stored Scripts

You use the
replace script
command to replace stored scripts in the recovery catalog. Here is an example of using the
replace script
command. Note that we also add a comment to the script.

replace script my backup script

comment 'This script backs up the database'

{ backup database plus archivelog delete input;}

Deleting Stored Scripts

To drop a script, you use the
delete script
command. You must be connected to the recovery catalog to successfully drop a stored script. Here is an example of using the
delete script
command:

delete script my backup script;

420
Part III: Using RMAN Effectively

Using Stored Scripts

Now that you have created some stored scripts, you probably want to use them. This is what the
execute script
command is for. Simply connect to the recovery catalog and use the
execute script
command within the confines of a
run
block, as shown in this example: run {execute script my backup script;}

If you are using substitution variables, you can use the
using
parameter to include the values of those parameters in the
execute script
command, as seen in this example: Run {execute script my backup script using TEST BACKUP;}

Printing Stored Scripts

If you want to print a copy of your stored script, you can use the
print script
command. Connect to the recovery catalog, and run the
print script
command, as shown in this example: RMAN> print script my backup script;

printing stored script: my backup script

{ backup database plus archivelog;}

You can also use the RC_STORED_SCRIPT_LINE recovery catalog view to display the contents of a stored script, as shown in this example:

select script name, text from rc stored script line

order by script name, line;

SCRIPT NAME TEXT

---------------- ----------------------------------------

my backup script { backup database plus archivelog;}

RMAN Workshop:
Using RMAN Stored Scripts

Workshop Notes

This workshop expects that you have an operational Oracle database (called recover) and that you are also using a separate Oracle database to store the recovery catalog in (called catalog).

Step 1.
Connect to the target database and to the recovery catalog: rman target rman account/rman password catalog rcat user/rcat password@catalog
Step 2.
Create a stored script to back up the target database:

RMAN> create script my backup script

2> {backup database plus archivelog;}

created script my backup script

Step 3.
Print the stored script:

RMAN> print script my backup script;

printing stored script: my backup script

{backup database plus archivelog;}

Chapter 16: Maintaining RMAN
421

Step 4.
Execute the stored script to back up your database:

RMAN> run {execute script my backup script;}

Step 5.
Delete the stored script:

RMAN> delete script my backup script;

When You Just Can’t Take It Anymore

If you are sick and tired of your database and you just can’t take it anymore, RMAN offers the perfect response, the
drop database
command. If only terrorists were as easy to get rid of. Simply put the database in restricted session mode, connect to the target database with RMAN, issue the
drop database
command, and watch your database quietly go away. You can add the
including
backups
parameter, and all RMAN-related backups will be removed, too. When you issue this command, RMAN will confirm the action first and then proceed to remove the database. If you wish to not be prompted, you can use the
noprompt
parameter. Here is an example of the use of the
drop database
command:

SQL> alter system enable restricted session;

SQL> quit;

.. log into RMAN ..

RMAN>drop database including backups;

Summary

In this chapter, we discussed the various maintenance operations that RMAN may require.

We discussed the
crosscheck
command and validating RMAN backups, both very important operations. We also talked about retention policies and how RMAN uses them to control how long your backups will remain available to you for recovery purposes.

We also talked about the
change
and
delete
commands and how they can be used to modify the status of RMAN records in the control file or recovery catalog. We also covered adding backups to the control file or recovery catalog. Finally, we discussed maintenance of the recovery catalog and the use of stored scripts for RMAN operations.

This page intentionally left blank

CHAPTER

17

Monitoring and

Reporting on RMAN

Other books

Carnations in January by Clare Revell
Anilyia by Carroll, John H.
Dread Murder by Gwendoline Butler
On His Terms by Jenika Snow
Strong Signal (Cyberlove #1) by Megan Erickson, Santino Hassell
Alicia Roque Ruggieri by The House of Mercy
Murder Mile High by Lora Roberts