Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to remove archive logs as they are applied independing of backup

Status
Not open for further replies.

jlaw10

Technical User
Jul 28, 2005
54
US
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}:Delete ${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}:Delete ${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!"
 
What happens if you simply comment out the following line ?
/usr/openv/netbackup/bin/bplist -l "/oracle/PRD/saparch/*.dbf" > ${BACKUP_LIST}

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I still receive the following message:

INFO:071121_125730:Start archive cleanup.
ERR:071121_125730:Cannot delete PRDarch1_248703.dbf because no backup record is
found.
ERR:071121_125730:Cannot delete PRDarch1_248704.dbf because no backup record is
found.
 
I would replace both occurrences of this:
Code:
  l=`cat ${BACKUP_LIST} | grep ${g}| wc -l`
  if [ ${l} -ge 1 ]; then
    print "INFO:${dt}:Delete ${g}!"
    rm /oracle/${ORACLE_SID}/saparch/${g}
  else
    print "ERR:${dt}:Cannot delete ${g} because no backup record is found."
  fi
by this:
Code:
  print "INFO:${dt}:Delete ${g}!"
  rm /oracle/${ORACLE_SID}/saparch/${g}
hope this helps
 
The latest recommended change resulted in the following output and did not delete any of the archive log files:

sddb03:eek:raprd 22% ./cleanup_archive.ksh > cleanup.log
EXIT STATUS 227: no entity was found
find: cannot open /oracle/PRD/saparch/PRDarch*.dbf.gz: No such file or directory
INFO:071122_165302:Archive cleanup end!

[1] Done ./cleanup_archive.ksh cleanup_archive.log
EXIT STATUS 227: no entity was found
find: cannot open /oracle/PRD/saparch/PRDarch*.dbf.gz: No such file or directory
/oracle/PRD/scripts/cleanup_archive/tmp/lock.tmp: No such file or directory

sddb03:eek:raprd 24% more cleanup.log
INFO:071122_165136:Start archive cleanup.
INFO:071122_165302:Archive cleanup end!


 
Imho you should get this very same error message whether or not you applied PHV's or mine suggestion ...

From the output you showed I gather this:
On your system there are no files /oracle/PRD/saparch/PRDarch*.dbf.gz, and so they cannot be found, and cannot be deleted either.
There are files /oracle/PRD/saparch/PRDarch*.dbf, but they are not old enough (see ${KEEP_DAYS}), and so cannot be deleted either.

So please double check. If I am wrong, please show a part of the output of ls -l command in directory /oracle/PRD/saparch.
 
Now I receive the following output but the archive logs are not deleted:

INFO:071128_155800:Start archive cleanup.
INFO:071128_155940:Archive cleanup end!
 
Modified script after recommended mods:

"cleanup_archive.ksh" 47 lines, 1407 characters
#!/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##/*/}
print "INFO:${dt}:Delete ${g}!"
rm /oracle/${ORACLE_SID}/saparch/${g}
done
/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##/*/}
print "INFO:${dt}:Delete ${g}!"
rm /oracle/${ORACLE_SID}/saparch/${g}
done
rm ${LOCKFILE}
dt=`date +%y%m%d_%H%M%S`
print "INFO:${dt}:Archive cleanup end!"
 
Did you read my previous post?
Do you understand what the ${KEEP_DAYS} in your script is for?
(a hint: man find)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top