Lesson 5 | The FORMAT parameter and scripting in RMAN |
Objective | Create a backup script by using the FORMAT parameter. |
FORMAT Parameter RMAN scripting
Placing backup files by using the FORMAT parameter
When you back up to a disk, you need to tell RMAN where to put the backup files by using the format parameter.
The %u variable causes RMAN to generate a unique eight-character name for the backup set.
You can use several other variables, such as %d for database name, with the FORMAT parameter.
RMAN creates several client connections, or channels, between the target database and the backup storage device.
RMAN can create backup sets on disk or directly on tape. The first line of code specifies the channel (in this case, the disk drive),
within which it stores the data.
So, within three lines of code, you can accomplish a full backup and dynamically identify the database files to be included.
RMAN is very flexible, however, and can perform complex backup routines without your having to add much complexity to the code.
The following script, for example, performs a full database backup to tape, in two parallel streams (two channels allocated, each of type 'sbt_tape'), automatically excluding any data files that support read-only tablespaces:
RMAN> RUN {
2> ALLOCATE CHANNEL T1 TYPE 'sbt_tape';
3> ALLOCATE CHANNEL T2 TYPE 'sbt_tape';
4> BACKUP
5> FORMAT 'full_d%d_u%u'
6> FILESPERSET 10
7> SKIP READONLY
8> DATABASE;
9> RELEASE CHANNEL T1;
10> RELEASE CHANNEL T2;
11> }
The filesperset
value specifies the maximum number of datafiles that RMAN will write to a backup set.
The combination of multiple output channels and files per set governs the parallelism of the operation. RMAN backups that include the first data file within the SYSTEM
tablespace automatically include a copy of the current control file.
To back up the control file explicitly, add the INCLUDE CURRENT
CONTROLFILE
clause to your backup statement.
Scripting in RMAN
You can integrate RMAN into operating-system command scripts, either as a call to RMAN with a command file or with in-line RMAN scripts.
You can store RMAN commands within scripts and hold them within the recovery catalog itself.
The following command creates a script for backing up the TEMP
tablespace:
RMAN> REPLACE SCRIPT BACKUP_TEMP {
2> ALLOCATE CHANNEL C1 TYPE DISK;
3> BACKUP TABLESPACE TEMP
4> FORMAT 'D:\BACKUPS\TEMP%u';
5> RELEASE CHANNEL C1;
6> }
The next lesson runs a backup script.