RMAN supports the use of stored scripts and command files to help manage recurring tasks. The RMAN RUN command provides a degree of flow-of-control in your scripts.

Command Files

A command file is a text file which contains RMAN commands as you would enter them at the command line. You can run the command file by specifying its name on the command line. If the LOG command line argument is specified, RMAN directs output to the named log file. Command files are one way to automate scheduled backups through an operating system job control facility.

RMAN TARGET / CATALOG rman/cat@catdb CMDFILE commandfile.rcv LOG outfile.txt

Stored Scripts

  • Stored scripts stores sequence of RMAN commands.
  • Always available to any RMAN client that can connect to the database and catalog.
  • Scripts can be local or global (associated with target DB / can be run against any target DB).
  • To work with stored scripts u must be connect with both target DB and recovery catalog.

Commands Valid Only in RUN Blocks

There are RMAN commands which are only valid in RUN blocks. These typically involve setting up the environment within which the statements in the RUN block will execute.

ALLOCATE CHANNEL  
SET NEWNAME FOR DATAFILE.

Commands Not Valid in RUN Blocks

There are a number of RMAN commands which cannot be used in RUN blocks. Typically these are used to control the RMAN environment

CONNECT 
CONFIGURE C
REATE CATALOG,DROP CATALOG, UPGRADE CATALOG
CREATE SCRIPT,DELETE SCRIPT,REPLACE SCRIPT
LIST
REPORT

You can include these commands inside command files, as long as they are not wrapped inside a RUN block. You cannot use them inside a stored script from the recovery catalog, because the contents of a stored script are executed within a RUN block.

 

RMAN Output to a Log File

RMAN client sends the output to the terminal. If LOG option specified, then output is written to a log file instead.

V$RMAN_OUTPUT VIEW   currently executing RMAN jobs 
V$RMAN_STATUS VIEW contains metadata about jobs IN progress & completed jobs

Operations of Stored Scripts

Connect with target DB and catalog

RMAN> CONNECT TARGET SYS/SRDC@TEST1       -- connect with target database 
RMAN> CONNECT CATALOG RMAN/CAT@DEVDB -- connect with recovery catalog

Create script - CREATE SCRIPT

CREATE SCRIPT full_backup            --Create local script 
{
BACKUP DATABASE PLUS ARCHIVELOG;
DELETE OBSOLETE;
}

--Create global script with comments
CREATE GLOBAL SCRIPT global_full_backup
COMMENT 'use only with ARCHIVELOG mode databases'
{
BACKUP DATABASE PLUS ARCHIVELOG;
DELETE OBSOLETE;
}

Create local or global scripts and read contents form text file. File must be start with { and end with a } CREATE SCRIPT full_backup FROM FILE 'my_script_file.txt';

Execute Script - EXECUTE SCRIPT

RUN  
{
EXECUTE SCRIPT --Execute local script
full_backup;
}

RUN
{
EXECUTE GLOBAL SCRIPT --Execute Global script
global_full_backup ;
}

OR
RUN
{
EXECUTE SCRIPT global_full_backup;
}

 

Display stored script contest - PRINT SCRIPT

PRINT SCRIPT full_backup;                      -- display local script 
PRINT GLOBAL SCRIPT global_full_backup; -- display global script

-- send contents to file
PRINT GLOBAL SCRIPT global_full_backup TO FILE 'my_script_file.txt';

 

List stored script name - LIST SCRIPT

LIST SCRIPT NAMES;                -- name of all local script 
LIST GLOBAL SCRIPT NAMES; -- name of all Global script
LIST ALL SCRIPT NAMES; -- name of all script including local and global

Update stored script - REPLACE SCRIPT

IF the script IS does NOT already EXISTS RMAN creates its.
REPLACE SCRIPT full_backup -- Replace local script
{ BACKUP DATABASE PLUS ARCHIVELOG; }

REPLACE GLOBAL SCRIPT global_full_backup -- Replace global script

COMMENT 'A script for full backup to be used with any database'
{ BACKUP AS BACKUPSET DATABASE PLUS ARCHIVELOG; }

-- Replace with text file
REPLACE GLOBAL SCRIPT global_full_backup FROM FILE 'my_script_file.txt';

 

Delete stored script - DELETE SCRIPT

DELETE SCRIPT 'full_backup'; 
DELETE GLOBAL SCRIPT 'global_full_backup';
Go to top
JSN Boot template designed by JoomlaShine.com