Automate Oracle backups in Linux

The examples for this article were done on CENTOS 6.

First of all, we will start by creating scripts that perform backups. In total, we will need two files. One of the instructions that will go to RMAN, the second is to run RMAN and addictive instructions to execute from the first file.

We create the first file:

nano /home/skrypty/oracle/backup_inc0.txt

Enter the commands to get to RMAN:

backup as the compressed backup set incremental level 0 database; delete noprompt obsolete; 

In our case, it is a compressed backup of the entire database, which can also be the basis for incremental backups. Right after the full backup, old archives and archive logs are deleted. currently, set retention policy.

Create another file, this will run RMAN and download the script with instructions to it:

nano /home/skrypty/oracle/backup_inc0.sh

Inside it enter the command:

set ORACLE_SID =
rman target / @ / home / scripts / oracle / backup_inc0.txt

First sets the sid of the backup that we want to execute, the second starts RMAN and inserts the instructions from the first file. Time to give our script the appropriate CHMOD:

chmod 775 /home/scripts/oracle/backup_inc0.sh

You can check if everything works by firing the second script:

/home/scripts/oracle/backup_inc0.sh

We are now going to add an entry to crontab:

nano / etc / crontab 

I want to have backups done every day at 3 o’clock. I am adding this entry:

0 3 * * * root /home/scripts/oracle/backup_inc0.sh

The meaning of each item nicely explains the statement in the file:

# Example of job definition:
#. —– minute (0 – 59)
# | .pay (0 – 23)
# | | ./– day of month (1 – 31)
# | | | .– (1 – 12) OR jan, feb, mar, apr …
# | | | | .—- day of week (0 – 6) (Sunday = 0 or 7) OR sun, mon, tue, wed, fri, sat
# | | | | |
# * * * * * * * * * * * * * * * * * * * * *

We still have to reload CRONTAB:

service crond restart

I will make one small modification so that in a separate directory gathered logs from the backup. By the way, log files include the date and time of the backup. So I create a separate directory for the logs:

mkdir / home / 

logi … and edit our script (/home/scripts/oracle/backup_inc0.sh) so that it looks something like this:

set ORACLE_SID = XE
rman target / @ / home / scripts / oracle / backup_inc0.txt> / home / logs / backup_inc0 _ $ (date ‘+% Y-% m-% d_% H-% M-% S’) .log 

Now you can run the script to see if everything works. 🙂