Easy-to-use commands for backup, restore, and recovery.
Ability to track which files have been backed up and where to.
Manages the deletion of obsolete backups and archivelogs.
Parallelization: can use multiple processes for backup, restore, and recovery.
Incremental backups that only back up changes since the previous backup.
Ability to apply incremental backups to an image copy.
Recovery at the database, tablespace, data file, table, or block level.
Advanced compression and encryption features.
Integration with media managers for tape backups.
Backup validation and testing. Restore validation and testing.
Cross-platform data conversion.
Data Recovery Advisor, which assists with diagnosing failures and proposing solutions.
Ability to detect corrupt blocks in data files.
Advanced reporting capabilities from the RMAN command line.
The goal of this chapter is to present enough information about RMAN that you can make reasonable decisions about how to implement a solid backup strategy. The basic RMAN components are described first, after which you walk through many of the decision points involved in implementing RMAN.
Note
The RMAN-related chapters in this book are not intended to be a complete reference on all aspects of backup and restore. That would take an entire book. These chapters contain the basic information you need to successfully use RMAN. If you require advanced RMAN information regarding backup, restore, and recovery, see RMAN Recipes for Oracle Database 12c, second edition, by Darl Kuhn, Sam Alapati, and Arup Nanda (Apress, 2013).
Understanding RMAN
DBA : Human interaction to ensure successful backups and restores.
Target database : The database being backed up by RMAN. You connect to the target database with the RMAN command-line TARGET parameter (see the next section for more details).
RMAN client: The rman utility from which you issue BACKUP , RESTORE , and RECOVER commands. On most database servers, the rman utility is located in the ORACLE_HOME/bin directory (along with all the other Oracle utilities, such as sqlplus and expdp).
Oracle server processes : When you execute the rman client and connect to the target database, two Oracle server background processes are started. The first default server process interacts with the PL/SQL packages to coordinate the backup activities. The secondary polling process occasionally updates Oracle data dictionary structures.
Channel (s): The Oracle server processes for handling I/O between files being backed up (or restored) and the backup device (disk or tape).
PL/SQL packages : RMAN uses two internal PL/SQL packages (owned by SYS) to perform backup and restore tasks: DBMS_RCVMAN and DBMS_BACKUP_RESTORE. DBMS_RCVMAN accesses information in the control file and passes that to the RMAN server processes. The DBMS_BACKUP_RESTORE package performs most of RMAN’s work. For example, this package creates the system calls that direct the channel processes to perform B&R operations.
Memory buffers (PGA or SGA): RMAN uses a memory area in the PGA (and sometimes in the SGA) as a buffer when reading from data files and copying subsequent blocks to back up files.
Auxiliary database : A database to which RMAN restores target database data files for the purpose of duplicating a database, creating a Data Guard standby database, or performing a database point in time recovery (DBPITR).
Backup/Back up : Can be either a noun or a verb. The physical files (backup) that store the backed-up files; or, the act of copying and archiving (backing up) files. Backups can consist of backup sets and backup pieces or image copies.
Backup set : When you run an RMAN BACKUP command, by default, it creates one or more backup sets. A backup set is a logical RMAN construct that groups backup piece files. You can think of the relationship of a backup set to a backup piece as similar to the relationship between a tablespace and a data file: one is a logical construct, the other is a physical file.
Backup piece file : RMAN binary backup files. Each logical backup set consists of one or more backup piece files. These are the physical files that RMAN creates on disk or tape. They are binary, proprietary format files that only RMAN can read or write to. A backup piece can contain blocks from many different data files. Backup piece files are typically smaller than data files, because backup pieces only contain blocks that have been used in the data files.
Image copy : Initiated with the BACKUP AS COPY command. A type of backup in which RMAN creates identical copies of a data file, archivelog file, or control file. Image copies can be operated on by OS utilities such as the Linux cp and mv commands. Image copies are used as part of incrementally updated image backups. Sometimes, it is preferable to use image copies rather than backup sets if you need to be able to restore quickly.
Recovery catalog : An optional database schema that contains tables used to store metadata information regarding RMAN backup operations. Oracle strongly recommends using a recovery catalog, because it provides more options for backup and restore. The catalog is normally remote and does not have to be in each of the databases.
Media manager : Third-party software that allows RMAN to back up files directly to tape. Backing up to tape is desirable when you do not have enough room to back up directly to disk or when disaster recovery requirements necessitate a backup to storage that can be easily moved offsite.
Fast Recovery Area (FRA): A disk area that RMAN can use for backups. You can also use the FRA to multiplex control files and online redo logs. You instantiate a fast recovery with the database initialization parameters DB_RECOVERY_FILE_DEST_SIZE and DB_RECOVERY_FILE_DEST.
Snapshot control file : RMAN requires a read-consistent view of the control file when either backing up the control file or synchronizing with the recovery catalog (if it is being used). In these situations, RMAN first creates a temporary copy (snapshot) of the control file. This allows RMAN to use a version of the control file that is guaranteed not to change while backing up the control file or synchronizing with the recovery catalog being used). In these situations, RMAN first creates a temporary copy (snapshot) of the control file. This allows RMAN to use a version of the control file that is guaranteed not to change while backing up the control file or synchronizing with the recovery catalog.
Full backup : All modified blocks associated with the data file are backed up. A full backup is not a backup of the entire database. For example, you can make a full backup of one data file.
Incremental level 0 backup : Backs up the same blocks as a full backup. The only difference between a level 0 backup and a full backup is that you can use a level 0 backup with other incremental backups, but not a full backup.
Incremental level 1 backup : Backs up only blocks that have been modified since the previous backup. Level 1 incremental backups can be either differential or cumulative. A differential level 1 backup is the default and backs up all blocks that have been modified since the last level 0 or level 1 backup. A cumulative level 1 backup backs up all blocks that have changed since the last level 0 backup.
Incrementally updated backup : First creates an image copy of the data files, after which subsequent backups are incremental backups that are merged with the image copy. This is an efficient way to use image copies for backups. Media recoveries using incrementally updated backups are fast because the image copy of the data file is used during the restore.
Block change tracking : Database feature that keeps track of blocks that have changed in the database. A record of the changed blocks is kept in a binary file. RMAN can use the contents of the binary file to improve the performance of incremental backups: instead of having to scan all modified blocks in a data file, RMAN can determine which blocks have changed from the binary block change tracking.
Archivelog backups : This performs the backup of the archivelogs and allows for freeing up space in the archivelog directory. Archivelog backups are normally included as part of the data files but can also be run separately to manage the disk space for the archivelogs.
Now that you understand the RMAN architectural components and the types of backups you can make, you are ready to start up RMAN and configure it for your environment.
Starting RMAN
OS environment variables
Access to a privileged OS account or a database user with SYSBACKUP privileges
The easiest way to connect to RMAN is to log in to the server on which the target database resides as the owner of the Oracle software (usually named oracle, on Linux/Unix boxes). When you log in as oracle, you need to establish several OS variables before you can use utilities such as rman and sqlplus . Setting these required OS variables is covered in detail in Chapter 2. RMAN can be run from another server with the Oracle software installed. The service or SID name is what is needed to connect to the target database in order to perform the backup.
At minimum, you need to set ORACLE_HOME and ORACLE_SID. Additionally, it is convenient if the PATH variable includes the directory ORACLE_HOME/bin. This is the directory that contains the Oracle utilities.
When connecting to RMAN, you do not have to specify the AS SYSDBA clause (as you do when connecting to a database as a privileged user in SQL*Plus). This is because RMAN always requires that you connect as a database user with SYSDBA privileges. Any user will need to have the SYSBACKUP role granted to it in order to perform the backups.
Tip
New in Oracle Database 12c, the SYSBACKUP privilege allows you to assign privileges to a user that include only the permissions needed to perform backup and restore operations. The SYSBACKUP privilege contains the subset of SYSDBA privileges required for carrying out such operations.
The previous example of logging in to RMAN uses OS authentication. This type of authentication means that if you can log in to an authorized OS account (such as the owner of the Oracle software, usually oracle), then you are allowed to connect to the database without having to provide a username and password. You administer OS authentication by assigning special groups to OS accounts. When you install the Oracle binaries in a Linux/Unix environment, you are required to specify at the time of installation the names of the OS groups that are assigned the database privileges of SYSDBA, SYSOPER, SYSBACKUP—typically, the dba, oper, and backupdba groups, respectively (see Chapter 1 for details). As part of an enterprise backup solution, it would be recommended to create a separate user for backups in order to perform the backups to disk or tape and schedule to run automatically.
(NOT) Calling RMAN from SQL*PLUS
It is very typical to be in a SQLPLUS session and accidentally attempt an RMAN command or just try running RMAN from SQLPLUS. Well, it does not work:
SQL> rman
SP2-0042: unknown command "rman" - rest of line ignored.
The answer is short: the rman client is an OS utility, not an SQL*Plus function. You must invoke the rman client from the OS prompt.
RMAN Architectural Decisions
You are good to go, right? No, not quite. RMAN’s default attributes are reasonably set for simple backup requirements. The RMAN out-of-the-box settings may be appropriate for small development or test databases. But, for any type of business-critical database, you need to consider carefully where the backups are stored, how long to store backups on disk or tape, which RMAN features are appropriate for the database, and so on. The following sections in this chapter walk you through many of the backup and recovery architectural decisions necessary for implementing RMAN in a production environment. RMAN has a vast and robust variety of options for customizing backups, managing backup files, and performing restores; and, typically, you do not need to implement many of RMAN’s features. However, each time you implement RMAN to back up a production database, you should think through each decision point and decide whether you require an attribute.
Overview of Architectural Decisions and Recommendations
Decision Point | Recommendation |
---|---|
1. Running the RMAN client remotely or locally | Run the client locally on the target database server. |
2. Specifying the backup user | Create a user for performing backups. |
3. Using online or offline backups | Depends on your business requirements. Most production databases require online backups, which means that you must enable archiving. |
4. Setting the archivelog destination and file format | If you are using an FRA, archive logs are written there with a default format. To use the LOG_ARCHIVE_DEST_N initialization parameter to specifically set the location outside the FRA. |
5. Configuring the RMAN backup location and file format | Depends on your business requirements. Some shops require tape backups. If you are using disk, place the backups in the FRA, or specify a location via channel settings. Using FRA will allow for increasing the storage sizing dynamically. Backups to tape can be run after creating the backup set and is normally more efficient. |
6. Setting the autobackup of the control file | Always enable autobackup of the control file. |
7. Specifying the location of the autobackup of the control file | Either place it in the FRA, or configure a location. It makes sense to write the autobackup of the control file to the same location as that of the database backups. |
8. Backing up archivelogs | Depends on your business requirements. For many environments, backing up the archivelogs can be done just on a daily basis, with the same command use to back up the database or triggered when space requires it. |
9. Determining the location for the snapshot control file | Use the default location. |
10. Using a recovery catalog | Depends on your business requirements. Oracle recommends that you do use a recovery catalog. If the RMAN retention policy is greater than CONTROL_FILE_RECORD_KEEP_TIME, then I recommend that you use a recovery catalog. |
11. Using a media manager | This is required for backing up directly to tape. |
12. Setting the CONTROL_FILE_RECORD_KEEP_TIME initialization parameter | Usually, the default of 7 days is sufficient. |
13. Configuring RMAN’s backup retention policy | Depends on your database and business requirements. For many environments, I use a backup retention redundancy of 1 or 2. |
14. Configuring the archivelogs’ deletion policy | Depends on your database and business requirements. In many scenarios, applying the backup retention policy to the archivelogs is sufficient (this is the default behavior). |
15. Setting the degree of parallelism | Depends on the available hardware resources and business requirements. For most production servers, on which there are multiple CPUs, configure a degree of parallelism of 2 or more based on CPUs available. |
16. Using backup sets or image copies | Backup sets are generally smaller than image copies and easier to manage. |
17. Using incremental backups | Use incremental backups for large databases when a small percentage of the database changes between backups and when you want to conserve on disk space. Use incremental backups in a large database and data warehouse-type databases. |
18. Using incrementally updated backups | Use this approach if you require image copies of data files. |
19. Using block change tracking | Use this to improve the performance of incremental backups. For large, data warehouse-type databases, block change tracking can result in significant time savings for backups because it keeps track of the blocks changed so the backup does not have to read the headers to determine if the block has changed. |
20. Configuring binary compression | Depends on your business requirements. Compressed backups consume less space but require more CPU resources (and time) for backup and restore operations. |
21. Configuring encryption | Depends on your business requirements. |
22. Configuring miscellaneous settings | You can set many channel-related properties, such as the backup set size and backup piece size. Configure as needed. |
23. Configuring informational output | Configure the OS variable NLS_DATE_FORMAT to display date and time. Use SET ECHO ON and SHOW ALL to display RMAN commands and settings. |
1. Running the RMAN Client Remotely or Locally
This allows you to run RMAN backups on disparate remote servers from one central location. When you run RMAN remotely, the backup files are always created on the target database server.
If you run RMAN remotely, you need to be sure the remote rman executable is compatible with the target database. For example, you may establish that the remote rman executable you are running is an Oracle Database 12c version of the RMAN client, and it is compatible with several earlier versions of Oracle database. If you run the rman client locally on the target server, there is never a compatibility issue because the rman client is always the same version as the target database.
2. Specifying the Backup User
3. Using Online or Offline Backups
Most production databases have 24-7 availability requirements. Therefore, your only option is online RMAN backups. Your database must be in archivelog mode for online backups. You need to consider carefully how to place archivelogs, how to format them, how often to back them up, and how long to retain them before deletion. These topics are discussed in subsequent sections.
Note
If you make offline backups, you must shut down your database with IMMEDIATE, NORMAL, or TRANSACTIONAL and then place it in mount mode. RMAN needs the database in mount mode so that it can read from and write to the control file.
4. Setting the Archivelog Destination and File Format
Enabling archive redo log mode is a prerequisite for making online backups (see Chapter 5 for a full discussion of architectural decisions regarding the archivelog destination and format and how to enable/disable archivelog mode).
Default location
FRA (Fast Recovery Area)
Location specified via the LOG_ARCHIVE_DEST_N initialization parameter(s)
If you do not use an FRA, and if you do not explicitly set the archivelog destination via a LOG_ARCHIVE_DEST_N initialization parameter, then by default the archivelogs are written to an OS-dependent location. On many Linux/Unix boxes the default location is the ORACLE_HOME/dbs directory. The default file name format for archivelogs is %t_%s_%r.dbf. The format is a shorthand to reference date, backup set number, etc. The %t is timestamp, %s is log sequence number and %r is reset logs ID.
Sometimes, DBAs use .dbf as an extension for both data files and archivelog files. I prefer to use .arc for the archivelog files. The .arc extension avoids the potentially confusing task of identifying a file as an archivelog file or a live database data file.
5. Configuring the RMAN Backup Location and File Format
Default location
FRA
Location specified via the BACKUP...FORMAT command
Location specified via the CONFIGURE CHANNEL...FORMAT command
Default Location
Tip
The default location is okay for small development databases. However, for most other environments (especially production), you will need to plan ahead for how much disk space you will need for backups and explicitly set the location for the backups via one of the other methods (such as implementing an FRA or CONFIGURE CHANNEL).
FRA
Dynamically being able to set the size or location of the FRA is available with SYSTEM parameters. This is useful if the backsets are still being purged or archivelogs are filling up the space; instead of hoping a backup or move of files completes, the FRA size can be adjusted, and then you can shrink it back down to the original size.
BACKUP...FORMAT
RMAN allocates multiple channels and writes in parallel to two different backup files. The U% in the format string guarantees that unique file names are created.
CONFIGURE CHANNEL...FORMAT
In these lines of code, you should configure the device-type parallelism degree to match the number of channels that you allocated. RMAN only allocates the number of channels as specified by the degree of parallelism; other configured channels are ignored. For instance, if you specify a degree of parallelism of 2, RMAN allocates only two channels, regardless of the number of channels you configured via the CONFIGURE CHANNEL command .
RMAN allocates three channels, all on separate mount points (/u01, /u02, /u03), and writes in parallel to the specified locations. RMAN creates as many backup pieces in the three locations as it deems necessary to create a backup of the database.
Note
Also consider what happens if you configure a degree of parallelism higher than the number of preconfigured channels. RMAN will open a channel for each degree of parallelism, and if the number of channels opened is greater than the number of preconfigured channels, for the unconfigured channels, RMAN will write backup files to the FRA (if configured) or the default location.
6. Setting the Autobackup of the Control File
The automatic control file backup always goes into its own backup set. When autobackup of the control file is enabled, if you are using an spfile, it is automatically backed up along with the control file.
Note
If autobackup of the control file is off, then any time you back up data file 1 (SYSTEM tablespace data file), RMAN automatically backs up the control file.
7. Specifying the Location of the Autobackup of the Control File
Default location
FRA
Location specified via the CONFIGURE CONTROLFILE AUTOBACKUP FORMAT command
8. Backing Up Archivelogs
You should back up your archivelogs on a regular basis. The archivelog files should not be removed from disk until you have backed them up at least once. I usually like to keep on disk any archivelogs that have been generated since the last good RMAN backup.
Sometimes, if your database generates a great deal of redo, you may need to back up your archivelogs at a frequency different from that of the data files. DBAs may back up the archivelogs two or three times a day; after the logs are backed up, the DBAs delete them to make room for more current archivelog files.
In most situations, you do not need any archivelogs that were generated before your last good backup. For example, if a data file has experienced media failure, you need to restore the data file from a backup and then apply any archivelogs that were generated during and after the backup of the data file.
On some occasions, you may need archivelogs that were generated before the last backup. For instance, you may experience a media failure, attempt to restore your database from the last good backup, find corruption in that backup, and therefore need to restore from an older backup. At that point, you need a copy of all archivelogs that have been generated since that older backup was made.
9. Determining the Location for the Snapshot Control File
Synchronizing with the recovery catalog
Backing up the current control file
RMAN creates a snapshot copy of the current control file that it uses as a read-consistent copy while it is performing these tasks. This ensures that RMAN is working from a copy of the control file that is not being modified.
The default location of the snapshot control file is OS specific. On Linux platforms, the default location/format is ORACLE_HOME/dbs/[email protected]. Note that the default location is not in the FRA.
For most situations, the default location and format of the snapshot control file are sufficient. This file does not use much space or have any intensive I/O requirements. I recommend that you use the default setting.
10. Using a Recovery Catalog
RMAN always stores its latest backup operations in the target database control file. You can set up an optional recovery catalog to store metadata regarding RMAN backups. The recovery catalog is a separate schema (usually in a database different from that of the target database) that contains database objects (tables, indexes, and so on) that store the RMAN backup information. The recovery catalog does not store RMAN backup pieces—only backup metadata.
Provides a secondary repository for RMAN metadata. If you lose all your control files and backups of your control files, you can still retrieve RMAN metadata from the recovery catalog.
Stores RMAN metadata for a much longer period than is possible when you just use a control file for the repository.
Offers access to all RMAN features. Some restore and recovery features are simpler when using a recovery catalog.
The disadvantage of using a recovery catalog is that this is another database you have to set up, maintain, and back up. Additionally, when you start a backup and attempt to connect to the recovery catalog, if the recovery catalog is not available for any reason (server down, network issues, and so on), you can continue with the backup without a recovery catalog.
You must also be aware of versioning aspects when using a recovery catalog. You need to make sure the version of the database you use to store the recovery catalog is compatible with the version of the target database. When you upgrade a target database, be sure the recovery catalog is upgraded (if necessary).
Note
See Chapter 18 for details on how to implement a recovery catalog.
11. Using a Media Manager
A media manager is required for RMAN to back up directly to tape. Several vendors provide this feature (for a cost). Media managers are used in large database environments, such as data warehouses, in which you may not have enough room to back up a database to disk. You may also have a disaster recovery requirement to back up directly to tape.
If you have such requirements, then you should purchase a media management package and implement it. If you do not need to back up directly to tape, there’s no need to implement a media manager. RMAN works fine backing up directly to disk. The backup files can be copied off to tape for offsite storage and because of retention policies. If copying to tape, you can have a job run the RMAN backup and then initiate the copy to tape. The backup files need to be complete and not in the middle of a backup; otherwise there is the risk of only getting partial files copied to tape.
Tip
See Chapter 20 for details on how to implement Oracle Secure Backup as a media management layer.
12. Setting the CONTROL_FILE_RECORD_KEEP_TIME Initialization Parameter
The CONTROL_FILE_RECORD_KEEP_TIME initialization parameter specifies the minimum number of days a reusable record in the control file is retained before the record can be overwritten. The RMAN metadata are stored in the reusable section of the control file and therefore are eventually overwritten.
If you are using a recovery catalog, then you do not need to worry about this parameter because RMAN metadata are stored in the recovery catalog indefinitely. Therefore, when you use a recovery catalog, you can access any historical RMAN metadata.
You can set the value to anything from 0 to 365 days. Setting the value to 0 means that the RMAN metadata information can be overwritten at any time.
The CONTROL_FILE_RECORD_KEEP_TIME parameter was more critical in older versions of Oracle, in which it was not easy to repopulate the control file with RMAN information, in the event that metadata were overwritten. The C command can be used to quickly make the control file aware of RMAN backup files.
If you run daily backups, then I recommend that you leave this parameter at 7 days. However, if you only back up your database once a month, or if, for some reason, you have a retention policy greater than 7 days, and you are not using a recovery catalog, then you may want to consider increasing the value. The downside to increasing this parameter is that if you have a significant amount of RMAN backup activity, this can increase the size of your control file.
13. Configuring RMAN’s Backup Retention Policy
Recovery window
Number of backups (redundancy)
Recovery Window
For the specified recovery, RMAN may need backups older than the 5-day window because it may need an older backup to start with to be able to recover to the recovery point specified. For example, suppose your last good backup was made 6 days ago, and now you want to recover to 4 days in the past. For this recovery window, RMAN needs the backup from 6 days ago to restore and recover to the point specified.
Redundancy
I find that a retention policy based on redundancy is easier to work with and more predictable with regard to how long backups are retained. If I set redundancy to 2, I know that RMAN will not mark as obsolete the latest two backups. In contrast, the recovery window retention policy depends on the frequency of the backups and the window length to determine whether a backup is obsolete.
Deleting Backups, Based on Retention Policy
I usually have the DELETE NOPROMPT OBSOLETE command coded into the shell script that backs up the database. This instructs RMAN to delete any obsolete backups and obsolete archivelogs, as specified by the retention policy (see the section “Segueing from Decisions to Action,” later in this chapter, for an example of how to automate the deleting of obsolete backups with a shell script).
Clearing the Retention Policy
When the policy is set to NONE, no backups are ever considered obsolete and therefore cannot be removed via the DELETE OBSOLETE command. This normally is not the behavior you want. You want to let RMAN delete backups per a retention policy based on a window or number of backups.
14. Configuring the Archivelogs’ Deletion Policy
As of Oracle Database 11g, you can specify an archivelog deletion policy that is separate from that of the database backups. This deletion policy applies to archivelogs both outside and in the FRA.
Note
Prior to Oracle Database 11g, the archive deletion policy only applied to archivelogs associated with a standby database.
Tip
Run the CROSSCHECK command before running the DELETE command . Doing so ensures that RMAN is aware of whether a file is on disk.
15. Setting the Degree of Parallelism
You can significantly increase the performance of RMAN backup and restore operations if your database server is equipped with the hardware to support multiple channels. If your server has multiple CPUs and multiple storage devices (disks or tape devices), then you can improve performance by enabling multiple backup channels.
If you require better performance from backup and restore operations and have hardware that facilitates parallel operations, you should enable parallelism and perform tests to determine the optimal degree. If your hardware can take advantage of parallel RMAN channels, there is little downside to enabling parallelism.
This code configures four channels that write to separate locations on disk. When you configure separate channels for different locations, make sure you enable the degree of parallelism to match the number of configured device channels. If you allocate more channels than the specified degree of parallelism, RMAN only writes to the number of channels specified by the degree of parallelism and ignores the other channels.
16. Using Backup Sets or Image Copies
Backup set
Image copy
A backup set is the default type of RMAN backup. A backup set contains backup pieces, which are binary files that only RMAN can write to or read from. Backup sets are desirable because they are generally smaller than the data files being backed up. RMAN automatically attempts to create backup pieces with unused block compression. In this mode, RMAN reads a bitmap to determine which blocks are allocated and only reads from those blocks in the data files. This feature is supported only for disk-based backup sets and Oracle Secure Backup tape backups.
Note
RMAN can also create backup sets using true binary compression. This is the type of compression you get from an OS compression utility (such as zip). Oracle supports several levels of binary compression. The BASIC compression algorithm is available without an additional license. Oracle provides further compression features with the Oracle Advanced Compression option (see the section “Configuring Binary Compression,” later in this chapter, for details on how to enable binary compression).
When you create a backup as a backup set, the binary backup piece files can only be manipulated by RMAN processes. Some DBAs view this as a disadvantage because they must use RMAN to back up and restore these files (you have no direct access to or control over the backup pieces). But these perceptions are not warranted. Unless you hit a rare bug, RMAN is dependable and works reliably in all backup and restore situations.
Contrast the backup set with an image copy. An image copy creates a byte-for-byte identical copy of each data file. The advantage of creating an image copy is that (if necessary) you can manipulate the image copy without using RMAN (as with an OS copy utility). Additionally, in the event of a media failure, an image copy is a fast method of restoring data files, because RMAN only has to copy the file back from the backup location (there is no reconstructing of the data file, because it is an exact copy).
The size of the backup to disk is almost always a concern. Backup sets are more efficient regarding disk space consumption. Because backup sets can take advantage of RMAN compression, there is also less I/O involved, compared with an image copy. In many environments, reducing the I/O so as not to impact other applications is a concern.
However, if you feel that you need direct control over the backup files that RMAN creates, or you are in an environment in which the speed of the restore process is paramount, consider using image copies.
17. Using Incremental Backups
Incremental backup strategies are appropriate for large databases in which only a small portion of the database blocks change from one backup to the next. If you are in a data warehouse environment, you may want to consider an incremental backup strategy, because it can greatly reduce the size of your backups. For example, you may want to run a weekly level 0 backup and then run a daily level 1 incremental backup.
The only difference between the prior two commands is that an incremental level 0 backup can be used in conjunction with other incremental backups, whereas a full backup cannot participate in an incremental backup strategy. Therefore, I almost always prefer to use the INCREMENTAL LEVEL=0 syntax (as opposed to a full backup); it gives me the flexibility to use the level 0 incremental backup along with subsequent incremental level 1 backups.
18. Using Incrementally Updated Backups
Incrementally updated backups are an efficient way to implement an image copy backup strategy. This technique instructs RMAN to first create image copies of data files; then, the next time the backup runs, instead of creating a fresh set of image copies, RMAN makes an incremental backup (changes to blocks since the image copy was created) and applies that incremental backup to the image copies.
If you have the disk space available for full image copies of your database and you want the flexibility to use the image copies directly, in the event of a media failure, consider this backup strategy.
One potential disadvantage of this approach is that if you are required to restore and recover to some point in the past, you can only restore and recover to the point at which the image copies were last updated with the incremental backup.
19. Using Block Change Tracking
This feature keeps track of when a database block changes. The idea is that if you are using an incremental backup strategy, you can enhance performance, because by implementing this feature, RMAN does not have to scan each block (under the high-water mark) in the data files to determine whether it needs to be backed up. Rather, RMAN only has to access the block change tracking file to find which blocks have changed since the last backup and directly access those blocks. If you work in a large, data warehouse environment and are using an incremental backup strategy, consider enabling block change tracking to enhance performance.
Note
See Chapter 18 for more details on implementing incremental and block change backup and restores.
20. Configuring Binary Compression
Specify AS COMPRESSED BACKUPSET with the BACKUP command .
Use a one-time CONFIGURE command .
The default compression algorithm proves to be quite efficient. For a typical database, the backups are usually approximately four to five times smaller than the regular backups. Of course, your compression results may vary, depending on your data.
Why not compress all backups? Compressed backups consume more CPU resources and take longer to create and restore from, but they result in less I/O, spread out over a longer period. If you have multiple CPUs, and the speed of making a backup isn’t an issue, then you should consider compressing your backups.
In my experience the prior compression algorithms are very efficient, both in compression ratios and time taken to create backups.
21. Configuring Encryption
You may be required to encrypt backups. Some shops especially require this for backups that contain sensitive data and that are stored offsite. To use encryption when backing up, you must use the Oracle Enterprise Edition and possess a license for the Advanced Security option.
Encrypted tablespaces will remain encrypted in the backup sets. The configuration for backup encryption does not need to be on for this, but only the tablespaces that are encrypted will remain encrypted.
You can query V$RMAN_ENCRYPTION_ALGORITHMS to view details regarding the encryption algorithms available for your release of the database.
Running SQL from Within RMAN
This ability to run SQL from within RMAN is a really nice enhancement; it allows you to see the results of SQL queries and eliminates the need for specifying the sql keyword as well as for placing quotation marks around the SQL command itself.
22. Configuring Miscellaneous Settings
Maximum backup set size
Maximum backup piece size
Maximum rate
Maximum open files
You may need to configure any of these settings when you need to make RMAN aware of some OS or hardware limitation. You will rarely need to use these parameters but should know of them.
23. Configuring Informational Output
This is useful during troubleshooting, especially when RMAN fails, because we can use the exact date/time information for when the RMAN error occurred and compare it with the alert.log and OS/MML logs to verify what other events occurred in the database/server.
Also consider executing SET ECHO ON to ensure that RMAN commands are displayed within the log before the command is executed. Execute SHOW ALL as well to display the current settings of RMAN variables. These settings are useful when troubleshooting and tuning.
Clearing All RMAN Configurations
Depending on what you have set (and the version of your database), you may need to set additional configurations.
Segueing from Decision to Action
Now that you have a good understanding of what types of decisions you should make before implementing RMAN, it is instructional to view a script that implements some of these components. Scripts can be used to automate the RMAN backups. These shell scripts are automated through a scheduling utility such as cron . RMAN can also be run from Oracle Enterprise Manager. Additionally, if there are tools that are used to copy files to tape or other schedulers, RMAN scripts can be included in these jobs; however, there is less flexibility if the RMAN script does not remain on the database side.
This section contains a typical shell script for RMAN backups. The shell script has line numbers in the output for reference in the discussion of the architectural decisions there were made when writing the script. (If you copy the script, take out the line numbers before running it.)
Implementation of Architectural Decisions
Decision Point | Implementation in Script | Line Number in Script |
---|---|---|
1. Running the RMAN client remotely or locally | Running script locally on the database server | Line 26, connecting locally (not a network connection) |
2. Specifying the backup user | Using SYS to connect | Line 27, starting rman connecting with forward slash (/) |
3. Using online or offline backups | Online backup | N/A. Database is assumed to be up during the backup |
4. Setting the archivelog destination and file format | LOG_ARCHIVE_DEST_N and LOG_ARCHIVE_FORMAT initialization parameters set outside the script in a database parameter file | N/A; set outside the script |
5. Configuring the RMAN backup location and file format | Using the CONFIGURE command directly in the script | Lines 33–37 |
6. Setting the autobackup of the control file | Enabled in the script | Line 32 |
7. Specifying the location of the autobackup of the control file | Placed in the same directory as the backups | Line 33 |
8. Backing up archivelogs | Backing up with the rest of the database; specifically, using the PLUS ARCHIVELOG clause | Line 38 |
9. Determining the location for the snapshot control file | Using the default location | N/A |
10. Using a recovery catalog | Not using | Line 26, connecting as nocatalog |
11. Using a media manager | Not using | Lines 35–37, device type disk |
12. Setting the CONTROL_FILE_RECORD_KEEP_TIME initialization parameter | Using the default | N/A |
13. Configuring RMAN’s backup retention policy | Configuring to a redundancy of 1, cross-checking, and deleting obsolete backups and archivelog files | Line 34, configuring; lines 30 and 31 crosscheck; line 39, using RMAN to delete old files |
14. Configuring the archivelogs’ deletion policy | Using the same retention policy applied to the backups | N/A |
15. Setting the degree of parallelism | Setting a degree of 2 | Lines 35–37 |
16. Using backup sets or image copies | Using backup sets | Line 38 |
17. Using incremental backups | Incremental level 0, the same as a full backup | Line 38 |
18. Using incrementally updated backups | Not using | N/A |
19. Using block change tracking | Not using | N/A |
20. Configuring binary compression | Using basic compression | Line 38 |
21. Configuring encryption | Not using | N/A |
22. Configuring miscellaneous settings | Not using | N/A |
23. Configuring informational output | Setting | Lines 15, 28, and 29 |
A few aspects of this script need further discussion. Line 11 sets the required OS variables by running a script named oraset (see Chapter 2 for details on running oraset and sourcing OS variables). Many DBAs choose to hard-code OS variables, such as ORACLE_HOME and ORACLE_SID, into the script. However, you should avoid hard-coding variables and instead use a script to source the required variables. Running a script is much more flexible, especially when you have many databases on a box with different versions of Oracle installed.
Line 15 sets the NLS_DATE_FORMAT OS variableyou are debugging and diagnoses issues. By default, RMAN displays only the date component. Knowing just the date when a command ran is rarely enough information to determine the timing of the commands as they were executed. At minimum, you need to see hours and minutes (along with the date).
Lines 18–24 check for the existence of a lock file. You do not want to run this script if it is already running. The script checks for the lock file, and, if it exists, the script exits. After the backup has finished, the lock file is removed (lines 49–51).
Line 28 sets the ECHO parameter to on. This instructs RMAN to display in the output the command before running it. This can be invaluable for debugging issues. Line 29 displays all the configurable variables. This also comes in handy for troubleshooting issues because you can see what the RMAN variables were set to before any commands are executed.
Lines 32–37 use the CONFIGURE command. These commands run each time the script is executed. Why do that? You only need to run a CONFIGURE command once, and it is stored in the control file—you do not have to run it again, right? That is correct. However, I’ve occasionally been burned when a DBA with poor habits configured a setting for a database and didn’t tell anybody, and I didn’t discover the misconfiguration until I attempted to make another backup. I strongly prefer to place the CONFIGURE commands in the script so that the behavior is the same, regardless of what another DBA may have done outside the script. The CONFIGURE settings in the script also act as a form of documentation: I can readily look at the script and determine how settings have been configured.
Lines 30 and 31 run CROSSCHECK commands . Why do that? Sometimes, files go missing, or a rogue DBA may remove archivelog files from disk with an OS command outside RMAN. When RMAN runs, if it can’t find files that it thinks should be in place, it throws an error and stops the backup. I prefer to run the CROSSCHECK command and let RMAN reconcile which files it thinks should be on disk with those that are actually on disk. This keeps RMAN running smoothly.
You run DELETE NOPROMPT OBSOLETE on line 39. This removes all backup files and archivelog files that have been marked as OBSOLETE by RMAN, as defined by the retention policy. This lets RMAN manage which files should be kept on disk. I prefer to run the DELETE command after the backup has finished (as opposed to running it before the backup). The retention policy is defined as 1, so if you run DELETE after the backup, RMAN leaves one backup copy on disk. If you run DELETE before the backup, RMAN leaves one copy of the backup on disk. After the backup runs, there are be two copies of the backup on disk, which I do not have room for on this server.
The script runs daily at 1600 hours military time on the database server. A log file is created (INVPRDRMAN.log) to capture any output and errors associated with the RMAN job. See Chapter 21 for details on automating jobs through cron .
Again, the script in this section is basic; you will no doubt want to enhance and modify it to meet your requirements. This script gives you a starting point, with concrete RMAN recommendations and how to implement them.
Summary
RMAN is not only the backup tool for Oracle database but the restore and recovery manager. If you are still using the older, user-managed backup technologies, then I strongly recommend that you switch to RMAN. RMAN contains a powerful set of features that are unmatched by any other backup tool available. RMAN is easy to use and configure. It will save you time and effort and give you peace of mind when you are implementing a rock-solid restore and backup strategy.
If you are new to RMAN, it may not be obvious which features should always be enabled and implemented and, likewise, which aspects you will rarely need. This chapter contains a checklist that walks you through each architectural decision point. Many of the strategies need to be discussed to make sure that the business requirements are going to be met. The point is that you should carefully consider each component and how to implement the features that make sense.
The chapter ended with a real-world example of a script used to implement RMAN in a production environment. Now that you have a good idea of RMAN’s features and how to use them, you are ready to start making backups. The next chapter deals with RMAN backup scenarios.