Rman Backup with Stored Script

A stored scripts offer an alternative to command files for managing frequently used sequences of RMAN commands. The advantage of a stored script over a command file is that a stored script is always available to any RMAN client that can connect to the target database and recovery catalog, whereas command files are only available if the RMAN client has access to the file system on which they are stored.

A Stored scripts can be global or local. A local stored script is associated with the target database to which RMAN is connected when the script is created, and can only be executed when you are connected to that target database. A global stored script can be run against any database registered in the recovery catalog, if the RMAN client is connected to the recovery catalog and a target database.
Note that to work with stored scripts, even global ones, you must be connected to both a recovery catalog and a target instance.

RMAN TARGET SYS/ORACLE@ORCL3 CATALOG RMAN/RMAN@SHAAN
NOW on RMAN prompt create the desired scripts. Before creating scripts you must run and check the correctness of script.
CREATE GLOBAL SCRIPT full_backup
{
BACKUP DATABASE PLUS ARCHIVELOG;
DELETE OBSOLETE;
}
CREATE SCRIPT global_full_backup
{
BACKUP DATABASE PLUS ARCHIVELOG;
DELETE OBSOLETE;
}
CREATE GLOBAL SCRIPT global_full_backup
COMMENT ‘use only with ARCHIVELOG mode databases’
{
BACKUP DATABASE PLUS ARCHIVELOG;
DELETE OBSOLETE;
}
You can also create local and global script by reading its contents from text file. Before being Create Script you must create “my_script_file.txt” on the given location.
CREATE SCRIPT full_backup FROM FILE ‘D:\Backup\Rman\my_script_file.txt’;
How to EXECUTE the Script:
RUN
{
EXECUTE SCRIPT full_backup;
}
RUN
{
EXECUTE GLOBAL SCRIPT full_backup;
}
Executing a global script only affects the connected target database; to run a global script across multiple databases, you must connect the RMAN client to each one separately and execute the script. Your script will use the automatic channels configured at the time you execute the script. Use ALLOCATE CHANNEL commands in the script if you need to override the configured channels. Note that, because of the RUN block, if an RMAN command in the script fails, subsequent RMAN commands in the script will not execute.
DISPLAYING THE CONTENTS OF STORED SCRIPTS:
rman> PRINT SCRIPT full_backup;
rman> PRINT SCRIPT full_backup TO FILE ‘my_script_file.txt’;
rman> PRINT GLOBAL SCRIPT global_full_backup;
rman> PRINT GLOBAL SCRIPT global_full_backup TO FILE ‘my_script_file.txt’;
Listing Stored Scripts:
LIST SCRIPT NAMES;
This command displays the names of all stored scripts, both global and local, that can be executed for the currently connected target database: If RMAN is not connected to a target database when the LIST SCRIPT NAMES command is run, then RMAN will respond with an error.
LIST GLOBAL SCRIPT NAMES;
LIST ALL SCRIPT NAMES;
LIST GLOBAL SCRIPT NAMES and LIST ALL SCRIPT NAMES are the only commands that work when RMAN is connected to a recovery catalog without connecting to a target instance.
How to Update Stored Script:
REPLACE SCRIPT full_backup
{
BACKUP DATABASE PLUS ARCHIVELOG;
}
REPLACE GLOBAL SCRIPT global_full_backup
COMMENT ‘A script for full backup to be used with any database’
{
BACKUP AS BACKUPSET DATABASE PLUS ARCHIVELOG;
}
Global scripts can be updated using the REPLACE GLOBAL SCRIPT command when connected to a recovery catalog, as follows:
REPLACE GLOBAL SCRIPT global_full_backup FROM FILE ‘D:\BACKUP\RMAN\my_script_file.txt’;
DELETING STORED SCRIPTS:
DELETE SCRIPT ‘full_backup’;
DELETE GLOBAL SCRIPT ‘global_full_backup’;
DELETE SCRIPT ‘global_full_backup’;
If you use DELETE SCRIPT without GLOBAL, and there is no stored script for the target database with the specified name, RMAN will look for a global stored script by the specified name and delete the global script if it exists.
Starting the RMAN Client and Running a Stored Script:
CMD> rman TARGET SYS/oracle@trgt CATALOG rman/cat@catdb SCRIPT ‘full_backup’;
Restrictions on Stored Script Names:
1. Avoid script name that begins with character other than A-Z or that are the same as reserve word.
2. When starting the RMAN client with the script name argument and if the local and global script name defiend with the same name then rman gives the priority to execute the local script.
3. For the EXECUTE SCRIPT, DELETE SCRIPT and PRINT SCRIPT commands, if the script name passed as an argument is not the name of a script defined for the connected target instance, RMAN will look for a global script by the same name to execute, delete or print.
4. Consider using some naming convetion to avoid mistakes due to confusion between global stored scripts and local stored scripts.
References:
http://docs.oracle.com/cd/B28359_01/backup.111/b28273/rcmsynta014.htm

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: