Lesson 5 | The FORMAT parameter and scripting in RMAN |
Objective | Create a backup script by using the FORMAT parameter. |
FORMAT Parameter RMAN scripting
A backup script can be created using the FORMAT parameter in Oracle. The FORMAT parameter allows you to specify the format of the backup files that are created. This is useful for customizing the backup process and for creating backup files that are compatible with specific backup and restore tools.
To create a backup script using the FORMAT parameter, you can use the following steps:
- Create a new text file and name it with a .RMAN extension.
- In the text file, enter the following RMAN commands:
CONNECT TARGET <target_database>;
CONNECT RCVCAT <recovery_catalog>;
BACKUP TARGET <target_database> FORMAT '<backup_file_format>';
Where:
- `<target_database>` is the name of the target database that you want to back up.
- `<recovery_catalog>` is the name of the Recovery Catalog database.
- `<ltbackup_file_format>` is the format of the backup files that you want to create.
For example, the following RMAN script would back up the database "PETS" to disk in the format of a compressed TAR archive:
CONNECT TARGET RMAN/RMAN@PETS;
CONNECT RCVCAT RMAN/RMAN@BACKUP;
BACKUP TARGET RMAN/RMAN@PETS FORMAT 'tar:cvf /backup/pets.tar';
- Save the text file.
- Make the text file executable by running the following command:
chmod +x <backup_script_name>
- To run the backup script, type the following command:
./<backup_script_name>
This will create a backup of the database "PETS" to the file `/backup/pets.tar`.
The FORMAT parameter is a powerful tool that can be used to create backup scripts that are customized to your specific needs. For more information on the FORMAT parameter, please refer to the Oracle Database Backup and Recovery User's Guide.
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> }
RMAN Channels
RMAN client connections are known as "channels" in Oracle terminology. Channels are used to establish communication between the RMAN client and the target database or Recovery Catalog database.
Each channel is associated with a specific server session on the target database or Recovery Catalog database. This allows RMAN to perform concurrent operations on the database, such as backing up multiple datafiles or restoring multiple tablespaces.
Channels can be created manually using the `ALLOCATE CHANNEL` command, or they can be created automatically by RMAN. By default, RMAN will create a single channel when you connect to the database or Recovery Catalog. However, you can increase the number of channels to improve performance.
To create a channel manually, you can use the following RMAN command:
ALLOCATE CHANNEL <channel_name> DEVICE TYPE <device_type> <parameters>;
Where:
- `<channel_name>` is the name of the channel.
- `<device_type> ` is the type of device that the channel will use to communicate with the target database or Recovery Catalog database.
- `<parameters>` are any additional parameters that are required for the device type.
Once a channel has been created, it can be used to perform any RMAN operation. For example, the following RMAN command would back up the datafile `datafile1.dbf` to disk using the channel `channel1`:
BACKUP DATAFILE datafile1.dbf CHANNEL channel1;
Channels are an important part of the RMAN architecture. By understanding how channels work, you can better manage your RMAN backups and restores.
For more information on channels, please refer to the Oracle Database Backup and Recovery User's Guide.
The next lesson runs a backup script.