Wednesday, June 21, 2017

Simple Linux shell script for oracle export or expdp backup from cron job

This shell script is for expdp backup of Oracle database, it will take export ( data pump ) backup of "scott" user every night at 1:00AM and it will remove the backup older than 3 days.

1) save the script as below (with oracle user)



export ORACLE_BASE=/userdata/app/ora11gR2; #export ORACLE_BASE
export ORACLE_HOME=$ORACLE_BASE/prduct/; #export ORACLE_HOME
export ORACLE_SID=orcl; #export ORACLE_SID
export EXPORT_FOLDER=/userdata/app/dump;
DATE=$(date +"%m%d%y") ;
$ORACLE_HOME/bin/expdp system/system schemas=scott directory=DIR_DUMP1 dumpfile=$DATE-EXPDP_CRON.DMP logfile=$DATE-EXPDP_CRON_LOG.log ;
find /userdata/app/dump/ -name *EXPDP_CRON_TAR.tar.bz2 -mtime +3 -delete;


Please change ORACLE_BASE,ORACLE_HOME,ORACLE_SID and EXPORT_FOLDER (directory location, where backup will store) values as per your environment and change or add schemas name as yours.

2) Create a cron job log location as below (with oracle user)


3) Adding to cron job-

oracle$ crontab -e

then add below line with vi editor commands

0 1 * * * /app/scripts/ >> /app/logs/expdb_backup_logs.log 2>&1

[ Note- for testing purpose, you can schedule it for every 5 minutes like below

*/5 * * * * /app/scripts/ >> /app/logs/expdb_backup_logs.log 2>&1


4) Make the script executable

oracle$ chmod +x /app/scripts/

5) check the cron job logs for details

oracle$ cat /app/logs/expdb_backup_logs.log



Mehedi Liku said...

Effective Info...............Thanks Boss.

Mehedi Liku said...

Effective Info................ Thanks Boss.