Debian旧版本源同步脚本


Debian旧版本源同步脚本
 
Debian Lenny源被官方归档了,使得许多来不及更新系统的服务器没源可用,archive.debian.org访问速度太慢, 不得以自己写个脚本同步lenny源。
由于Debian源的结构,要单独分版本来同步很不方便,包都集中在/pool目录下,故此脚本主要根据索引文件来生成该版本的包列表
 
ARCH_EXCLUDE 用来过滤 不同架构的 包的
dists 用来过滤不同版本的
 
同步完成后,整个lenny源(i386,amd64,source) 共 50G
lenny archive源设置
 
deb http://mirrors.163.com/debian-archive/ lenny main contrib non-free
deb-src http://mirrors.163.com/debian-archive/ lenny main contrib non-free
同步脚本代码
 
#!/bin/sh
#author: igi
#date:   2012-03-28
 
TO="/tmp/debian"
FROM="archive.debian.org::debian-archive/debian"
#FROM="debian.ethz.ch::debian-archive/debian"
#FROM="mirror.1und1.de::debian-archive/debian"
#FROM="debian.koyanet.lv::debian-archive/debian"
RUNDIR="/tmp/"
 
ARCH_EXCLUDE="alpha arm armel armhf hppa hurd-i386 ia64 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc s390 s390x sparc"
for ARCH in $ARCH_EXCLUDE; do
    EXCLUDE=$EXCLUDE"\
        --exclude binary-$ARCH/ \
        --exclude *_$ARCH.deb \
        --exclude *_$ARCH.udeb \
        --exclude installer-$ARCH/ \
        --exclude Contents-$ARCH* "
done
 
#dists='lenny etch'
dists='lenny'
for dist in $dists; do
    DIST_INCLUDE=${DIST_INCLUDE}"\
        --include /dists/$dist/ \
        --include /dists/$dist/contrib/ \
        --include /dists/$dist/main/ \
        --include /dists/$dist/non-free/ "
    DIST_EXCLUDE="${DIST_EXCLUDE}\
        --exclude /dists/$dist/* "
done
 
#sync index files
rsync --progress -av \
    --include 'Packages.gz' \
    --include 'Sources.gz' \
    $DIST_INCLUDE \
    --include '/dists/' \
    --exclude '/*' \
    --exclude '/dists/*' \
    $DIST_EXCLUDE \
    --exclude 'i18n' \
    --exclude 'installer-amd64' \
    --exclude 'installer-i386' \
    --exclude 'Release' \
    --exclude '*.bz2' \
    $EXCLUDE \
    "$FROM/" "$TO/"
 
find "$TO/dists/" -name 'Packages.gz' -exec zgrep 'Filename: ' {} + | awk '{print $2}' >"$RUNDIR"/filelist
find "$TO/dists/" -name 'Sources.gz'  -exec zcat {} + | awk '/Directory:/{dir=$2;next};/Files:/{files=1;next}; files && /^ / {print dir"/"$NF};/^[^ ]/{files=0;next}' >>"$RUNDIR"/filelist
 
#first stage
rsync --progress -v --recursive --times --links --hard-links \
    --files-from="$RUNDIR"/filelist \
    "$FROM/" "$TO/"
 
#second stage
rsync --progress -v --recursive --times --links --hard-links \
    $DIST_INCLUDE \
    --exclude '/dists/*' \
    $EXCLUDE \
    --exclude '/pool/' \
    "$FROM/"  "$TO/"

相关内容

    暂无相关文章