个人工具

UbuntuHelp:ZsyncCdImage

来自Ubuntu中文

Wikibot讨论 | 贡献2010年5月20日 (四) 01:05的版本 (以内容'{{From|https://help.ubuntu.com/community/ZsyncCdImage}} {{Languages|UbuntuHelp:ZsyncCdImage}} '''zsync''' is a wonderful piece of software that downloads only the parts of …'创建新页面)

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航, 搜索

zsync is a wonderful piece of software that downloads only the parts of a file that are changed, so as to avoid downloading a full copy everytime. A nice thing about the way the Ubuntu CDs are constructed is that it's quite easy to keep an up to date local install CD using zsync. Since the daily CDs generally change quite little, it can be processed quite quickly. zsync also perform a checksum comparison making it possible to change the flavour of the ISO (e.g. you have an ISO of Ubuntu and you want to change it on Kubuntu. Simply copy/paste the right line for Kubuntu and it'll download just the parts that differs from the two versions).

Installing zsync

Install zsync package.

Acquiring the ISO

All Ubuntu's CD images are stored on http://cdimage.ubuntu.com. It's best to use the torrent file if you can.

Updating the ISO

Ubuntu archives provide .zsync files using quite similar URIs about the various flavours. For example:

zsync http://cdimage.ubuntu.com/daily-live/current/lucid-desktop-i386.iso.zsync

will sync the server's daily Lucid desktop image (for i386) to your local system with an older desktop image already stored on your hard drive. Note 1: If you are using other flavours of Ubuntu don't forget to add the flavour's name in the rsync path after cdimage/, e.g.

zsync http://cdimage.ubuntu.com/kubuntu/daily-live/current/lucid-desktop-i386.iso.zsync

Note 2: If you are using another architecture don't forget to change i386 in the zsync path with the correct architecture name, e.g.

zsync http://cdimage.ubuntu.com/daily-live/current/lucid-desktop-amd64.iso.zsync

To zsync your images, you can also use the dl-ubuntu-test-iso script, which is part of the ubuntu-qa-tools package.

Updating with rsync instead

Another way to update your ISO is by using rsync. It's another implementation of the same algorithm that zsync uses, but it requires special software at the server end and it seems to be less efficient (require more data to be downloaded) for ISO images. https://launchpad.net/products/rsync is a good resource for more information. A number of the Ubuntu servers also work as rsync servers with quite similar URIs to the websites. For example:

rsync -zhhP rsync://cdimage.ubuntu.com/cdimage/daily-live/current/lucid-desktop-i386.iso .

will sync the server's daily Lucid desktop image (for i386) to your local system with an older desktop image already stored on your hard drive. -z is compression, -hh is human readable file size (in KB or MB), and -P is a progress indicator. If you have a local Ubuntu archive mirror or cache, you can also use Jigdo, rsync is handy for finishing up Jigdo downloads that still have a few missing pieces. Note: If you are using other flavours of Ubuntu don't forget to add the flavour's name in the rsync path after cdimage/, e.g.

rsync -zhhP rsync://cdimage.ubuntu.com/cdimage/kubuntu/daily-live/current/lucid-desktop-i386.iso .

A slightly more advanced script will automate much of the syncing process. To run this script successfully, you will need to set the DIR variable according to your needs. You can set ISO inside the script or simply pass it in on the command-line (to make it easier to sync multiple ISO images). In some cases you may need to manually set ISOPATH if you're downloading an image not automatically detected.

#!/bin/bash

#    Copyright 2010 Aaditya Bhatia http://www.dragonsblaze.com/
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    See GNU General Public License at <http://www.gnu.org/licenses/>.

# This script updates individual ISO image from cdimage.ubuntu.com via rsync
# Orginal script written by Henrik Omma, slightly adjusted by Bert Verhaeghe,
# then a bit by Victor Van Hee. 
# Jeremy Yoder made it try to automatically pick an ISOPATH,
# adapted to karmic by Christian Bangerter.
# And then Aaditya pimped it up a little (curl, stdout text, md5 logic)

# This is how you adjust the ISOPATH, in case you need to.
# ISOPATH="cdimage.ubuntu.com/cdimage/LOCATION/current"

# If a command line argument is present, use that as ISO name
if [ -n "$1" -a $(expr "$1" : '.*\.iso$') -gt 4 ]; then
 ISO=`basename $1`;
 cd `dirname $1`;
else
 echo -e "\nUsage:\n\t$(basename $0) UBUNTU-IMAGE-FILENAME.iso\n";
 exit 1;
fi

if [ "$ISOPATH" = "" ]; then
 if [[ "$ISO" =~ "-desktop-" ]]; then
 ISOPATH="cdimage.ubuntu.com/cdimage/daily-live/current"
 elif [[ "$ISO" =~ "-alternate-" ]]; then
 ISOPATH="cdimage.ubuntu.com/cdimage/daily/current"
 elif [[ "$ISO" =~ "-dvd-" ]]; then
 ISOPATH="cdimage.ubuntu.com/cdimage/dvd/current"
 elif [[ "$ISO" =~ "-netbook-remix-" ]]; then
 ISOPATH="cdimage.ubuntu.com/cdimage/ubuntu-netbook-remix/daily-live/current"
 elif [[ "$ISO" =~ "-server-" ]]; then
 ISOPATH="cdimage.ubuntu.com/cdimage/ubuntu-server/daily/current"
 else
 echo "Unrecognized distribution, set \$ISOPATH manually"
 exit 2;
 fi
fi

curl -sI "http://$ISOPATH/$ISO" | head -1 | grep 200 > /dev/null;

if [ $? -eq 0 ]; then
 echo "Location: rsync://$ISOPATH/$ISO";
else
 echo "Not Found: http://$ISOPATH/$ISO";
 exit 2;
fi;


echo -n "Fetching latest md5sum from the server... "
curl -s http://$ISOPATH/MD5SUMS | grep $ISO > $ISO.md5
echo "done"

echo -n "Comparing local and server MD5SUMs... "
md5sum --status -c $ISO.md5

if [ $? -eq 0 ]; then
 echo "match!"
 echo "Local copy is up to date."
 rm $ISO.md5;
 exit 0
else
 echo "mismatch!"
 echo "Performing rsync..."
 rsync -avzhhP rsync://$ISOPATH/$ISO .
fi

echo -n "Comparing local and server MD5SUMs one more time... "

md5sum --status -c $ISO.md5

if [ $? -eq 0 ]; then
 echo "match!"
 echo "Success!"
 rm $ISO.md5;
else
 echo "mismatch!"
 echo "FAILED!"
 rm $ISO.md5;
 exit 2;
fi

This script downloads MD5SUMs from the server, checks it against the local copy's MD5SUM. If they are not identical, it syncs the local ISO image to the most recent ISO image on the Ubuntu servers. Then it compares the new local MD5SUM against the server's copy again to check whether the sync process was successful diplaying the result.