#照葫芦画瓢,照着ubuntu同步脚本 写的
最近想同步arch的repo,发现rsync很不错,写了脚本记在这里,以后丢了可以再这里找到。
sync.sh
============
#!/bin/bash
[[ $UID == 0 ]] || { echo "Must be root run this script.";exit 0; }
LOCK="lock"
LOG="log.sync"
if [ -f $LOCK ]; then
echo "another sync is running ...,exiting !"
exit 1
fi
touch $LOCK
echo -e "/nStart sync @ `date `"|tee -a $LOG
echo -e "FROM rsync://mirror.rit.edu/archlinux/"|tee -a $LOG
echo "======================================"|tee -a $LOG
#================================================================
st=`date +%s`
rsync -avzP --delete --progress --exclude=".~tmp~" --delete-excluded rsync://mirror.rit.edu/archlinux/core/os/i686/ core/os/i686
ret=$?
if [ $ret -eq 0 ]; then
echo "Rsync core all succ"|tee -a $LOG
et=`date +%s`
echo "Sync core use $(( $et-$st )) sec = $(( ($et-$st)/60 )):$(( ($et-$st)%60 ))" | tee -a $LOG
else
echo "sync core failed " $ret |tee -a $LOG
fi
st=`date +%s`
rsync -avzP --delete --progress --exclude=".~tmp~" --delete-excluded rsync://mirror.rit.edu/archlinux/community/os/i686/ community/os/i686
ret=$?
if [ $ret -eq 0 ]; then
echo "Rsync community all succ"|tee -a $LOG
et=`date +%s`
echo "Sync community use $(( $et-$st )) sec = $(( ($et-$st)/60 )):$(( ($et-$st)%60 ))" | tee -a $LOG
else
echo "sync community failed " $ret |tee -a $LOG
fi
st=`date +%s`
rsync -avzP --delete --progress --exclude=".~tmp~" --delete-excluded rsync://mirror.rit.edu/archlinux/extra/os/i686/ extra/os/i686
ret=$?
if [ $ret -eq 0 ]; then
echo "Rsync extra all succ"|tee -a $LOG
et=`date +%s`
echo "Sync extra use $(( $et-$st )) sec = $(( ($et-$st)/60 )):$(( ($et-$st)%60 ))" | tee -a $LOG
echo "Sync OK .../n"|tee -a $LOG
else
echo "Sync extra Failed .../n" $ret |tee -a $LOG
fi
#================================================================
rm $LOCK