分享我的一个脚本,检测程序更新,有更新做备份
达到的目的: 项目程序不定期更新,一旦有更新就需要做一次备份,但是一些日志,缓存,临时文件需要排除掉。#! /bin/bash
basedir="/data/web/"
bakdir="/data/web_backup"
while :; do
cd $basedir
sum=0
for f in `ls|grep -v logs|grep -v tmp `; do
n=`find $f/ -type f -mmin -5 |wc -l`
sum=$[$sum+$n]
done
prename=`date +%m%d%H%M`
if [ $sum -gt "0" ]; then
/usr/bin/rsync -a --exclude=logs --exclude=tmp $basedir $bakdir/$prename\_web
cd $bakdir
tar zcf $prename\_web.tar.gz $prename\_web
rm -r $prename\_web
/usr/bin/find $bakdir/ -mtime +2 |xargs rm -rf
fi
sleep 300
done
basedir="/data/web/"
bakdir="/data/web_backup"
while :; do
cd $basedir
sum=0
for f in `ls|grep -v logs|grep -v tmp `; do
n=`find $f/ -type f -mmin -5 |wc -l`
sum=$[$sum+$n]
done
prename=`date +%m%d%H%M`
if [ $sum -gt "0" ]; then
/usr/bin/rsync -a --exclude=logs --exclude=tmp $basedir $bakdir/$prename\_web
cd $bakdir
tar zcf $prename\_web.tar.gz $prename\_web
rm -r $prename\_web
/usr/bin/find $bakdir/ -mtime +2 |xargs rm -rf
fi
sleep 300
done
none