文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>搜索体积较大的文件,自动备份的脚本

搜索体积较大的文件,自动备份的脚本

时间:2008-05-23  来源:liyf0371

#!/bin/sh
########################################################################
# Desc: thie shell script is used to monitor file size,and backup it.
# Author:[email protected]
# 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`"
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载