OS X Lion Time Machine backup to Debian

When OS X Lion was released I was eager to try out the updated FileVault and Time Machine features. Moving from an encrypted home directory to true full-disk encryption was a dream. I was also quite excited to find out if the new implementation of FileVault would work well with Time Machine.

I’d previously set up a Time Machine volume on my Debian file-server by installing netatalk and avahi.

Unfortunately, it seems OS 10.7 (Lion) requires netatalk 2.2, which is currently in beta. However, it’s quite simple to install the beta version of the package and it seems to run just fine.

To install netatalk 2.2~beta4-1 you’ll need to add the following line to your /etc/apt/sources.list file:

deb http://debian.oregonstate.edu/debian sid main

You can also use any of the mirrors listed here if they’re closer.

Then run the following commands to install or upgrade netatalk:

$ sudo apt-get update
$ sudo apt-get install netatalk

If you had a previous install of netatalk it may detect changes to your local configuration files. By default the installer will keep the local copies of your files. This behavior is fine in this case.

After the install has finished run $ dpkg -s netatalk | grep -i version to ensure it was successful.

The netatalk service will be restarted by the installer after it completes. You may need to give it a few seconds to spin back up before trying to connect to it.

Your Time Machine backups in OS X Lion should now work correctly!

At this point you may want to comment out or remove the line you added to /etc/apt/sources.list so that you don’t inadvertently upgrade other packages to an unstable branch. After removing the line simply run $ sudo apt-get update one more time.

Update: Found the official Netatalk documentation.

Update 2: Here is the contents of both my afpd.conf and AppleVolumes.default files.

Update 3: Unfortunately, I can’t really provide support for any issues you might have with this. However, please keep your comments coming if you think they’ll be useful for other users attempting to get this working for themselves.

User Friendly Design: Attachment Icons

Last October I helped launch www.psylabstudios.com, an online store for my friend Lars so he can hawk merch for his band Oneiroid Psychosis. This was my first foray into ecommerce, one that went pretty smoothly all things considered. We couldn’t use SSL, so we ended up using the Google Checkout API. I wrote a custom shopping cart for the site using the Google Checkout PHP library…

Anyway, I’m rambling. Fast forward 9 months to today. Lars emails me and asks for a way to create free items that are available for download. Things like computer wallpapers, screensavers and so on. I decided that the best way to accomplish this would be to add an “attachment” feature to store products. This way Lars could attach an arbitrary number of files to any product in the store.

The attachment plugin was fairly straightforward, since this is only an administrative feature. But I wanted it to make sure that users were clear on what exactly it was they were downloading.

I was initially going to use PHP’s mime_content_type() function to identify uploaded files, but it simply didn’t work (good thing it’s deprecated). Then I was going to use the finfo_file() function, but was unable to install PECL extensions on this particular site’s hosting environment. If you’re lucky enough to be running PHP 5.3.0, then finfo_file() is installed by default. No such luck here though.

Finally I decided to use a simple regular expression to scrape the file extension (like .jpg or .doc) from the file name. This is not a recommended way to do this, as it’s completely unreliable, but it’s better than nothing.

  1. <?php
  2.   preg_match('/\.([\w]{2,4}?)$/i', $filename, $matches);
  3.   echo $ext = $matches[1];
  4. ?>

The above regex will return $matches[1], which should be a 2 to 4 digit file extension (without the period). Now, the magic can happen!

Since we have a fairly good guess of what the filetype is, we can now assign a CSS class to the download link that will display an appropriate file icon. As an example, a video file will get a video icon, an MP3 will get a music icon and an Excel file will get a Microsoft Excel icon (see gallery below for examples). I’m using the Fugue icon set for this site (I know I’ve been pushing those icons a lot lately, but I’m just in love with them).

Finally, we can use the filesize() function to get the size of the file and display it to the user. This way they know what they’re getting into before they click download (helpful if they’re on a slow connection).

This may seem like a lot of work, but it really isn’t. It also greatly contributes to the overall experience of your site visitors. Plus it’s a lot of fun to write shiny web-applications.


You can do this even easier using CSS selectors.

a[href$='.pdf'] {
  padding-left: 16px;
  background: url('icons/pdf.png') no-repeat left;

All this says is look for any anchor tag whose href value ends with “.pdf” and give it a background image. This is a super easy way to add context (and a little flair) for your site visitors.

Generating useful error pages with Pound

We use Pound as a reverse-proxy and loud-balancing frontend to our web cluster here in the office. Today we had some NAT problems with our proxy server and ended up with some server downtime. Pound defaults to outputting a cryptic error message when it can’t reach a valid host:

The service is not available. Please try again later.

This isn’t very helpful to clients who probably have no idea why their site is unreachable. After getting NAT back up and running, I decided to work on replacing this error with something a little more useful.

Pound lets you create error files that will be displayed if all the hosts are unreachable. Just add any of the following strings to the ListenHTTP section of your pound.cfg file (man pound for more info):

Err414 "filename"
    #A file with the text to be displayed if an Error 414 occurs. Default: "Request URI is too long.".
Err500 "filename"
    #A file with the text to be displayed if an Error 500 occurs. Default: "An internal server error occurred. Please try again later.".
Err501 "filename"
    #A file with the text to be displayed if an Error 501 occurs. Default: "This method may not be used.".
Err503 "filename"
    #A file with the text to be displayed if an Error 503 occurs. Default: "The service is not available. Please try again later.".

Pound appears to cache these error files, so you’ll need to restart pound for it to pick up any changes to the error files you specified.

Presenting visitors with a more informative error message will do wonders to ease the stress of any unexpected downtime. I highly recommend it.

Originally posted here.