Sunday, November 9, 2014

RMAN-Creating Dynamic Command Files

Problem
You want to create dynamic command files that can be used for multiple jobs by passing substitution variables.

Solution
You can create dynamic shell scripts by using substitution variables in the RMAN command files inside the shell scripts. You can specify values for use in substitution variables through the new using clause when calling an RMAN command file. You use the &integer syntax (&1, &2, and so on) to indicate to which variable your substitution values should be assigned, just as in SQL*Plus.
Let’s review an example that shows how to create a dynamic backup shell script.

1. Create the RMAN command file that uses two substitution variables:

#backup.cmd
connect target sys/<sys_password>@prod1
run {
backup database
tag &1
format &2
}
exit;


The command file shown here will back up the database using two substitution variables (&1 and &2), one for the backup tag and the other for the string value in the format specification.
2. Create the shell script to run the backup command file you created in step 1:

#!/bin/tcsh
# script name: nightly_backup.sh
set tag=$argv(1)
set format=$argv[2]
rman @backup.cmd using $tag $format


3. Now that you have created a dynamic shell script, you can specify the arguments for the tag and format variables on the command line, thus being able to modify them for different jobs. Here’s an example:

$ nightly_backup.sh longterm_backup back0420

The example shows how to execute the shell script nightly_backup.sh with two dynamic parameters, longterm_backup (tag) and back0420 (format string).

How It Works
The ability to use substitution variables in RMAN scripts is new in Oracle Database 11g. The use of substitution variables in RMAN scripts is similar to the way you specify substitution variables in operating system and SQL*Plus scripts. Specifying substitution variables lets you use the same command file by modifying it appropriately for different backup tasks, thus
making the command file dynamic.

No comments:

Post a Comment