出自http://li2z.cn,排骨写的,不错,收了~~~~o(∩_∩)o...哈哈,以后可以拿来参考一下 #!/bin/bash[[ $UID == 0 ]] || { echo "Must be root to run this script."; exit 0; }
LOCK="/data/sync_sh/lock"
LOG="/data/sync_sh/log"
while true; do
echo -e "/nstart sync @ `date`" | tee -a $LOG
if [ -f $LOCK ]; then
echo "another sync is running, I exiting..." | tee -a $LOG
exit 1
fi
touch $LOCK
st=`date +%s`
rsync --timeout=120 --exclude=".~tmp~" -avP --delete-excluded --progress rsync://archive.ubuntu.com/ubuntu/pool/ /data/mirrors/ubuntu/pool/
res=$?
if [ $res -eq 0 ]; then
echo "rsync pool succ" | tee -a $LOG
et=`date +%s`
echo "pool sync use $(( $et-$st )) sec = $(( ($et-$st)/60 )):$(( ($et-$st)%60 ))" | tee -a $LOG
else
echo "rsync pool failed" $res | tee -a $LOG
fi
st=`date +%s`
rsync --timeout=120 --exclude=".~tmp~" -avP --delete-excluded --progress rsync://archive.ubuntu.com/ubuntu/ /data/mirrors/ubuntu/
res=$?
if [ $res -eq 0 ]; then
echo "rsync all succ" | tee -a $LOG
et=`date +%s`
echo "all sync use $(( $et-$st )) sec = $(( ($et-$st)/60 )):$(( ($et-$st)%60 ))" | tee -a $LOG
else
echo "rsync all failed" $res | tee -a $LOG
fi
df | grep "/data" | tee -a $LOG
echo -e "end sync @ `date`" | tee -a $LOG
rm $LOCK
sleep 7200
done
这个脚本先更新pool目录,再整个目录更新一遍,这样是为了减少出现软件列表里已经有某软件,但是却下载不到的情况。
脚本常驻运行,每隔两个小时就更新一次,163的源要隔天才更新一次,lupaworld一天才更新4次,这个比较新,以后可以考虑用这个源。