# +----------------------------------------------------------------------------+
# |                          Jeffrey M. Hunter                                 |
# |                      jhunter@idevelopment.info                             |
# |                         www.idevelopment.info                              |
# |----------------------------------------------------------------------------|
# |      Copyright (c) 1998-2012 Jeffrey M. Hunter. All rights reserved.       |
# |----------------------------------------------------------------------------|
# | DATABASE : Oracle                                                          |
# | FILE     : rman_configuration_setup_9i.rcv                                 |
# | CLASS    : Recovery Manager                                                |
# | PURPOSE  : Provides an example RMAN script used to persist Oracle9i RMAN   |
# |            configuration parameters to the control file of the target      |
# |            database. These parameters are used to control default RMAN     |
# |            operations. Some of the operations that can be performed are:   |
# |                                                                            |
# |              - The required number of backups of each datafile.            |
# |              - The number of server processes that will perform Backup     |
# |                and Restore tasks in parallel.                              |
# |              - The directory where on-disk backups will be stored.         |
# |                                                                            |
# |            This script will can be run by RMAN to configure (persist) the  |
# |            default parameters for the target database. For parameters that |
# |            should maintain their default setting, should use the "CLEAR"   |
# |            command to reset the parameter explicitly.                      |
# |                                                                            |
# | NOTE     : As with any code, ensure to test this script in a development   |
# |            environment before attempting to run it in production.          |
# +----------------------------------------------------------------------------+

# +----------------------------------------------------------------------------+
# |                  <<<    RMAN DEFAULT SETTING    >>>                        |
# |----------------------------------------------------------------------------+--------------------------+
# | CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default                                                 |
# | CONFIGURE BACKUP OPTIMIZATION OFF; # default                                                          |
# | CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default                                                      |
# | CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default                                                       |
# | CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default                       |
# | CONFIGURE DEVICE TYPE DISK PARALLELISM 1; # default                                                   |
# | CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default                                 |
# | CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default                               |
# | CONFIGURE MAXSETSIZE TO UNLIMITED; # default                                                          |
# | CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/9.2.0/dbs/snapcf_ORA920.f'; # default |
# +-------------------------------------------------------------------------------------------------------+



# +----------------------------------------------------------------------------+
# | RETENTION POLICY                                                           |
# |----------------------------------------------------------------------------|
# | Used to control how long RMAN will keep backups. This can be configured by |
# | the "number" of backups taken, or by the numbers of "days" to keep. Here   |
# | is an example of both:                                                     |
# |                                                                            |
# |   CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 3 DAYS;                 |
# |                                                                            |
# |   CONFIGURE RETENTION POLICY TO REDUNDANCY 2;                              |
# |                                                                            |
# | Note that when configuring a retention policy, RMAN will *not* cause       |
# | backups to be automatically deleted. The retention policy will, however,   |
# | mark backups as OBSOLETE that have fallen outside the retention period.    |
# | RMAN commands like "REPORT OBSOLETE" and "DELETE OBSOLETE" will work with  |
# | these obsolete backups.                                                    |
# +----------------------------------------------------------------------------+

CONFIGURE RETENTION POLICY TO REDUNDANCY 2;



