Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 88 lines (78 sloc) 2.133 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#!/bin/bash
# By Chen.Zhidong
# http://sillydong.com
# Email:njutczd+gmail.com

PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

PASSFILE="/path/to/rsync.pas"
LOCAL_WWW="/directory/path/"
TAG=$(date +%Y%m%d)
LOGDIR="/path/to/logs"
PIDFILE="./rsyncpid"

DAY_WEEK="5"
DAY_MONTH="26"

#Begin
readset(){
#readset keywork setfile
grep $1 $2 | grep -v "^#" | sed "s/$1=//"
}

www_rsync(){
#www_rsync setfile
www_dir=$LOCAL_WWW/`readset WWWNAME $1`
rsyncip="`readset RSYNCIP $1`"
rsyncname="`readset RSYNCNAME $1`"
rsyncextra="`readset RSYNCEXTRA $1`"

#echo $www_dir
#echo $rsyncip
#echo $rsyncname
#echo $rsyncextra
rsync -auHzSv --bwlimit=512 --delete --delete-excluded --ignore-errors --partial --password-file=$PASSFILE $www_dir rsync://rsyncback@${rsyncip}/${rsyncname}
}

echo "rsync start at $(date)" >> $LOGDIR/rsyncback_${TAG}.log

if [ -e $PIDFILE ];then
if [ "`cat $PIDFILE`" = "1" ];then
echo "rsync is still running" >> $LOGDIR/rsyncback_${TAG}.log
exit 0
fi
else
echo "1" > $PIDFILE
fi

if [ -e $LOGDIR/rsyncback_$(date +%Y%m%d --date="5 days ago").log ];then
rm -f $LOGDIR/rsyncback_$(date +%Y%m%d --date="5 days ago").log
fi

LIST=`find $LOCAL_WWW -maxdepth 2 -name tar.set`
for setfile in $LIST
do
echo -e "----\nusing $setfile" >> $LOGDIR/rsyncback_${TAG}.log
if [ "`readset DORSYNC $setfile`" = "true" ];then
frequency=`readset TARSET $setfile`
case $frequency in
daily)
www_rsync $setfile >> $LOGDIR/rsyncback_${TAG}.log
;;
weekly)
if [ $(date +%w) = $DAY_WEEK ];then
www_rsync $setfile >> $LOGDIR/rsyncback_${TAG}.log
else
echo "weekly skip $setfile" >> $LOGDIR/rsyncback_${TAG}.log
fi
;;
monthly)
if [ $(date +%d) = $DAY_MONTH ];then
www_rsync $setfile >> $LOGDIR/rsyncback_${TAG}.log
else
echo "monthly skip $setfile" >> $LOGDIR/rsyncback_${TAG}.log
fi
;;
*)
echo "wrong frequency setting" >> $LOGDIR/rsyncback_${TAG}.log
;;
esac
else
echo "skip" >> $LOGDIR/rsyncback_${TAG}.log
fi
done
rm -f $PIDFILE
echo -e "----\nrsync done at $(date)" >> $LOGDIR/rsyncback_${TAG}.log
exit 0
#End
Something went wrong with that request. Please try again.