Skip to content

Simple cronjob for datapump

Today morning I just written a small script for taking full database using datapump and after I scheduled on every one week with cron.

#Script to perform a full database  export backup using by datapump on every wednesday
# Script Written by
# Mohamed Azar
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1; export ORACLE_HOME
ORACLE_SID=devcrm; export ORACLE_SID
expdp system/Admin123 directory=exportdb dumpfile=exportdb-$(date +%Y-%m-%d).dmp logfile=exportdb-$(date +%Y-%m-%d).log full=y exclude=statistics
# Send log to mail
tail -4 /u01/datapump/dumps/exportdb-$(date +%Y-%m-%d).log | mailx -s “Cronjob Oracle Export Output:SIEBELDEV”

#Remove old previous dumpfile
rm -rf /u01/datapump/dumps/previous/*.*

#Find out last week dumpfiles and move to previous directory
cd /u01/datapump/dumps
chown -Rf oracle:oinstall *.dmp *.log
chmod -Rf 775 *.dmp *.log
find -mtime +6 -exec mv {} /u01/datapump/dumps/previous \;
gzip /u01/datapump/previous/*.*
gzip *.dmp *.log

Cronjob schedule :

I scheduled here , every week on wednesday at 04:00pm

[oracle@siebelpoc cronjob]$ vi cron.exportdb
0 16 * * 3 /u01/datapump/dumps/scripts/

[oracle@siebelpoc cronjob]$crontab cron.exportdb

4 Comments Post a comment
  1. Hi I tried the above cronjob but getting the below exception.

    ORA-39001: invalid argument value
    ORA-39000: bad dump file specification
    ORA-31641: unable to create dump file “/opt/oracle/admin/CI/dpdumps/export_full.dmp”
    ORA-27040: file create error, unable to create file
    Linux-x86_64 Error: 2: No such file or directory

    Could you please help me to solve this???

    September 13, 2012
  2. Ahmad #

    Thanks Mohamed!

    March 24, 2013
  3. Mikser #

    How to add to this script gzip or bzip2 compression?

    March 10, 2018

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: