Automating Oracle RMAN backups

Script Language: Korn Shell

This RMAN backup script can be used to schedule full, incremental level 0 or incremental level 1 backups.

I recommend running the INC0 backup on Wednesday evenings and INC1 on the other 6 days of the week in the oracle user’s crontab.

It can update your recovery catalog with the latest backup information if desired.

It will always send an email alert indicating success or failure.

Edit the user variables within the script to suit your environment, set execute permissions on the script file before test-executing it as the user oracle, and then scheduling it with crontab.

Configuring RMAN

Don’t forget to configure RMAN before you test the script. i.e. as the oracle OS user, type RMAN target / to enter the RMAN shell then some CONFIGURE **** commands to configure RMAN. e.g. CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 5 DAYS; etc.

Here are my recommended RMAN settings:

$ rman target /

RMAN> show all;

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 5 DAYS;
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘%F’; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO COMPRESSED BACKUPSET;
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 ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM ‘AES128’; # default
CONFIGURE COMPRESSION ALGORITHM ‘BASIC’ AS OF RELEASE ‘DEFAULT’ OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE RMAN OUTPUT TO KEEP FOR 7 DAYS; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘/oracle/19c/dbs/snapcf_RLL.f’; # default

Other Recommendations

Read The Fine Manual (RTFM).

Enable archive logging.

Set your fast recovery area (the directory where the Oracle backups are stored) by setting the value of the DB_RECOVERY_FILE_DEST initialization parameter to an appropriate directory on a large enough disk partition.

Ensure that your fast recovery area is backed up every night and those filesystem backups are stored offsite and onsite.

Ensure that your fast recovery area is on a disk that is a separate disk to your database’s data files for higher fault tolerance.

Ensure that your DB_RECOVERY_FILE_DEST_SIZE intialization parameter is large enough.

Enable Force Logging in the database.

Set the DB_BLOCK_CHECKSUM initialization parameter to TYPICAL.

Unset the values of all LOG_ARCHIVE_DEST and LOG_ARCHIVE_DEST_n initialization parameters by setting them to an empty string.

Enable block change tracking.

Duplex your redo log files to multiple disks / SSDs for a higher chance of recovery when there is a server crash and the database did not shut down properly.

Test the restoration of a database once a year with various scenarios. e.g. Use FLASHBACK DATABASE to perform a recovery from a logical data loss (such as data corrupted by a hacker), or delete all data files then restore to a point in time using RMAN, or delete everything Oracle Database related on the server and try to restore the filesystem using your filesystem backup system and then use RMAN to restore the database data files.

Document everything in a knowledgebase and back that up too.

Good luck!

RMAN Backup Script for Korn Shell

Posted

in

,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *