Recovery Catalog   «Prev  Next»

Lesson 6 Stored scripts
Objective Create and use Stored Oracle Rman Scripts

Create Oracle Rman Scripts

The Oracle Recovery Manager (RMAN) is a vital tool for database administrators (DBAs) managing Oracle databases, offering robust backup and recovery capabilities. An essential feature within this toolset is the use of "stored scripts," which can be a significant asset in reducing and eliminating potential operator errors. Stored scripts in RMAN are essentially named and stored sequences of RMAN commands that can be executed later, offering several advantages.
  1. Consistency and Standardization: Stored scripts provide a consistent and standardized approach to executing backup and recovery operations. By defining and storing a specific set of RMAN commands, DBAs can ensure that these operations are performed uniformly, reducing the likelihood of errors that might arise from manual command entry or ad-hoc scripts.
  2. Automation and Efficiency: Stored scripts allow for the automation of repetitive tasks, such as regular backups. This not only saves time but also minimizes the risk of human error, as the script will execute the same set of commands every time, regardless of the operator.
  3. Error Checking and Validation: Prior to storing and implementing the scripts, DBAs have the opportunity to thoroughly test and validate the scripts in various scenarios. This ensures that any potential issues are identified and resolved in advance, further reducing the risk of errors during actual operations.
  4. Ease of Use and Training: For new or less experienced DBAs, stored scripts simplify complex RMAN operations. Instead of remembering and typing out intricate command sequences, they can rely on pre-written, tested scripts. This makes training easier and operations more accessible.

To effectively utilize stored scripts in RMAN, the following steps are typically followed:
  • Creating a Stored Script: DBAs can create a stored script by writing the necessary RMAN commands and then using the `CREATE SCRIPT` command in RMAN to store it.
    RMAN> CREATE SCRIPT full_backup AS
  • Executing a Stored Script: To execute a stored script, the `RUN` command is used followed by the `EXECUTE SCRIPT` command.
    RMAN> RUN { EXECUTE SCRIPT full_backup; }
  • Managing Stored Scripts: RMAN also allows for the modification, listing, and deletion of stored scripts, giving DBAs full control over their script repository.

In summary, stored scripts in Oracle's RMAN are a powerful mechanism for enhancing the reliability and efficiency of database backup and recovery operations. By leveraging these scripts, DBAs can significantly mitigate the risk of operator errors, ensuring a more robust and secure Oracle database environment.

One of the most vexing problems a DBA has is how to automate tasks to eliminate potential operator errors. One way to do this is to use stored scripts, which is a feature of Recovery Manager. It is recommended that you seriously consider creating stored scripts for most if not all of your regular DBA tasks. You will use four primary commands with Recovery Manager to work with stored scripts:
create To create and store scripts in the recovery catalog
delete To delete scripts from the recovery catalog
print To print the contents of a stored script
replace To replace an existing stored script with a new stored script

Basic Syntax for creating a Stored Script

The basic syntax for creating a stored script is:
create script script_name {<commands>;}

where <commands> is a set of operations that you want to perform.
An example of a script to back up the USER_DATA tablespace is:
This image displays the syntax to back up USER_DATA.
RMAN > create script backup_usr1orcl{
2> allocate channel ct type disk;
3> backup

We will discuss the command syntax in later modules. What is important to observe is that Recovery Manager compiles and stores the script in the recovery catalog. If there are any syntax problems, Recovery Manager will report them immediately. But it is important to note that there is no check to determine if the USER_DATA tablespace exists.

Delete Stored Script

The basic syntax for deleting a stored script is:
delete script script_name;
Print: The basic syntax for a print of a stored script is:
print script script_name;

An example output of the script that we created earlier is:

Replace Script: The basic syntax of a replace is:
replace script script_name {<commands>;}
The complete syntax of the stored script is beyond the scope of this course. Your current objective is to understand how to manipulate scripts within Recovery Manager. Although you may store these scripts within Recovery Manager, they can also be stored in your file system.
In the next lesson, you will learn about the run command, which allows you to execute your stored scripts.

SEMrush Software