Database Backup and Recovery Reference
ContentsOpens a new window
Opens a new window
Page 29 of 152

EXECUTE SCRIPT

Purpose

Use the EXECUTE SCRIPT command to run a local or global RMAN script stored in the recovery catalog.

See Also:

Prerequisites

Use EXECUTE SCRIPT only within the braces of a RUNOpens a new window command. RMAN must be connected to the recovery catalog with the CATALOG command-line option or the CONNECTOpens a new window CATALOG command. The recovery catalog database must be open.

Usage Notes

When you run an EXECUTE SCRIPT command within a RUNOpens a new window block, RMAN places the contents of the script in that RUN block. Therefore, do not allocate a channel within the RUN block if you also allocate it in the script.

If GLOBAL is specified, then a global script with this name must exist in the recovery catalog; otherwise, RMAN returns error RMAN-06004. If GLOBAL is not specified, then RMAN searches for a local stored script defined for the current target database. If no local script with this name is found, then RMAN searches for a global script by the same name and executes it if one is found.

Semantics

Syntax Element Description
GLOBAL Specifies the execution of a global stored script instead of a local one.

See Also: "Usage Notes"Opens a new window for an explanation of the difference between global and local scripts

SCRIPT script_name Specifies the name of the stored script to execute. Quotes must be used around the script name when the name contains either spaces or reserved words.

USING
   [string_or_identifier
   | integer]
Specifies one or more values for use in substitution variables in a stored script (see Example 2-96Opens a new window).

See Also: CREATE SCRIPTOpens a new window to learn how to create a stored script with substitution variables, and RMANOpens a new window and @ (at sign)Opens a new window to learn how to use substitution variables with RMAN


Example

Example 2-95 Executing a Stored Script

This example uses LISTOpens a new window to list the script stored in the recovery catalog and PRINT SCRIPTOpens a new window to show the contents of global_backup_db, which was created in Example 2-71, "Creating a Global Stored Script"Opens a new window. Finally, the example runs global_backup_db to back up the database.

RMAN> LIST SCRIPT NAMES;
 
List of Stored Scripts in Recovery Catalog

    Global Scripts

       Script Name
       Description
       -----------------------------------------------------------------------
       global_backup_db
       back up any database from the recovery catalog, with logs

RMAN> PRINT SCRIPT global_backup_db;

printing stored global script: global_backup_db
{
    BACKUP DATABASE PLUS ARCHIVELOG;
}

RMAN> RUN { EXECUTE GLOBAL SCRIPT global_backup_db; }

executing global script: global_backup_db


Starting backup at 07-JUN-13
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=120 device type=DISK
.
.
.

Example 2-96 Creating and Executing a Stored Script That Uses Substitution Variables

After starting RMAN and connecting to a target database and recovery catalog, use REPLACE SCRIPTOpens a new window to create a backup script that includes three substitution variables. RMAN prompts you to enter initial values for the variables (user input is in bold).

RMAN> REPLACE SCRIPT 
2>  backup_df { BACKUP DATAFILE &1 TAG &2.1 FORMAT '/disk1/&3_%U'; }
 Enter value for 1: 1
 
Enter value for 2: df1_backup
 
Enter value for 3: df1

starting full resync of recovery catalog
full resync complete
created script backup_df
 

Later, you can execute the backup_df script with different values. The following example passes the values 3, test_backup, and test to the substitution variables in the stored script:

RMAN> RUN { EXECUTE SCRIPT backup_df USING 3 test_backup df3; }

After the values are substituted, RMAN executes the BACKUP command as follows:

BACKUP DATAFILE 3 TAG test_backup1 FORMAT '/disk1/df3_%U';