# +----------------------------------------------------------------------------+
# | BACKUP OPTIMIZATION                                                        |
# |----------------------------------------------------------------------------|
# | Used to enable or disable backup optimization. Backup file optimization    |
# | can assist in reducing the space used to backup the database. When         |
# | performing an RMAN backup, a check is done on the file before backup to    |
# | see if the file already exists in a backupset with the same information:   |
# | (dbid, checkpoint, and resetlogs data).                                    |
# |                                                                            |
# | For archive logs, the same file means the same dbid, thread, sequence, and |
# | resetlogs data. If the DELETE INPUT option is used, RMAN deletes all the   |
# | files that would have been backed up, even when the file is not included   |
# | due to file optimization.                                                  |
# |                                                                            |
# | The two possible values for backup optimization is ON and OFF as shown in  |
# | the following example syntax:                                              |
# |                                                                            |
# |   CONFIGURE BACKUP OPTIMIZATION OFF;                                       |
# |                                                                            |
# |   CONFIGURE BACKUP OPTIMIZATION ON;                                        |
# |                                                                            |
# | Use caution when enabling backup optimization if you use a media manager   |
# | that has an expiration policy. The media manager can expire tapes          |
# | containing backups (using its media control software), and RMAN will *not* |
# | make new backups because of optimization. One way to protect from this is  |
# | to run CROSSCHECK periodically to synchronize the repository with the      |
# | media manager.                                                             |
# |                                                                            |
# | Also note that you should consider how backup optimization works with      |
# | regards to the RETENTION POLICY. RMAN will only work with files within     |
# | the retention period. For example, consider performing a backup with       |
# | optimization enabled and a retention period of 3 days. RMAN will only      |
# | compare the datafile with backup sets within the 3 day period - even if    |
# | the datafile it is about to backup hasn't changed within that 3 days.      |
# +----------------------------------------------------------------------------+

CONFIGURE BACKUP OPTIMIZATION CLEAR;



# +----------------------------------------------------------------------------+
# | DEFAULT DEVICE TYPE                                                        |
# |----------------------------------------------------------------------------|
# | Configures the default backup / restore device type for automatic          |
# | channels. The two values for now are TAPE (SBT) and DISK (DISK) - the      |
# | default being DISK. By default, the BACKUP and COPY commands only allocate |
# | channels of the default device type. For example, if you configure         |
# | automatic channels for DISK and sbt and set the default device type to     |
# | DISK, then RMAN only allocates disk channels when you run the BACKUP       |
# | DATABASE command. You can override this behavior either by manually        |
# | allocating channels in a RUN command, or by specifying DEVICE TYPE on the  |
# | BACKUP command itself. The RESTORE command allocates automatic channels of |
# | all configured device types, regardless of the default device type. The    |
# | RESTORE command obeys the PARALLELISM setting for each configured device   |
# | type.                                                                      |
# |                                                                            |
# | The following two examples show the syntax for configuring the default     |
# | device type to TAPE (SBT) - then another command to re-configure the       |
# | default device type to DISK:                                               |
# |                                                                            |
# |   CONFIGURE DEFAULT DEVICE TYPE TO SBT;                                    |
# |                                                                            |
# |   CONFIGURE DEFAULT DEVICE TYPE TO DISK;                                   |
# |                                                                            |
# +----------------------------------------------------------------------------+

CONFIGURE DEFAULT DEVICE TYPE TO DISK;



