Zsync

Differences between revisions 4 and 5
Revision 4 as of 2013-06-20 23:06:26
Size: 4181
Editor: static-108-13-137-26
Comment: Break long zsync command into 3 lines for readability
Revision 5 as of 2013-06-20 23:08:37
Size: 4186
Editor: static-108-13-137-26
Comment: Add .iso suffix to filename mask used in remove-daily-isos.sh as safety precaution.
Deletions are marked like this. Additions are marked like this.
Line 74: Line 74:
find "$ISODIR" -type f -name "$ISONAMEPREFIX" -mtime +$DAYSTOKEEP |head -n -$DAYSTOKEEP |xargs rm find "$ISODIR" -type f -name "$ISONAMEPREFIX*.iso" -mtime +$DAYSTOKEEP |head -n -$DAYSTOKEEP |xargs rm

Zsync

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.

Keeping A Few ISOs around

In practice the above basic approach, although workable, 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. 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 it do the work.

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 \
http://cdimage.ubuntu.com/lubuntu/daily-live/current/saucy-desktop-i386.iso.zsync

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

get-daily.sh

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, 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=lubuntu-saucy-desktop-i386" # First part of filename
DAYSTOKEEP=7 # How many days worth of ISO files to keep

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

Putting 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.

Testing/Activities/Classroom/Saucy/Zsync (last edited 2013-06-24 04:59:13 by pool-108-0-68-79)