Auto Backup of Oracle Database

From SmartHCM Wiki
Revision as of 12:47, 22 December 2016 by Usman (talk | contribs) (Created page with " Create a backup script file; <pre> vim /home/oracle/oraclebackup.sh </pre> Write following code in oraclebackup.sh file <pre> export ORACLE_BASE=/u01/app/oracle export ORA...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Create a backup script file;

vim /home/oracle/oraclebackup.sh

Write following code in oraclebackup.sh file

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=SMARTHCM
expdp system/password@pdbsmarthcm schemas=smarthcm directory=data_dump dumpfile=smarthcm
mv /u01/data_dump/smarthcm.dmp /u01/data_dump/smarthcm_`date +%Y_%m_%d_%H`.dmp

Create a Cron Job;

crontab -e

Insert following schedule in cron job;

0 23 * * * /home/oracle/oraclebackup.sh

Understanding Cron the scheduler

Crontab Format:
Minute | Hour | Day | Month | DayOfWeek | user | ThingToDo

'user' is the account name for the 'ThingToDo' to be run under. Exceptionally useful. You don't want every job running as root do you?
'ThingToDo' is as per any command line syntax. Typically, it invokes a script.
'Day' and 'Date' are easy to understand, but very difficult to read in their raw form

Thus, our cron job will execute the script oraclebackup.sh on 23:00 hours daily.