# +----------------------------------------------------------------------------+
# | CONTROLFILE AUTOBACKUP                                                     |
# |----------------------------------------------------------------------------|
# | Starting with Oracle9i, RMAN offers the ability to backup the control file |
# | and the database parameter file (SPFILE only) and have this take place     |
# | automatically by default after each backup. By default, this feature is    |
# | not enabled. This feature can be enabled or disabled using the example     |
# | syntax below:                                                              |
# |                                                                            |
# |   CONFIGURE CONTROLFILE AUTOBACKUP ON;                                     |
# |                                                                            |
# |   CONFIGURE CONTROLFILE AUTOBACKUP OFF;                                    |
# |                                                                            |
# | When the CONTROLFILE AUTOBACKUP feature is enabled, then RMAN performs a   |
# | control file autobackup in the following circumstances:                    |
# |                                                                            |
# |     - After every BACKUP or COPY command issued at the RMAN prompt.        |
# |     - Whenever a BACKUP or COPY command within a RUN block is followed     |
# |       by a command that is neither BACKUP nor COPY.                        |
# |     - At the end of every RUN block if the last command in the block was   |
# |       either BACKUP or COPY.                                               |
# |     - After database structural changes such as adding a new tablespace,   |
# |       altering the state of a tablespace or datafile (for example,         |
# |       bringing it online), adding a new online redo log, renaming a file,  |
# |       adding a new redo thread, and so forth. This type of autobackup,     |
# |       unlike autobackups that occur in the preceding circumstances, goes   |
# |       only to disk. You can run:                                           |
# |       CONFIGURE CONTROLFILE AUTOBACKUP FOR DEVICE TYPE DISK                |
# |       to set a nondefault disk location.                                   |
# |                                                                            |
# | The "first channel" allocated during the BACKUP or COPY job creates the    |
# | autobackup and places it "into its own backup set"; for post-structural    |
# | autobackups, the "default disk channel" makes the backup.                  |
# |                                                                            |
# | RMAN writes both the CONTROLFILE and the SPFILE (if the database was       |
# | started with an SPFILE) to the same backup piece.                          |
# | After the CONTROLFILE AUTOBACKUP completes, Oracle writes a message        |
# | containing the complete path of the backup piece and the device type to    |
# | the alert log.                                                             |
# |                                                                            |
# | RMAN automatically backs up the current control file using the default     |
# | format of %F (see entry for CONFIGURE CONTROLFILE AUTOBACKUP FORMAT for an |
# | explanation of this substitution variable). You can change this format     |
# | using the CONFIGURE CONTROLFILE AUTOBACKUP FORMAT and SET CONTROLFILE      |
# | AUTOBACKUP FORMAT commands.                                                |
# |                                                                            |
# | When this feature is disabled, any BACKUP command that includes datafile 1 |
# | (including BACKUP DATABASE) automatically includes the current control     |
# | file and server parameter file in the backup set. Otherwise, RMAN does not |
# | include these files.                                                       |
# |                                                                            |
# | NOTE: You may see occasions where RMAN will sometimes automatically        |
# | include the CONTROLFILE and SPFILE in the backupsets during a backup. This |
# | is normal and is documented (above). When CONTROLFILE AUTOBACKUP is not    |
# | enabled, the CONTROLFILE and SPFILE, (if the database was started with an  |
# | spfile), are included automatically when datafile 1 is backed up. Consider |
# | the  following backup:                                                     |
# |                                                                            |
# |     RMAN> backup datafile 1;                                               |
# |                                                                            |
# | It will include the CONTROLFILE and the SPFILE (when the database is       |
# | started with a spfile).                                                    |
# +----------------------------------------------------------------------------+

CONFIGURE CONTROLFILE AUTOBACKUP ON;



# +----------------------------------------------------------------------------+
# | CONTROLFILE AUTOBACKUP FORMAT                                              |
# |----------------------------------------------------------------------------|
# | Configures the default filename format for the control file autobackup on  |
# | the specified device type. By default, the initial format is %F for all    |
# | devices. Any default format string specified with CONFIGURE must include   |
# | the %F substitution variable (see BACKUP). This variable translates into   |
# | c-IIIIIIIIII-YYYYMMDD-QQ, where:                                           |
# |                                                                            |
# |   - IIIIIIIIII  stands for the DBID. (The DBID is printed in decimal so    |
# |                 that it can be easily associated with the target database. |
# |   - YYYYMMDD    is a time stamp in the Gregorian calendar of the day the   |
# |                 backup is generated.                                       |
# |   - QQ          is the sequence in hexadecimal number that starts with 00  |
# |                 and has a maximum of 'FF' (256).                           |
# |                                                                            |
# | Specify CLEAR to return the format to the default %F.                      |
# |                                                                            |
# | NOTE: The %F tag is essential for RMAN to be able to restore the file      |
# | without a recovery catalog.                                                |
# +----------------------------------------------------------------------------+

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/orabackup/rman/ORA920/%F';



