Requirement:
Configure a shell script, to take export backup of table daily at 3 PM and send the log to stake holders.
Script: ( EXP_TAB_cmprss.sh)
# $Header: EXP_TAB_cmprss.sh # *====================================================================================+ # | Author - DBACLASS ADMIN TEAM # | | # +====================================================================================+ # | # | FILENAME # | EXP_table_bkp_cmprss_dbaclass.sh # | # | DESCRIPTION # | Daily Export backup script of a list of table # | PLATFORM # | Linux/Solaris # +===========================================================================+ #!/bin/bash echo Set Oracle Database Env export ORACLE_SID=$1 export ORACLE_HOME=/oracle/app/oracle/product/12.1.0/dbhome_1 export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib export PATH=$ORACLE_HOME/bin:$PATH:/usr/local/bin export TIMESTAMP=`date +%a%d%b%Y` export EXP_DIR=/export/home/oracle echo ======= echo Export command echo ======= echo $ORACLE_HOME $ORACLE_HOME/bin/expdp \'/ as sysdba\' directory=DB_DUMPS dumpfile=expdp_tab_${TIMESTAMP}_%U.dmp logfile=expdp_log_${TIMESTAMP}.log tables=DBATEST.ORDER_TAB PARALLEL=6 COMPRESSION=ALL echo SEND MAIL TO STAKE HOLDERS echo ======= mailx -s "$ORACLE_SID $TIMESTAMP Export backup logfile" support@dbaclass.com < $EXP_DIR/expdp_log_${TIMESTAMP}.log echo Export completed at $TIMESTAMP exit
give 755 permission
chmod 755 EXP_TAB_cmprss.sh
Now configure the script in crontab as below( pass the ORACLE_SID )
00 15 * * * /export/home/oracle/EXP_TAB_cmprss.sh TESTDB
NOTES: Please let us know if you are getting aany errors:
Ok, but how to remove dmp files for exmaple:
rm /export/home/oracle *expdp_tab_${TIMESTAMP}_%U.dmp -mtime +30 -delete
andleave one which was generated a last of month.
Will add that part also
find /export/home/ -name “*.dmp” -mtime +30 -exec rm -vf {} \;
test –> find /export/home/ -name “*.dmp” -mtime +30 -exec ls -lrth {} \;
or you simply make the dumpfiles reusable
Add reuse_dumpfiles=y
Thanks for the scripts. Really helpful.
After running the expdp command successfully, the script is not proceeding to next line.
Instead I have to press Ctrl+D manually to proceed for further execution.
Any idea “How to overcome this issue?”
Please let me know how you executed the shell script. You configured in crontab and it ran from that schedule?
Also your os type(linux or solaris or hp)