Discussions
Categories
- 197.2K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.8K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 555 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.4K SQL Developer
- 296.3K Development
- 17 Developer Projects
- 139 Programming Languages
- 293K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 158 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 205 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 468 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
reg: deletion of dump files

HI Experts,
have written the below script:-EXP_TAB_cmprss.sh to take the export backup through script.
Need to add in the start of script to delete export dump 3 days old and then start export backup,
script should not execute without deleting old backups,
if it fails to delete old backup , script should terminate and send us alert.
# $Header: EXP_TAB_cmprss.sh
# *====================================================================================+
#
# | |
# +====================================================================================+
# |
# | FILENAME
# |
# |
# | 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=5 COMPRESSION=ALL
echo SEND MAIL TO STAKE HOLDERS
echo =======
mailx -s "$ORACLE_SID $TIMESTAMP Export backup logfile" [email protected] < $EXP_DIR/expdp_log_${TIMESTAMP}.log
echo Export completed at $TIMESTAMP
exit
in EXP_DIR we have below files generated after running script
-rwxrwxrwx 1 tuser tuser 1.4K May 6 12:25 EXP_TAB_cmprss.sh
-rwxrwxrwx 1 t2n5463 odba 3.2G May 6 13:13 expdp_tab_Thu06May2021_05.dmp
-rwxrwxrwx 1 t2n5463 odba 3.1G May 6 13:13 expdp_tab_Thu06May2021_03.dmp
-rwxrwxrwx 1 t2n5463 odba 22G May 6 13:13 expdp_tab_Thu06May2021_02.dmp
-rwxrwxrwx 1 t2n5463 odba 2.9G May 6 13:13 expdp_tab_Thu06May2021_04.dmp
-rwxrwxrwx 1 t2n5463 odba 25G May 6 13:13 expdp_tab_Thu06May2021_01.dmp
-rw-r--r-- 1 t2n5463 odba 8.7K May 6 13:13 expdp_log_Thu06May2021.log
Any suggestion how can we add inside the script to , add in the start of script to delete export dump 3 days old and then start export backup,
script should not execute without deleting old backups,
if it fails to delete old backup , script should terminate and send us alert.
Answers
-
Your export creates dump files in OS directory Oracle directory object DB_DUMPS is pointing to while you showing EXP_DIR files. Is Oracle directory object DB_DUMPS pointing to same OS directory as EXP_DIR (/export/home/oracle)? Anyway, command below will delete all files in directory $EXP_DIR named expdp_tab_*.dmp (* is wildcard mathing any number of any characters - you can come up with more precise match if needed) created 3 or more days ago:
find $EXP_DIR/expdp_tab_*.dmp -type f -ctime +3 -exec rm {} \;
SY.
-
Thanks experts,
we have files like, containing string characters like: Thu06May2021 is above find command will accordingly fetch the details.
so 3 days old like above Monday dumps files need to delete.
-rwxrwxrwx 1 t2n5463 odba 3.2G May 6 13:13 expdp_tab_Thu06May2021_05.dmp
-rwxrwxrwx 1 t2n5463 odba 3.1G May 6 13:13 expdp_tab_Thu06May2021_03.dmp
-rwxrwxrwx 1 t2n5463 odba 22G May 6 13:13 expdp_tab_Thu06May2021_02.dmp
-rwxrwxrwx 1 t2n5463 odba 2.9G May 6 13:13 expdp_tab_Thu06May2021_04.dmp
-rwxrwxrwx 1 t2n5463 odba 25G May 6 13:13 expdp_tab_Thu06May2021_01.dmp
-
Why do extra unnecessary coding if OS maintaint file create time? -ctime +3 looks for files created more than 3 days ago.
SY.
-
Now when I said created it applies just to this particular case. Attribute ctime is last change time not true file create time but since I doubted anyone changes export dump file we can consider it as create time.
SY.
-
Thanks experts,
I tired with :-
find /export/home/oracle/expdp_tab_*.dmp -type f -ctime +1 -exec ls {} \;
to check one day old files, somehow not showing any o/p.
-
One day old means 24 hours before now. So if, for example, file was last changed(created) yesterday after 3:06 pm (my current time) it will not show up. You can also try using mtime (modification time) instead of ctime.
SY.