# +----------------------------------------------------------------------------+
# | PARALLELISM                                                                |
# |----------------------------------------------------------------------------|
# | Configure RMAN to use [n] number of disk channels for backup, restore,     |
# | recovery, and maintenance operations. Device types that are eligible for   |
# | use in jobs that use automatic channels can sets the degree of channel     |
# | parallelism. (The DISK device type is the default)                         |
# |                                                                            |
# | The PARALLELISM parameter specifies the number of automatic channels of    |
# | the specified device type allocated for RMAN jobs. RMAN always allocates   |
# | the number of channels specified by PARALLELISM, although it may actually  |
# | use only a subset of these channels.                                       |
# |                                                                            |
# | By default, PARALLELISM = 1.                                               |
# |                                                                            |
# | Take the following example; you can set PARALLELISM for DISK backups to 3. |
# | If you configure automatic channels of type disk and tape, and set the     |
# | default device type as disk, then RMAN allocates three disk channels when  |
# | you run BACKUP DATABASE at the RMAN prompt.                                |
# |                                                                            |
# | To change the parallelism for a device type to [n], run:                   |
# |                                                                            |
# |     CONFIGURE DEVICE TYPE [DISK | SBT]  PARALLELISM [n];                   |
# |                                                                            |
# | Here are several examples of how to configure PARALLELISM to 3 for sbt and |
# | then change it to 2:                                                       |
# |                                                                            |
# |     CONFIGURE DEVICE TYPE sbt PARALLELISM 3;                               |
# |     CONFIGURE DEVICE TYPE sbt PARALLELISM 2;                               |
# |                                                                            |
# | Another example that configures parallelism to 2 for automatic disk        |
# | channel.                                                                   |
# |                                                                            |
# |     CONFIGURE DEVICE TYPE DISK PARALLELISM 2;                              |
# |                                                                            |
# | NOTE: If you configure [n] manually numbered channels, the PARALLELISM     |
# | setting can be greater than or less than [n]. For example, you can         |
# | manually number 10 automatic channels and configure PARALLELISM to 2 or    |
# | even 12.                                                                   |
# +----------------------------------------------------------------------------+

CONFIGURE DEVICE TYPE DISK CLEAR;



# +----------------------------------------------------------------------------+
# | DATABASE BACKUP COPIES                                                     |
# | ARCHIVELOG BACKUP COPIES                                                   |
# |----------------------------------------------------------------------------|
# | Specifies the number of copies of each backup set for DATAFILE (both       |
# | datafiles and control files) or ARCHIVELOG files on the specified device   |
# | type, from 1 (default) to 4. If duplexing is specified in the BACKUP       |
# | command or in a SET BACKUP COPIES command, then the CONFIGURE setting is   |
# | overridden.                                                                |
# |                                                                            |
# | Here is the general syntax:                                                |
# |                                                                            |
# |     {ARCHIVELOG| DATAFILE}                                                 |
# |         BACKUP COPIES FOR DEVICE                                           |
# |         TYPE deviceSpecifier                                               |
# |         TO integer;                                                        |
# |                                                                            |
# | NOTE: Control file autobackups on disk are a special case and are never    |
# |       duplexed. RMAN always writes one and only copy.                      |
# +----------------------------------------------------------------------------+

CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK CLEAR;
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK CLEAR;



