RelationalDBDesign RelationalDBDesign


Backup Recovery   «Prev  Next»
Lesson 6Executing backup scripts
ObjectiveRun the backup script.

Executing Backup Scripts in Oracle

To execute the backup script that we created within the previous lesson, issue the call to run the backup_acct procedure, as shown within the RMAN run command:

RMAN> RUN {EXECUTE SCRIPT backup_acct;}

You may want to create a set of standard scripts for routine tasks. For example, you may have a set of scripts that allocate channels (allocate_1_disk, allocate_3_ tapes, and so on). You can call these scripts from within other scripts. Alternatively, you can write the RMAN commands to operating-system command files and invoke them either from within RMAN, byusing the @filename notation, or on the RMAN command line, by using the cmdfile= argument.

Managing archive logs

RMAN identifies when ARCH has finished writing to a log, which is available to the DBA. RMAN provides several features to assist you with backing up and keeping track of archive log files. You back up archived redo logs in much the same way you do datafiles. Use the RMAN backup command and specify criteria indicating the files to be backed up. Because RMAN works with the contents of the control files rather than the operating-system directory, it knows which log files are still being written by ARCH.
The following script backs up all complete archived redo logs within the log_arch_dest directory. (Note that you can use RMAN and SQL statements within a single piece of code.)

RMAN> REPLACE SCRIPT ARCHLOG_ALL {
2> ALLOCATE CHANNEL T1 TYPE sbt_tape;
3> SQL "ALTER SYSTEM ARCHIVELOG CURRENT";
3> BACKUP ARCHIVELOG ALL FORMAT 'arch_%u';
4> RELEASE CHANNEL T1;
5> }

You can be more selective when deciding which logs to back up, and you can delete log files once they've been successfully backed up. Selection criteria can include creation date/time, sequence number, or thread number.
The following example backs up, then deletes all logs generated more than 48 hours ago:

RMAN> REPLACE SCRIPT archlog_old {
2> ALLOCATE CHANNEL T1 TYPE sbt_tape;
3> BACKUP ARCHIVELOG
4> UNTIL TIME 'sysdate-2'
5> ALL FORMAT 'arch_%u'
6> DELETE INPUT;
7> RELEASE CHANNEL T1;
8> }

A complete backup

You can base a full-database-backup strategy on the examples shown so far. If you created a script called backup_db that included the code within the first database-backup example, the following code extract could perform full-database backups, including backups of control files and archived redo logs. It also automates housekeeping for log_arch_dest.

RMAN> RUN {
2> EXECUTE SCRIPT backup_db;
3> EXECUTE SCRIPT archlog_old;
4> EXECUTE SCRIPT archlog_all;
5> }

Incremental backups

If your database is particularly large, you may want to consider making incremental backups. Unlike incremental exports, which operate at a table level, RMAN incremental backups back up only changed blocks. This approach optimizes not only backup times but recovery operations as well, because RMAN intelligently decides what combination of full, incremental, and archive-log backups will produce the optimal recovery path.
RMAN uses the concept of multilevel incremental backups, with levels 0, 1, or 2. Level 0 is equivalent to a full backup. An incremental backup at a level greater than 0 copies only those blocks that have changed since a previous incremental backup at the same or lower level.
For example, Level 1 incremental backup backs up any blocks that have changed since the most recent backup at Level 0 or 1.
Level 2 backup backs up only blocks that have changed since the last backup at any level.
To execute an incremental backup, include the incremental keyword and a level number within the backup statement:

RMAN> RUN {
2> ALLOCATE CHANNEL T1 TYPE sbt_tape;
3> BACKUP
4> INCREMENTAL LEVEL 0
5> FORMAT 'full_inc1_%u'
6> DATABASE;
7> RELEASE CHANNEL T1;
8> 
}

Executing backup Scripts
We will detail the necessary steps for creating a backup script. But prior to that, you may find the link above helpful for understanding the benefits of using RMAN to write a backup script.
The following SlideShow illustrates the details of writing a backup script by using the line mode of RMAN:

  1. Through RMAN, you can specify where to place the backup files by using the format parameter.
  2. RMAN creates several client connections, or channels, between the target database and the backup storage device.
  3. RMAN scripts can be integrated with operating-system command scripts.
  4. You can be more selective when deciding which archive logs to be backup, and you can delete log files once they are successfully backed up
  5. The script starts with RUN statement, which specifies that the following script must be executed.
  6. This is an example of a specific type of backup for the TEMP tablespace

Writing Backup Scripts

Rman allocate Channel

Click the link below to create a script that performs a complete database backup.
rman allocate channel
The next lesson describes specifying a character set for a control file.