You are on page 1of 2

Command Files

Oracle RMAN command files are plain-text files and similar to shell scripts in U
NIX or batch files in Microsoft Windows. Listing 1 shows a very simple example c
ommand file named backup_ts_users.rman used to back up the USERS tablespace. The fil
e extension .rman is not necessary, but it is helpful in making the meaning of t
he file clear.
Code Listing 1: Command file for backing up USERS tablespace

connect target /
connect catalog rman/secretpass@rmancat
run {
allocate channel c1 type disk format '/orabak/%U';
backup tablespace users;
}

You can call a command file in several ways. From the Oracle RMAN prompt, you ca
n call the example command file as follows:

RMAN> @backup_ts_users.rman

Note that the command file is executed by the @ sign. It is important, however,
to provide the full name of the command file, including the extension. (The Orac
le RMAN executable does not expect or apply a default extension.)
You can also call the command file directly from the command line as

rman @backup_ts_users.rman

This approach for calling the script is highly useful in shell scripts or batch
files for making backups. Also note that instead of using the @ sign to call the
command file, you can use the cmdfile parameter as follows:

rman cmdfile=backup_ts_users.rman

Note that the CONNECT clauses are inside the backup_ts_users.rman command file,
so there is no reason to provide the password in the command line meaning that you
can eliminate the risk of accidental exposure of the password. Had we not inclu
ded the password of the catalog user rman inside the command file, we would have
had to call the Oracle RMAN executable like this:

rman target=/ catalog=


rman/secretpass@rmancat
If this command were executed, someone on the server could easily get the passwo
rd of the catalog user by checking the process. When the command file contains t
he connection information including the password for the catalog user, the sensitive
information is not visible to anyone watching the process. Note that you should
also set the permissions of the command file in such a way that nonadmin users
will not be able to read it.
Passing parameters. The backup_ts_users.rman command file works well, but it s too
specific. It forces the output of the backup to one specific directory and back
s up only one tablespace (USERS). If you want to back up to a different location
or back up a different tablespace, you have to create a new script.
A better strategy is to make an Oracle RMAN command file parameter-driven. Rathe
r than hard-coding specific values in the script, you can include parameters who
se values are passed at runtime. Listing 2 shows a modified version of the backu
p_ts_users .rman command file, named backup_ts_generic.rman. Instead of actual v
alues, the new command file includes the parameters (also known as placeholders
or substitution variables ) &1 and &2. With a parameter-driven command file, you
can define any number of parameters in this manner and pass the values at runti
me.