My team has limited shell scripting skills and we need to modify the following script to no longer delete only archive logs that have been backed up by Netbackup (because these files exist on 2 other servers and don't require backups). So we would like the archive logs to be deleted as they are applied to the database. Thanks to all in advance!
#!/bin/ksh
ORACLE_SID=PRD
KEEP_DAYS=1
ARCHIVE_DIR=/oracle/${ORACLE_SID}/saparch
LOG_DIR=/oracle/${ORACLE_SID}/scripts/cleanup_archive/log
TMP_DIR=/oracle/${ORACLE_SID}/scripts/cleanup_archive/tmp
BACKUP_LIST=${TMP_DIR}/backup_list.tmp
ERR_FILE=${LOG_DIR}/cleanup_archive.err
ERR=ERR
dt=`date +%y%m%d_%H%M%S`
LOG_FILE=${LOG_DIR}/sync.${dt}.log
LOCKFILE=${TMP_DIR}/lock.tmp
if [[ ! -d ${TMP_DIR} ]]; then
print "${ERR}:${dt}:${TMP_DIR} directory does not exist! Archive cancel" | tee
-a ${ERR_FILE}
return 1
elif [[ ! -w ${TMP_DIR} ]]; then
print "${ERR}:${dt}:NO WRITE ACCESS to ${TMP_DIR} directory! Archive cancel" |
tee -a ${ERR_FILE}
return 1
fi
if [[ -a ${LOCKFILE} ]]; then
print "${ERR}:${dt}:Lockfile ${LOCKFILE} exists!" | tee -a ${ERR_FILE}
return 1
else
touch ${LOCKFILE}
fi
print "INFO:${dt}:Start archive cleanup."
/usr/openv/netbackup/bin/bplist -l "/oracle/PRD/saparch/*.dbf" > ${BACKUP_LIST}
for f in `find ${ARCHIVE_DIR}/PRDarch*.dbf -mtime +${KEEP_DAYS}`
do
g=${f##/*/}
l=`cat ${BACKUP_LIST} | grep ${g}| wc -l`
if [ ${l} -ge 1 ]; then
print "INFO:${dt}elete ${g}!"
rm /oracle/${ORACLE_SID}/saparch/${g}
else
print "ERR:${dt}:Cannot delete ${g} because no backup record is found."
fi
done
/usr/openv/netbackup/bin/bplist -l "/oracle/PRD/saparch/*.dbf.gz" > ${BACKUP_LIS
T}
for f in `find ${ARCHIVE_DIR}/PRDarch*.dbf.gz -mtime +${KEEP_DAYS}`
do
g=${f##/*/}
l=`cat ${BACKUP_LIST} | grep ${g}| wc -l`
if [ ${l} -ge 1 ]; then
print "INFO:${dt}elete ${g}!"
rm /oracle/${ORACLE_SID}/saparch/${g}
else
print "ERR:${dt}:Cannot delete ${g} because no backup record is found."
fi
done
rm ${LOCKFILE}
dt=`date +%y%m%d_%H%M%S`
print "INFO:${dt}:Archive cleanup end!"
#!/bin/ksh
ORACLE_SID=PRD
KEEP_DAYS=1
ARCHIVE_DIR=/oracle/${ORACLE_SID}/saparch
LOG_DIR=/oracle/${ORACLE_SID}/scripts/cleanup_archive/log
TMP_DIR=/oracle/${ORACLE_SID}/scripts/cleanup_archive/tmp
BACKUP_LIST=${TMP_DIR}/backup_list.tmp
ERR_FILE=${LOG_DIR}/cleanup_archive.err
ERR=ERR
dt=`date +%y%m%d_%H%M%S`
LOG_FILE=${LOG_DIR}/sync.${dt}.log
LOCKFILE=${TMP_DIR}/lock.tmp
if [[ ! -d ${TMP_DIR} ]]; then
print "${ERR}:${dt}:${TMP_DIR} directory does not exist! Archive cancel" | tee
-a ${ERR_FILE}
return 1
elif [[ ! -w ${TMP_DIR} ]]; then
print "${ERR}:${dt}:NO WRITE ACCESS to ${TMP_DIR} directory! Archive cancel" |
tee -a ${ERR_FILE}
return 1
fi
if [[ -a ${LOCKFILE} ]]; then
print "${ERR}:${dt}:Lockfile ${LOCKFILE} exists!" | tee -a ${ERR_FILE}
return 1
else
touch ${LOCKFILE}
fi
print "INFO:${dt}:Start archive cleanup."
/usr/openv/netbackup/bin/bplist -l "/oracle/PRD/saparch/*.dbf" > ${BACKUP_LIST}
for f in `find ${ARCHIVE_DIR}/PRDarch*.dbf -mtime +${KEEP_DAYS}`
do
g=${f##/*/}
l=`cat ${BACKUP_LIST} | grep ${g}| wc -l`
if [ ${l} -ge 1 ]; then
print "INFO:${dt}elete ${g}!"
rm /oracle/${ORACLE_SID}/saparch/${g}
else
print "ERR:${dt}:Cannot delete ${g} because no backup record is found."
fi
done
/usr/openv/netbackup/bin/bplist -l "/oracle/PRD/saparch/*.dbf.gz" > ${BACKUP_LIS
T}
for f in `find ${ARCHIVE_DIR}/PRDarch*.dbf.gz -mtime +${KEEP_DAYS}`
do
g=${f##/*/}
l=`cat ${BACKUP_LIST} | grep ${g}| wc -l`
if [ ${l} -ge 1 ]; then
print "INFO:${dt}elete ${g}!"
rm /oracle/${ORACLE_SID}/saparch/${g}
else
print "ERR:${dt}:Cannot delete ${g} because no backup record is found."
fi
done
rm ${LOCKFILE}
dt=`date +%y%m%d_%H%M%S`
print "INFO:${dt}:Archive cleanup end!"