服務器上的源是 Debian 的,考慮到學校裡面已經沒有多少人使用 Debian,而使用 Ubuntu 來做推廣顯然更加合適,同學們遇到什麼問題,也可以得到更好的支持,於是決定把 Debian 源換成 Ubuntu 的。
建立源,當然要用 rsync ,不過這裡並非直接使用,而是用的 Debian 官網提供的一段腳本,叫做 anonftpsync,加上 cron 作為定時任務做成的。
cron 是 Linux 下的計劃任務工具,可以按每小時、每天、每星期、每月執行任務,支持多用戶多設置,很是方便。往下看之前,確認你安裝了 rsync,並且開啟了 cron 守護程序。
下面說一下步驟:
首先,建立源目錄。如果想放在 FTP 服務器上,應該建立在 FTP 目錄裡,比如:
mkdir /home/ftp/ubuntu
mkdir -p /home/ftp/ubuntu/project/trace/
#! /bin/sh -p
set -e
# EXCLUDE 是你要排除的文件和目錄。
EXCLUDE="--exclude *alpha.deb \
--exclude *alpha.udeb \
--exclude binary-alpha/ \
--exclude disks-alpha/ \
--exclude *-alpha.gz \
--exclude installer-alpha/ \
--exclude binary-arm/ \
--exclude *arm.deb \
--exclude *arm.udeb \
--exclude disks-arm/ \
--exclude *-arm.gz \
--exclude installer-arm/ \
--exclude binary-m68k/ \
--exclude *m68k.deb \
--exclude *m68k.udeb \
--exclude disks-m68k/ \
--exclude *-m68k.gz \
--exclude installer-m68k/ \
--exclude binary-hppa/ \
--exclude *hppa.deb \
--exclude *hppa.udeb \
--exclude disks-hppa/ \
--exclude *-hppa.gz \
--exclude installer-hppa/ \
--exclude binary-ia64/ \
--exclude *ia64.deb \
--exclude *ia64.udeb \
--exclude disks-ia64/ \
--exclude *-ia64.gz \
--exclude installer-ia64/ \
--exclude binary-mips/ \
--exclude *mips.deb \
--exclude *mips.udeb \
--exclude disks-mips/ \
--exclude *-mips.gz \
--exclude installer-mips/ \
--exclude binary-mipsel/ \
--exclude *mipsel.deb \
--exclude *mipsel.udeb \
--exclude disks-mipsel/ \
--exclude *-mipsel.gz \
--exclude installer-mipsel/ \
--exclude binary-s360/ \
--exclude *s360.deb \
--exclude *s360.udeb \
--exclude disks-s360/ \
--exclude *-s360.gz \
--exclude installer-s360/ \
--exclude binary-s390/ \
--exclude *s390.deb \
--exclude *s390.udeb \
--exclude disks-s390/ \
--exclude *-s390.gz \
--exclude installer-s390/ \
--exclude binary-sh/ \
--exclude *sh.deb \
--exclude *sh.udeb \
--exclude disks-sh/ \
--exclude *-sh.gz \
--exclude installer-sh/ \
--exclude binary-sparc/ \
--exclude *sparc.deb \
--exclude *sparc.udeb \
--exclude disks-sparc/ \
--exclude *-sparc.gz \
--exclude installer-sparc/ \
--exclude /Debian-1.3* \
--exclude /Debian3.1* \
--exclude local/ \
--exclude stable/ \
--exclude slink-proposed-updates/ \
--exclude slink/ \
--exclude bo/ \
--exclude bo-unstable/ \
--exclude bo-updates/ \
--exclude binary-hurd-i386/ \
--exclude *hurd-i386.deb \
--exclude *hurd-i386.udeb \
--exclude disks-hurd-i386/ \
--exclude *-hurd-i386.gz \
--exclude installer-hurd-i386/ \
--exclude binary-powerpc/ \
--exclude *powerpc.deb \
--exclude *powerpc.udeb \
--exclude disks-powerpc/ \
--exclude *-powerpc.gz \
--exclude installer-powerpc/ "
#--exclude /contrib/ --exclude /non-free/ --exclude source/\
# --exclude Incoming/ \
#######################################
# TO 是目標目錄
TO=/home/ftp/ubuntu
# 以下兩個合起來就是源地址: debian.ustc.edu.cn/ubuntu/
# 這裡設置同步的服務器域名
RSYNC_HOST=debian.ustc.edu.cn
# 這裡是同步服務器上源所在的目錄
RSYNC_DIR=ubuntu/
LOCK="${TO}/Archive-Update-in-Progress-`hostname -f`"
# Get in the right directory and set the umask to be group writable
#
cd $HOME
umask 002
# Check to see if another sync is in progress
if lockfile -! -l 43200 -r 0 "$LOCK"; then
echo `hostname` is unable to start rsync, lock file exists
exit 1
fi
trap "rm -f $LOCK > /dev/null 2>&1" exit
set +e
#result=1
#while (( $result != 0 )) ; do
rsync -rltv --progress --delete \
--exclude "Archive-Update-in-Progress-`hostname -f`" \
--exclude "project/trace/`hostname -f`" \
$EXCLUDE \
$RSYNC_HOST::$RSYNC_DIR $TO > ${HOME}/log/rsync.log 2>&1
#result=$?
#done
date -u > "${TO}/project/trace/`hostname -f`"
savelog ${HOME}/log/rsync.log > /dev/null 2>&1
chmod +x anonftpsync
chmod 755 /home/ftp/ubuntu
crontab -e
00 2 * * * /usr/local/bin/anonftpsync
crontab -l
/etc/init.d/cron restart
/etc/rc.d/crond restart
ftp://tofree.org/sources.list/
如果對 cron 不夠明白,可以參考:計劃任務工具 cron 的配置和說明
本文來自http://ivenvd.blogspot.com/2009/05/ubuntudebian.html