Using the Oracle Suggested Backup Strategy

The Oracle suggested backup strategy is a scheduled disk backup strategy that protects your data and provides efficient recoverability to any point in the user-specified recovery window (time period). It leverages the incrementally updated backup features to provide faster backups than whole database backups, and faster recoverability than is possible by applying multiple incremental backups to the last full backup.

Complete the following tasks, detailed in this section, to schedule a daily backup that implements the Oracle suggested backup strategy:

About the Oracle Suggested Backup Strategy

The Oracle suggested backup strategy is based on incrementally updated backups. This strategy starts with an image copy of each data file and then rolls forward the image copies each day by applying an incremental level 1 backup.

For each data file, the strategy calls for backups as follows:

  • At the beginning of day 1 of the strategy (the time the first scheduled job actually runs), Oracle Recovery Manager (RMAN) creates an incremental level 0 image copy. It contains the data file contents at the beginning of day 1.

    If a recovery is required, then the archived redo log files from day 1 can be used to recover to any point during day 1.

  • At the beginning of day 2, RMAN creates a differential incremental level 1 backup that contains the blocks changed during day 1.

    If a recovery is required, then RMAN can apply this incremental level 1 to roll forward the level 0 backup to the beginning of day 2. RMAN can use archived redo log files to recover to any point during day 2.

  • At the beginning of each day n for day 3 and onward, RMAN applies the level 1 backup from the beginning of day n-1 to the level 0 backup. This action brings the data file copy to its state at the beginning of day n-1. Then, RMAN creates a new level 1 backup that contains the blocks changed during day n-1.

    If a recovery is required, then RMAN can apply this incremental level 1 backup to the data file rolled forward on day n-1 to the beginning of day n. RMAN can use archived redo log files to recover the database to any point during day n.

In this Oracle suggested backup strategy, the data file image copies and the level 1 incremental backups share the same tag. You can safely implement other backup strategies without interfering with the Oracle suggested backup strategy.

Oracle suggested backup strategies also use tape backups in addition to disk backups, but these are beyond the scope of this section.

Task 1 - Preparing to Use the Oracle Suggested Backup Strategy

To use the Oracle suggested backup strategy, ensure that:

  • The database is in ARCHIVELOG mode.

  • The fast recovery area size is configured, or a default device for storing backups is configured.

  • You have added a database host user to the OSBACKUPDBA operating system group, for operating system authentication.

Task 2 - Creating the Backup Script—UNIX and Linux

This backup script implements the Oracle suggested backup strategy, enabling quick recovery to any time in the preceding 24 hours. This script can be used to back up a non-CDB or a whole multitenant container database (CDB).

To create the backup script for UNIX and Linux:

  • Start a text editor and create and save a file with the following contents. Save the file in a directory that is accessible to the Oracle Database software and on which the Oracle software owner has the read permission.

    Note:

    In the following script, substitute the correct values for your installation for the ORACLE_HOME and ORACLE_SID environment variables.

    #!/bin/sh
    export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
    export ORACLE_SID=orcl
    PATH=$ORACLE_HOME/bin:$PATH
    rman <<EOF
    connect target /
    RUN {
     ALLOCATE CHANNEL disk_iub DEVICE TYPE DISK;
     RECOVER COPY OF DATABASE WITH TAG daily_iub;
     BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG daily_iub DATABASE;
    }
    exit
    EOF
    

Task 3 - Testing the Backup Script

It is recommend that you run the script manually, to check for errors, before scheduling it. Your manual run of the script will start day one of the strategy, creating an incremental level 0 image copy of all datafiles.

To test the backup script:

  1. Log in to the database host as a user who is a member of the OSBACKUPDBA operating system group (typically the backupdba group).
  2. In a command window, enter the following command:
    full-script-path
    

    where full-script-path is the full path and file name of the script you created in Task 2.

    For example, if your script is in the file /u01/app/oracle/rman/daily_backup.sh, then enter this command:

    /u01/app/oracle/rman/daily_backup.sh
    

The script starts Oracle Recovery Manager (RMAN), which starts the backup. The output from RMAN includes warning messages similar to the following:

...
no copy of datafile 1 found to recover
no copy of datafile 2 found to recover
...
no parent backup or copy of datafile 1 found
no parent backup or copy of datafile 2 found
...

These messages are normal for the first run of the script.

Note:

For the second run of the script, the output includes only these warning messages:

no copy of datafile 1 found to recover
no copy of datafile 2 found to recover
...

Again, these messages are normal. For the third and subsequent script runs, no further warning messages are output.

Task 4 - Scheduling the Daily Backup—UNIX and Linux

The following procedure uses the cron utility to schedule daily database backups at 2:00 a.m.

To schedule the Oracle-suggested disk backup strategy:

  1. Ensure that you are logged in to the database host as a user who is a member of the OSBACKUPDBA operating system group (typically the backupdba group).

    The cron job will run as this host user.

  2. Start a text editor, and create and save a file with the following contents into your home directory. Name the file .crontab. (Note the period at the front of the file name.)
    MAILTO=first.last@example.com
    # MI HH DD MM DAY CMD
      00  2  *  *  *  full-script-path
    

    where full-script-path is the full path and file name of the script you created in Task 2.

    For example, if the script is in the file /u01/app/oracle/rman/daily_backup.sh, then the .crontab file must contain:

    MAILTO=first.last@example.com
    # MI HH DD MM DAY CMD
      00  2  *  *  *  /u01/app/oracle/rman/daily_backup.sh
    

    Note:

    Supply the desired e-mail address in the MAILTO line. This line is optional. Content written to stdout by the cron job is e-mailed to this address at the completion of the job.

  3. In a command window, change directory to your home directory and enter the following command:
    crontab .crontab
    

    This creates a crontab file for this user from the contents of .crontab.

    Caution:

    The existing crontab file for this user is overwritten. If you want to preserve the contents of this file and add this new job, use this command, which enables you to edit the existing file:

    crontab -e
    
  4. (Optional) Check the contents of the crontab file for this user with the following command:
    crontab -l
    
    MAILTO=first.last@example.com
    # MI HH DD MM DAY CMD
      00  2  *  *  *  /u01/app/oracle/rman/daily_backup.sh
    

See Also:

Your operating system documentation for a description of the crontab command and crontab files