#!/bin/sh
########################################################################
# Desc: thie script is used to monitor file size,and backup it.
# Author:
# Date: 2004-09-06
#########################################################################
#Function: process the backup action.
backup()
{
AVASIZE=`df .|grep -v Filesystem|awk -F" " '{print $4}'`
AVASIZE=`expr $AVASIZE \* 1000`
#echo $1
for F in $1
do
MBASENAME=`basename $F`
MDIRNAME=`dirname $F`
CURFILESIZE=`ls -l $F|grep -v total|grep -v "log.[0-9]\{4\}"|awk -F' ' '{print $5}'`
#***** IF FILTING SOME NOT VALID FILE,YOU MUST NOT COMPARE BELOW ******
if [ "$CURFILESIZE" == "" ];then
continue;
fi
echo $AVASIZE $CURFILESIZE $MBASENAME $MDIRNAME
if [ $CURFILESIZE -lt $AVASIZE ];then
echo "--- `date +%Y-%m-%d' '%T`: FOUND SO BIGGER FILE,BEGIN BACKUP ---" >> monitor_file_size.log
cp $F $F".`date +%Y_%m_%d_%H_%M_%S`"
#rm -f $F
>$F
echo " File $F BACKUP TO $F.`date +%Y_%m_%d_%H_%M_%S`, File Size: $CURFILESIZE" >> monitor_file_size.log
echo "--- `date +%Y-%m-%d' '%T`: END OF BACKUP ---" >> monitor_file_size.log
echo "" >> monitor_file_size.log
else
echo "WARNING: The partition has not enough space !"
fi
done;
}
if [ $# -ne 2 ]; then
echo "Usage: `basename $0` MONITOR_PATH MONITORFILE_SIZE(Mbytes)"
exit 0
fi
MPATH=$1
MSIZE=`expr $2 \* 1024`
backup "`find $MPATH -type f -size +$MSIZE -print`"
阅读(1318) | 评论(0) | 转发(0) |