Schedule periodic hot backups of a running database instance using RMAN

RMAN

In this article I will schedule periodic hot backups of a running database instance using rman.

To perform hot backups using rman, first you need to check if your database is in ArchiveLog mode.

[[email protected] ~]$ sqlplus “/ as sysdba”

SQL> SELECT log_mode FROM v$database;

LOG_MODE

NOARCHIVELOG

If not change it:

SQL> SHUTDOWN IMMEDIATE;

SQL> STARTUP MOUNT;

SQL> ALTER DATABASE ARCHIVELOG;

SQL> ALTER DATABASE OPEN;

SQL> SELECT log_mode FROM v$database;

LOG_MODE

ARCHIVELOG

Once it’s in ArchiveLog mode create the main rman script which will be called by crontab:

[[email protected] ~]$ vi /u01/rman_main

ORACLE_HOSTNAME=db1
export ORACLE_HOSTNAME
ORACLE_UNQNAME=orcl
export ORACLE_UNQNAME
ORACLE_BASE=/u01/app/oracle
export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_HOME
ORACLE_SID=orcl
export ORACLE_SID

/u01/app/oracle/product/11.2.0/db_1/bin/rman target=/ @/u01/rman_script

Where ORACLE_HOSTNAME is your machine hostname and ORACLE_UNQNAME and ORACLE_SID is the SID of the instance you need to backup.

[[email protected] ~]$ chmod a+x /u01/rman_main
Then we create the rman script itself:

[[email protected] ~]$ vi /u01/rman_script

run {
allocate channel ch1 type disk format ‘/u01/backup%d_DB_%u_%s_%p’;
backup database;
backup archivelog all;
release channel ch1;
}

This will backup the database creating a file under “/u01/” directory.
In the above script %d, %u, %s, %p are substitution variables for generating unique file name, if you wish to know more about these variables have a look HERE.

You could manually run rman_main to take hot backups, but if you like to run scheduled backups we need to add this to crontab:

[[email protected] ~]# crontab -e -u oracle

I will schedule backup everyday at 18:10 (6.10 PM)

10 18 * * * /u01/rman_main

The first five fields are:

minute (0-59)
hour (0-23)
day of the month(1-31)
month of the year (1-12)
day of the week (0-6 with 0 = Sunday)

For more info on crontab have a look at crontab.org

NOTE: At first I was unable to edit this file, so after a brief search I had to set EDITOR variable according to my preferred file editor.

In my case:

[[email protected] ~]# export EDITOR=nano

[[email protected] ~]# crontab -e -u oracle

That’s all!!

service crond status


It will schedule full backup on sunday at 9.30pm EST.

It will schedule incremental backup everyday 9.30pm EST.

It will schedule cumulative backup everyday 9.30pm EST.

It will schedule transfer of backup files every minute.

[email protected]

30 21 * * 0 /bin/sh /home/oracle/rman_mainfull.sh

30 21 * * 3 /bin/sh /home/oracle/rman_maincum.sh

01 03 * * * /bin/sh /home/oracle/rman_maininc.sH

* * * * * /bin/sh /home/oracle/ftp.backup.script.sh

The first five fields are:
minute (0-59)
hour (0-23)
day of the month(1-31)
month of the year (1-12)
day of the week (0-6 with 0 = Sunday)