Skip to main content

Automating RMAN backup Jobs with CRON utility

Automating RMAN backup Jobs with CRON utility

DBAs often debate whether they should use Oracle Scheduler or the Linux/Unix cron utility for scheduling and automating tasks. There are many benefits that Oracle Scheduler  has over cron, but yet despite these benefits, many DBAs prefer to use a scheduling utility such as cron to automate many tasks. There are some advantages of cron:-
  • Easy to use, simple, tried and true, only takes seconds to create or modify jobs.
  • Almost universally available on all Linux/Unix boxes; for the most part, runs nearly identically, regardless of the Linux/Unix platform (yep!, there are minor differences)
  • Database agnostic; operates independently of the database and works the same, regardless of the database vendor or version.
  • Works whether or not the database is available.
When your Linux server boots up, a cron background process is automatically started to manage all the cron jobs in the  system.
On your Linux box, you can check  to see whether the cron daemon is running, using the service command:

Enabling Access to cron

Sometimes when System Admins set up a new Linux box, they don't (by default) enable the use of cron for all users on the system. So to verify  whether you have  access to cron, invoke  the utility as follows:

      $ crontab -e

If you receive the following error massage, then you do not have access:

       You (oracle) are not allowed to use this program (crontab)

If you received this error then you can enable cron access as root user or ask your SA to enable it for you.

# echo oracle >> /etc/cron.allow

Once the oracle entry is added to the /etc/cron.allow file, you can use the crontab utility to schedule a job.

Next you need a backup script, you can download a backup script using the link below or write your own rman backup script. 


Once you have your script ready the next thing is to understand cron table enteries

Understanding cron Table Entries

Your cron  table is a list of numbers and commands that cron background  process will run at specified time and schedule. The crontab utility expects entries to follow a well-defined format. It's a good practice to add a comment line at the beginning of your crontab file that documents the required format, like :-

# min(0-59) hr(0-23) dayMonth(1-31) monthYear(1-12) dayWeek(0/7-6) commandOrScript

The number sign (#) in the cron file represents the start of a comment. Any text entered after # is ignored by cron.

Scheduling a Job to Run Automatically

To schedule a job, you must add a line in your cron table, specifying  the time you want  the job to execute.
You can edit you cron table directly with the -e (editor) option of the crontab command:

$ crontab -e

When issuing the previous command, you will be presented with a file to edit. This file is known as your cron table (crontab).
To schedule a script name rman_backup.sh to run daily, at 11:50 pm enter the line into your cron table:

# min(0-59) hr(0-23) dayMonth(1-31) monthYear(1-12) dayWeek(0/7-6) commandOrScript
 50   23    *    *    *     /home/oracle/bin/rman_backup.sh  1>/home/oracle/bin/log/bck.log 2>&1

Exit the cron table file. If your default editor is vi, then type wq to exit. When you exit crontab, your cron table is saved for you. To view your cron entries, use the -l (list) option of the crontab command:

$ crontab -l

To remove your cron table completely, use the r option:

$ crontab -r

NB!! Before running the previous command, you should save your cron table in a text file, as shown:
$ crontab -l > saved.cron
In this way, you can refer to the saved file, in the event that you didn’t mean to delete your cron table.

The cron job above use redirection features to send the output of a shell script to a log file.
In the cron table entry, any standard output and error messages generated by the rman_backup.sh shell script are captured in a file named bck.log

If you don’t redirect the cron job output, then any output will be e-mailed to the user that owns the cron table. You can override this behavior by specifying the MAILTO variable directly within the cron table.



Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. Crontab files are simple text files that have a particular format. Each line of a crontab file follows a particular format as a series of fields, separated by spaces and/or tabs. Each field can have a single value or a series of values. A single cron job should take up exactly one line, but this can be a long line (more than 80 characters).
    for further information click here: how to setup a cron job

    ReplyDelete

Post a Comment

Popular posts from this blog

Oracle Database 19c Step by Step Installation On Oracle Linux 7.6

This post describes the installation of Oracle Database 19c 64-bit on Oracle Linux 7.6  x86-64 bit. The Linux server needs a minimum of 3G swap and secure Linux set to permissive. An example of this type of Linux installation can be seen here . Download Software Download the Oracle software from oracle edelivery . Oracle Installation Prerequisites Automatic Setup Use the "oracle-database-preinstall-19c" package to perform all your prerequisite setup. # yum install -y oracle-database-preinstall-19c If you are using RHEL7 or CentOS7, you can pick up the PRM from the OL7 repository and install it. It will pull the dependencies from your normal repositories. # yum install -y https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm Hosts File Set a fully qualified name for the server in the "/etc/hosts" file. < IP-address > < fully-qualified-machine-name > < machin...

How to Delete Old Trace & Dump files with ADRCI

The ADRCI command interpreter has multiple features:- Create a package with incident or problem information for Oracle Support Analyze diagnostic data within the Automatic Diagnostic Repository (ADR) Run health checks In this post, we'll be concentrating on deleting the old diagnostic files with ADRCI. Set your environment and run the ADRCI utility: $ adrci Use the following command to list the ADR homes: adrci> show home ADR Homes: diag/rdbms/db11g/DB11G diag/tnslsnr/sol10/listener Choose the ADR home from the list above: adrci> set home diag/rdbms/db11g/DB11G Check the current retention policy: adrci> show control Check the following columns in the output: LONGP_POLICY:- It is set to 365 days by default. It is responsible for Incidents and Health Monitor warnings. SHORTP_POLICY:- It is set to 30 days by default. It manages the trace and core dump files. Use the following commands to change the retention policy: Specify the time in hours: 10 Days = 240 ...

Oracle Database 12C Error Codes, Solutions and Suggestions from ORA-19700 to ORA-20000

Oracle 12C Error Codes, Solutions and Suggestions from ORA 19700 to ORA 20000 ORA-19700: device type exceeds maximum length of string Cause:  The device type indicated is invalid. Action:  Supply a correct device type and retry the allocation. ORA-19701: device name exceeds maximum length of  string Cause:  The device name indicated is invalid. Action:  Supply a correct device name and retry the allocation. ORA-19702: device parameter exceeds maximum length of  string ORA-19703: device command string exceeds maximum length of  string Cause:  The device command string exceeds maximum length. Action:  Correct the command and retry the operation. ORA-19704: file name exceeds maximum length of  string Cause:  The specified file name, which was a parameter to a copy, backup, or restore operation, exceeds the maximum file name length for this operating system. Action:  Retry the operation with a s...