# +----------------------------------------------------------------------------+
# | CHANNEL CONFIGURATION                                                      |
# |----------------------------------------------------------------------------|
# | Specifies the standard or AUXILIARY channel that you are configuring or    |
# | clearing, as well as the device type (DISK or sbt) of the channel. You can |
# | either configure a "generic channel" or specify a channel by number, where |
# | "integer" is less than 255.                                                |
# |                                                                            |
# | Here is the general syntax:                                                |
# |                                                                            |
# |     CHANNEL integer DEVICE TYPE deviceSpecifier allocOperandList;          |
# |                                                                            |
# |         integer              You can specify a channel by number. You may  |
# |                              also exclude an integer, in which case you    |
# |                              are specifying a general channel.             |
# |         deviceSpecifier      {DISK | SBT}                                  |
# |         allocOperandList     /* Specifies control options for the  */      |
# |                              /* allocated channel                  */      |
# |                              [PARMS         = 'channel_parms']             |
# |                              [CONNECT       = (quoted string)]             |
# |                              [FORMAT        = 'format_sring']              |
# |                              [MAXPIECESIZE  = integer [K|M|G]]             |
# |                              [RATE          = integer [K|M|G]]             |
# |                              [MAXOPENFILES  = integer]                     |
# |                              [SEND          = 'command']                   |
# |                                                                            |
# | NOTE: The RATE parameter is intended to slow down a backup so that you can |
# |       run it in the background with as little effect as possible on OLTP   |
# |       operations. The RATE parameter specifies units of bytes/second. Test |
# |       to find a value that improves performance of your queries while      |
# |       still letting RMAN complete the backup in a reasonable amount of     |
# |       time. Note that RATE is not designed to increase backup throughput,  |
# |       but to decrease backup throughput so that more disk bandwidth is     |
# |       available for other database operations.                             |
# |                                                                            |
# | NOTE: The CONNECT parameter Specifies a connect string to the database     |
# |       instance where RMAN should conduct the backup or restore operations. |
# |       Use this parameter to spread the work of backup or restore           |
# |       operations across different instances in an Oracle Real Application  |
# |       Clusters configuration. If you do not specify this parameter, and if |
# |       you did not specify the AUXILIARY option, then RMAN conducts all     |
# |       operations on the target database instance specified by the          |
# |       command-line parameter or the instance connected to when you issued  |
# |       the CONNECT command. Typically, you should not use the CONNECT       |
# |       parameter in conjunction with the AUXILIARY option.                  |
# |                                                                            |
# | I generally use this parameter to configure the location (directory)       |
# | and file format where RMAN will write disk backups to. Here are some of    |
# | the substitution variables that can be used in the backup set file name:   |
# |                                                                            |
# |     %d      Database name                                                  |
# |     %s      Backup set number                                              |
# |     %p      Backup piece number                                            |
# |     %t      4-byte timestamp                                               |
# |                                                                            |
# | If you configure a generic channel (that is, if you do not specify a       |
# | channel number), then RMAN uses the generic settings for every             |
# | parallelized channel except any channel number that you have explicitly    |
# | configured. In other words, a generic channel setting specifies options    |
# | for all channels not configured explicitly.                                |
# |                                                                            |
# | NOTE: For generic channels of a specified device type, a new command       |
# |       erases previous settings for this device type. Assume that you run   |
# |       these commands:                                                      |
# |                                                                            |
# |       CONFIGURE CHANNEL DEVICE TYPE sbt MAXPIECESIZE 1G;                   |
# |       CONFIGURE CHANNEL DEVICE TYPE sbt RATE 1700K;                        |
# |                                                                            |
# |       The second command erases the MAXPIECESIZE setting of the first      |
# |       command.                                                             |
# |                                                                            |
# | If AUXILIARY is specified, then this configuration is used only for        |
# | channels allocated at the auxiliary instance. If no auxiliary device       |
# | configuration is specified, and if RMAN needs to automatically allocate    |
# | auxiliary channels, then RMAN uses the target database device              |
# | configuration. It is not necessary to specify configuration information    |
# | for auxiliary channels unless they require different parameters from the   |
# | target channels.                                                           |
# |                                                                            |
# | NOTE: It is useful to understand how the CLEAR command works for this      |
# |       parameter. CLEAR Clears the specified channel. For example,          |
# |       CONFIGURE CHANNEL 1 DEVICE TYPE DISK CLEAR returns only channel 1 to |
# |       its default, whereas CONFIGURE CHANNEL DEVICE TYPE DISK CLEAR        |
# |       returns the generic disk channel to its default. Note that you       |
# |       cannot specify any other channel options (for example, PARMS) when   |
# |       you specify CLEAR.                                                   |
# +----------------------------------------------------------------------------+

  CONFIGURE CHANNEL  DEVICE TYPE DISK  FORMAT '/orabackup/rman/ORA920/backup_db_%d_S_%s_P_%p_T_%t' MAXPIECESIZE 1024m;
