When troubleshooting RMAN output or checking the status of a backup job, it’s essential to have a record of what RMAN ran and the status of each command. There are several methods for logging RMAN output. Some are built-in aspects of the Linux/Unix OS. Others are RMAN-specific features:
- Linux/Unix redirect output to file
- Linux/Unix logging commands
- RMAN SPOOL LOG command
- V$RMAN_OUTPUT view
These logging features are discussed in the next sections.
Redirecting Output to a File
I run almost all RMAN backup jobs from shell scripts. The shell scripts are usually run automatically from a scheduling tool such as cron. When running RMAN commands in this fashion, I always capture the output by instructing the shell command to redirect standard output messaging and standard error messaging to a log file. This is done with the redirection (>) character. This example runs a shell script (rmanback.bsh) and redirects both standard output and standard error output to a log file named rmanback.log:
$ rmanback.bsh 1>/home/oracle/bin/log/rmanback.log 2>&1
Here, 1> instructs standard output to be redirected to the specified file. The 2>&1 instructs the shell script to send standard error output to the same location as standard output.
Tip For further details on how DBAs use shell scripts and Linux features, see Linux Recipes for Oracle DBAs by Darl Kuhn (Apress, 2008).
Capturing Output with Linux/Unix Logging Commands
You can instruct Linux/Unix to create a log file to capture any output that is also being displayed on your screen. This can be done in one of two ways:
- tee
- script
Capturing Output with tee
When you start RMAN, you can send the output you see on your screen to an OS text file, using the tee command:
$ rman | tee /tmp/rman.log
Now, you can connect to the target database and run commands. All the output seen on your screen will be logged to the /tmp/rman.log file:
RMAN> connect target /
RMAN> backup database;
RMAN> exit;
The tee party session stops writing to the log file when you exit RMAN.
Capturing Output with script
The script command is useful because it instructs the OS to log any output that appears at the terminal to a log file. To capture all output, run the script command before connecting to RMAN:
$ script /tmp/rman.log
Script started, file is /tmp/rman.log
$ rman target /
RMAN> backup database;
RMAN> exit;
To end a script session, press Ctrl+D, or type exit. The tmp/rman.log file will contain all output that was displayed on your screen. The script command is useful when you need to capture all the output from a particular time range. For example, you may be running RMAN commands, exiting from RMAN, running SQL*Plus commands, and so on. The script session lasts from the point at which you start script to the point at which you press Ctrl+D.
Logging Output to a File
An easy way to capture RMAN output is to use the SPOOL LOG command to send the output to a file. This example spools a log file from within RMAN:
RMAN> spool log to '/tmp/rmanout.log'
RMAN> set echo on;
RMAN> <run RMAN commands>
RMAN> spool log off;
By default the SPOOL LOG command will overwrite an existing file. If you want to append to the log file, use the keyword APPEND:
RMAN> spool log to '/tmp/rmanout.log' append
You can also direct output to a log file when starting RMAN on the command line, which will overwrite an existing file:
$ rman target / log /tmp/rmanout.log
You can also append to the log file, as follows:
$ rman target / log /tmp/rmanout.log append
When you use SPOOL LOG as shown in the previous examples, the output goes to a file and not to your terminal. Therefore, I hardly ever use SPOOL LOG when running RMAN interactively. The command is mainly a tool for capturing output when running RMAN from scripts.
Querying for Output in the Data Dictionary
If you don’t capture any RMAN output, you can still view the most recent RMAN output by querying the data dictionary. The V$RMAN_OUTPUT view contains messages recently reported by RMAN:
select sid, recid, output
from v$rman_output
order by recid;
The V$RMAN_OUTPUT view is an in-memory object that holds up to 32,768 rows. Information in this view is cleared out when you stop and restart your database. The view is handy when you’re using the RMAN SPOOL LOG command to spool output to a file and cannot view what is happening at your terminal.