Zsync is a tool to allow updating a changing ISO image file, such as the daily ISO images of Ubuntu produced during testing, without having to download the whole new file each time.

It works by tracking what has changed within the file and only downloading the changed parts, saving a lot of bandwidth (and time).

Basic Usage

Install the zsync package in the usual way:

sudo apt-get install zsync

Zsync uses files containing checkums of each small part of the file. For Ubuntu ISOs, these are found in the same place as the ISO files themselves, and end in .zsync . For example, look at the list of files at http://cdimage.ubuntu.com/lubuntu/daily-live/current/ and notice those ending in .zsync .

You can cut and paste the link to one of these files into a shell, as the parameter to the zsync command, for example

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

This will download a file called saucy-desktop-i386.iso and if you use that same command the next day, it will update that file to the new daily ISO image.

Checking the date of an ISO image

To find out which day's image a file on your machine saucy-desktop-i386.iso (for example) really is, you can use the isoinfo command in a small script called iso-date.sh, below. Save it on your $PATH and run chmod +x iso-date.sh so it is executable, and then

iso-date.sh saucy-desktop-i386.iso

will display the date of the MD5SUM.TXT file in that ISO image, for example you will see output like

Jun 17 2013

Here is the very short script:

# isodate.sh -- outputs date of MD5SUM.TXT file
#   within an ISO image file provided as $1

if [ -z "$1" ];
  echo "$0: Usage is $0 ISOfilename"
  exit 1

LANG=C isoinfo -l -i "$1" |grep MD5SUM.TXT | \
  sed -e 's/^[0-9 -]\+//g' -e 's/\[.*$//'

Keeping A Few ISOs around

In practice the above approach, although workable and a big advance on downloading the whole ISO image every single day (!), is not always what you would really like. It makes it hard to know exactly which days image the local file really is, and it does not keep any older versions, making it hard to go back a few days and try an older one to see if a problem is "new", or exactly when it was introduced -- information that can be very valuable to developers.

Therefore, it makes good sense, if you are doing ISO testing, to keep a few of these ISOs around, perhaps a week or two worth, and keep them named so it is clear which date each one is for to avoid confusion. You could do this by hand, but Linux is better at doing boring repetitive tasks reliably than most humans are... so it is better to let Linux do the work of maintaining the collection of images for you.

One suggested approach is to start with the simple command format described above to get the first daily image needed, and manually rename it to include both the flavour of Ubuntu (in the example above, Lubuntu) and the date, for example

mv saucy-desktop-i386.iso lubuntu-saucy-desktop-i386-$(date +%Y%m%d).iso

Then, you can run the a command like the following one, to use yesterday's image as a source of data when downloading today's image, and keep the image files named appropriately with dates in them in YYYYMMDD format:

zsync -i lubuntu-saucy-desktop-i386-$(date -d yesterday +%Y%m%d).iso \
-o lubuntu-saucy-desktop-i386-$(date +%Y%m%d).iso \

You can put this command in a file get-daily.sh and make it executable with chmod +x get-daily.sh and put it somewhere on your $PATH, perhaps in /usr/local/bin/ and then you can just type


each day to get that day's ISO image using zsync.

Deleting Old Unwanted Daily ISOs

The only remaining issue is that your collection of daily ISOs will grow forever, until you run out of disk space! To solve this, you need to decide where the collection of ISOs will be kept, such as /usr/local/isos/daily/ and then you can delete image files older than 14 days from that directory if there are more than 14 images in there.

# remove-old-daily-isos.sh

ISODIR=/usr/local/isos/daily # Where the ISO files are stored
ISONAMEPREFIX=${1:-lubuntu-saucy-desktop-i386} # First part of filename
DAYSTOKEEP=14 # How many days worth of ISO files to keep

[ -d "$ISODIR" ] || exit 1
find "$ISODIR" -type f -name "$ISONAMEPREFIX*.iso" -mtime +$DAYSTOKEEP |head -n -$DAYSTOKEEP |xargs rm

Putting a symbolic link to this script in /etc/cron.daily/ so it runs every night might be a good way to keep your collection of daily ISO files neat and tidy. You can also schedule get-daily.sh that way too, if your machine is always connected to the Internet, so your collection of daily ISOs is maintained fully automatically while you sleep!

Testing/Activities/Classroom/Saucy/Zsync (last edited 2013-06-24 04:59:13 by jmarsden)