阅读更多
脚本名:clearup.ksh
配置文件名:clearuptab
#!/bin/ksh
#clearup.ksh
THISDAY=$(date +%Y%m%d%H%M%S)
NFS_MOUNTDIR='/home/other'
CLEARUP_HOME=/backup/diskclearup
CLEARUP_TABLST=$CLEARUP_HOME/clearuptab
CLEARUP_DETAIL=$CLEARUP_HOME/clearup.lst
CLEARUP_LOG=$CLEARUP_HOME/clearup.log
echo "" >> $CLEARUP_LOG
echo "+++ Diskclearup: disk clearup start." >> $CLEARUP_LOG
touch $CLEARUP_DETAIL
cat $CLEARUP_TABLST | while read LINE
do
case $LINE in
\#*) # skip over comment-line in oratab
;;
*)
ITEM_SID=`echo $LINE | awk -F: '{print $1}'`
ITEM_DIR=`echo $LINE | awk -F: '{print $2}'`
ITEM_TEMPLATE=`echo $LINE | awk -F: '{print $3}'`
RESERVER_DAYS=`echo $LINE | awk -F: '{print $4}'`
ITEM_FLAG=`echo $LINE | awk -F: '{print $6}'`
CLEARUP_DESTFILE=$NFS_MOUNTDIR/${ITEM_SID}_clearup_$THISDAY.tar.gz
# Proceed only if third field is 'Y'
if [ "`echo $LINE | awk -F: '{print $5}'`" = "N" ]
then
echo "$THISDAY INFO: No start entry for ITEM $ITEM_SID in $CLEARUP_TABLST ." >>$CLEARUP_LOG
elif [ "`echo $LINE | awk -F: '{print $5}'`" = "Y" ]
then
if (( `expr $RESERVER_DAYS` < 1 ))
then
echo "$THISDAY INFO: Error reserver days entry for ITEM $ITEM_SID in $CLEARUP_TABLST ." >>$CLEARUP_LOG
elif [ "`echo $ITEM_FLAG`" != "C" ] && [ "`echo $ITEM_FLAG`" != "D" ]
then
echo "$THISDAY INFO: Error FLAG for ITEM $ITEM_SID in $CLEARUP_TABLST" >>$CLEARUP_LOG
else
#
find $ITEM_DIR -mtime +$RESERVER_DAYS -name "$ITEM_TEMPLATE" -type f -print >$CLEARUP_DETAIL 2>>$CLEARUP_LOG
if [ "$?" -ne 0 ]
then
echo "$THISDAY INFO: Error execute FIND command for ITEM $ITEM_SID in $CLEARUP_TABLST" >>$CLEARUP_LOG
continue
fi
#
#--Closed by HuangYuesong....
#--tar -zcvf ${CLEARUP_DESTFILE} --files-from $CLEARUP_DETAIL 2>&1 >>$CLEARUP_LOG
#--if [ "$?" -ne 0 ]
#--then
#-- echo "$THISDAY INFO: Error execute TAR command for ITEM $ITEM_SID in $CLEARUP_TABLST"
#-- continue
#--fi
#
#
while read SUBLINE
do
#
if [ "`echo $ITEM_FLAG`" = "C" ]
then
> $SUBLINE
else
rm $SUBLINE
if [ "$?" -ne 0 ]
then
echo "$THISDAY INFO: Fail RM $SUBLINE for ITEM $ITEM_SID in $CLEARUP_TABLST." >>$CLEARUP_LOG
else
echo "$THISDAY INFO: Succ RM $SUBLINE for ITEM $ITEM_SID in $CLEARUP_TABLST." >>$CLEARUP_LOG
fi
fi
done < $CLEARUP_DETAIL
#
#
fi
else
echo "$TIMESTAMP INFO: Error define entry for ITEM $ITEM_SID in $CLEARUP_TABLST ." >>$CLEARUP_LOG
fi
;;
esac
done
echo "+++ Diskclearup: disk clearup end." >> $CLEARUP_LOG
配置文件示例:#
# This file is used by clearup.ksh .
#
# item_sid : item_dir : file_regular : reserve_days : auto_start(Y/N) : delete&Create / Delete
vmarchlog:/oracle/oradata/vmdb/archive:*dbf:7:Y:D
gjdb-dmp:/backup/gjdb:*.dmp:2:Y:D
gjdb-log:/backup/gjdb:*.log:2:Y:D
gjdb-par:/backup/gjdb:*.par:2:Y:D
vmdb-dmp:/backup/vmdb/db:*.dmp:2:Y:D
vmdb-log:/backup/vmdb/db:*.log:2:Y:D
vmdb-par:/backup/vmdb/db:*.par:2:Y:D
vmdbgpslog-dmp:/backup/vmdb/gpslog:*.dmp:4:Y:D