# CONFIGURE CHANNEL  DEVICE TYPE DISK  FORMAT '/orabackup/rman/ORA920/backup_db_%d_S_%s_P_%p_T_%t' MAXPIECESIZE 1024m  RATE 5M;



# +----------------------------------------------------------------------------+
# | MAXSETSIZE                                                                 |
# |----------------------------------------------------------------------------|
# | Specifies the maximum size of each backup set created on a channel. By     |
# | default MAXSETSIZE is set to UNLIMITED, meaning that it is disabled.       |
# |                                                                            |
# | Here is the general syntax:                                                |
# |                                                                            |
# |     CONFIGURE MAXSETSIZE TO { integer [K|M|G] | UNLIMITED | CLEAR };       |
# |                                                                            |
# | TO integer       Specifies the maximum set size in bytes, kilobytes (K),   |
# |                  megabytes (M), or gigabtyes (G). The default setting is   |
# |                  in bytes and is rounded down to kilobtyes. For example,   |
# |                  if you set MAXSETSIZE to 5000, RMAN sets the maximum set  |
# |                  size at 4 kilobytes (that is, 4096 bytes), which is the   |
# |                  lower kilobyte boundary of 5000. The minimum value must   |
# |                  be greater than or equal to the database block size.      |
# | TO UNLIMITED     Specifies that there is no size limit for backup sets.    |
# | CLEAR            Resets the maximum set size to its default value          |
# |                  (UNLIMITED).                                              |
# +----------------------------------------------------------------------------+

CONFIGURE MAXSETSIZE CLEAR;



# +----------------------------------------------------------------------------+
# | SNAPSHOT CONTROLFILE                                                       |
# |----------------------------------------------------------------------------|
# | Configures the snapshot control file filename to 'filename'. If you run    |
# | CONFIGURE SNAPSHOT CONTROLFILE NAME CLEAR, then RMAN sets the snapshot     |
# | control file name to its default.                                          |
# |                                                                            |
# | The default value for the snapshot control file name is platform-specific  |
# | and dependent on the Oracle home. For example, the default on some UNIX    |
# | system is ?/dbs/snapcf_@.f. If you clear the control file name, and you    |
# | change the Oracle home, then the default location of the snapshot control  |
# | file changes as well.                                                      |
# |                                                                            |
# |     SNAPSHOT CONTROLFILE NAME TO 'filename';                               |
# +----------------------------------------------------------------------------+

CONFIGURE SNAPSHOT CONTROLFILE NAME CLEAR;



# +----------------------------------------------------------------------------+
# | EXCLUDE TABLESPACE                                                         |
# |----------------------------------------------------------------------------|
# | Excludes the specified tablespace from BACKUP DATABASE commands. Note that |
# | you cannot exclude the SYSTEM tablespace. By default, each tablespace is   |
# | not excluded, that is, the exclude functionality is disabled.              |
# |                                                                            |
# | The exclusion is stored as an attribute of the tablespace, not the         |
# | individual datafiles, so the exclusion applies to any files that are added |
# | to this tablespace in the future.                                          |
# |                                                                            |
# | If you run CONFIGURE ... CLEAR on a tablespace after excluding it, then it |
# | returns to the default configuration of "not excluded."                    |
# |                                                                            |
# | You can still back up the configured tablespace by explicitly specifying   |
# | it in a BACKUP command or by specifying the NOEXCLUDE option on a BACKUP   |
# | DATABASE command.                                                          |
# |                                                                            |
# | The general syntax is:                                                     |
# |                                                                            |
# |     EXCLUDE FOR TABLESPACE tablespace_name;                                |
# |                                                                            |
# +----------------------------------------------------------------------------+

# CONFIGURE EXCLUDE FOR TABLESPACE USERS_READ_TBS;
