Blog

How to run a script when a filesystem gets mounted on Linux

I wanted to run a script when a filesystem gets mounted on my Ubuntu server. I thought this would be a common task but it took me a while to find the answer. Some people suggested using udev, but udev responds to device changes. If you're trying to trigger something like a backup when you plug in a USB drive, udev is the way to go. But it's no use if your device is always connected but not always mounted.

When my server starts, /home isn't mounted automatically. /home's on an encrypted filesystem, and the system runs without a keyboard and monitor, so I want it to boot up normally without /home and I'll mount it the next time I login. When /home becomes available, it should start a media server and NFS sharing.

It's not well documented, but it's easy under Ubuntu. You need to use upstart and create an init script. These live in /etc/init/ and can have any name ending in .conf. You can either write your script directly in the init script, or call another script elsewhere. As I only had a couple of tasks to perform the behaviour's more obvious if it's in the init script. Here's what mine looks like:

# mounted-home - Trigger actions when home becomes available. 

description "Trigger actions when /home becomes available." 

start on mounted MOUNTPOINT=/home 

task 

script
    /etc/init.d/forked-daapd restart
    service nfs-kernel-server restart   
end script

You could also write a complementary script that stops these things when the home directory is unmounted, but I don't normally unmount my home dir and there's no harm in running this script repeatedly – the restart command will start it if it's stopped, or bounce it if it's already running.

A brief review of Catball Eats it All

Let me state my biases upfront. I love quirky, ridiculous games. I love great game music. And I love cats. Catball Eats It All ticks all of these boxes. Later I discovered it started as a Kickstarter project - icing on the indie cake.

Catball Eats It All is a pinball-platformer game for iOS. You are the Catball, and must roll & float through the level eating all the little bits of food before the timer runs out. Once you've got all the food, you eat the level itself. It's a simple concept, and the delight is in the execution: great artwork (from Nosego), great music (from Ben Thornewill/Jukebox the Ghost), and great sound effects. There's also a refreshing absence of freemium piffle. Overall, it's a charmer.

There are some flaws, however: the controls can be irritating and hard to master. In many ways, the controls are the game. It's sometimes fairly hard but that tends to flow from the controls rather than the game itself. It also made a poor first impression, downloading its level data when you run it for the first time (instead of when you install it), so you're out of luck if you try it out somewhere without internet. Fortunately, this was fixed in a recent update.

It's a bit of a slow burner, and I found myself playing it more for the music than the gameplay. But it's a lovely little game for 69p, and definitely worth your time - especially if you like Kometun, pinball, or cats.

Overall: 7/10. Recommended; Available from the iTunes store.

Lessons from my recent iPad debacle.

A series of unfortunate events left my iPad reset to its factory defaults and unable to restore from backup. All my data: gone. This was a horrid reminder of things that I knew but hadn't fully internalised. Please learn from my mistakes and absorb the following:

Don't forget your iTunes backup password. There's no going back if you tick the "encrypt my backups" option. You can't trash the old backups and make a new one with a known password. You can't recover the old password (unless it's really weak and you'll pay £80). Your iPad will still back up – but you can't restore without the password. If you forget your password and want a usable backup, you must blank your iPad and start from scratch.

iPad encryption is strong. Really strong. I think of the iPad as a consumer device and expected security to match – allowing new backups, and/or weak encryption. Nope: it uses AES256 for encryption, SHA-1 hashes for filenames¹, and random keys as part of each backup². All the encryption's handled on the iPad and no data leaves the iPad unencrypted³. Each file in the backup gets a different encryption key¹. You need the passcode to unlock the device, and checking this is done on the iPad itself.

Ubiquitous capture for passwords is vital. Use a password safe – a program that stores your passwords, so you can memorise 1 really strong password & use randomised passwords for everything – and make sure everything goes in there. No paper scraps. No "Oh, I'll remember this one." EVERYTHING. If you find a password you've written down, put it in the password safe as "unknown" before destroying it.

Password reuse can be a good thing. Why the fuck didn't I use my Apple ID password? Or the unlock code for the iPad? Or my encrypted HD password? Or my encrypted PC backup password? Because I'm a fucking idiot, that's why.

If you don't have more than one copy of your data, you don't have it. My password safe was on my iPad. I would have been stuck even if I'd stored it in there. You need multiple copies of your data, in multiple locations, and not tied to any one device.

¹ iPhone Data Protection in-depth, slide 48.
² iPhone Data Protection in-depth, slide 52.
³ Data Decryption & Password Recovery, slide 25.
Evolution of iOS Protection and iPhone Forensics: from iPhone OS to iOS 5, slides 29-30.

Anthropomorphism

A headless teddy bear.

This evening I was going through some old boxes and I found this teddybear. He has a NatWest ribbon on – he's clearly a promotional item, and not a much-loved childhood friend. Somehow he’d been decapitated while in storage. What am I supposed to do with a headless teddy?

I’m supposed to throw him away, of course. But I don’t think I can. His big black eyes are pleading with me to love him.

I think I have issues with anthropomorphism.

Lightning Shoots in Abandoned Buildings

On Sunday I noticed an abandoned building with an easy way in. On Monday I emailed a friend and asked her if she'd like to come with me as a model. On Tuesday we did the photos. I love it when a plan comes together.

  1. The Setting
  2. The Model
  3. The Point
  4. The Shoot
  5. The Post-processing
  6. The Lessons
  7. The Results

The Setting

Abandoned buildings are fun and scary. I spotted one with easy access from a bus ride, and thought it could make a good setting. A friend suggested that as sets go they've been done to death. I suppose they have - even I've used one before - but I wasn't looking to create something groundbreaking, just something interesting to me. "This is my photograph. There are many others like it but this one is mine," and all that.

There are some risks with abandoned buildings. They are dirty and possibly structurally unsound so you need to keep your wits about you. You never know if you're going to find squatters or other people in there. You're trespassing, which in the UK is a civil offence (ie. you're risking court, not an arrest). I am not a lawyer, or even an experienced trespasser, but I expect that if you're not causing any damage then if you do meet a security guard they'll ask you to leave, nothing more. I am paranoid so I left anything identifying in my wallet at home anyway.

When in the building itself, keep an eye out for broken glass, used needles, excrement, etc. Bring a torch even if it's a sunny day outside. Look for signs of human habitation - bedding, fresh rubbish, etc. If you do meet someone chances are they'll be friendly (or at least leave you alone), certainly if you explain that you're just looking around - but on the other hand you've probably got some expensive equipment with you. If you're going with someone else (which is a damn good idea) then take care of them too, especially if they're a model - tell them in advance so they can bring some rugged footwear and clothes. You may be fine in jeans and boots but if they're in ballet pumps and a floaty dress they might not be so lucky. Don't take unnecessary risks, and try to think before you move (especially if you're on an upper floor or looking at stairs). With wooden floors be aware of damp and flexing surfaces; with metal be aware of rust; with concrete be aware of cracked or broken surfaces. If you're going up stairs try to stay as close to the point of support as you can (generally close to the wall).

The Model

I don't have any go-to models in London at the moment so I asked a friend of mine, Lara, who seemed like she'd have the temperament for prancing around in front of a camera. I met Lara at jitsu lessons, and I figured that if we both knew some jitsu we stood a fighting chance against zombies, vampires, and anyone else unsavoury we encountered inside the building. (Lara's better than I am.) As usual I got her to sign a standard model release, and told her about the setting and the point of the shoot.

The Point

I wanted to try out some of the small-strobe lighting techniques recommended by Strobist. I was also interested to see how my cheap eBay flash held up. I was planning to borrow another, more powerful speedlite from a friend, but alas that didn't work out. I carried everything by bike - camera, tripod, light stand, umbrella. The umbrella got ball-bungeed to the stand, and the stand got ball-bungeed to the bike. It made riding ungainly, but not unbearably so. That said, I'd have been out of luck if I wanted two stands and I wouldn't make a habit of going by bike. I've decided the best accessory a photographer can have is an assistant. An assistant with a car.

We only had an evening after work to do it; I wanted to get in quickly before the hole was boarded up, so didn't want to wait until the weekend. We'd also be fighting fading ambient light in what was likely to be a fairly dingy setting anyway. With two lights this wouldn't be a problem as you can light both the subject and the background, but with just one low-powered strobe it was likely to be limiting. I brought a tripod along so I could use long exposures and a couple of lenses that open up to f/2 and f/1.8. The only mental image I had in my mind going in was of a pristine secretary in the ruined building, so I asked Lara to bring some office clothes with her.

On the whole, this was very much a "Wander around an abandoned building while taking some photos" rather than "A photoshoot that happens to be in an abandoned building."

The Shoot

We met a little later than planned, around 19:40. We walked to the building and went inside. It was a bit of a wreck. We looked on the first floor and found used needles, razor blades, and a condom wrapper. We tried the next floor up, which had less drug paraphernalia but more turds and rubbish. There was detritus everywhere. We decided to go down to the first floor instead of scouting further as the light was fading. I got Lara to change into her secretarial garb and grabbed some available light portraits. Even at this late stage I had to shoot at a high ISO rating, and pushed my luck too much with slow shutter speeds. I tried grabbing some wide-angle shots to try and get a broad view of the broken office with Lara in the centre, but these were prosaic due to boring lighting. Slightly better were the attempts to use a broken window as a framing device. I stuck a diffuser on the flash and placed it to camera left, bouncing it off the ceiling.

After that there was a quick outfit change to the green silk top, and a lighting change too. The light was coming from one silvered umbrella, wherein I valiantly attempted to avoid reflections in the windows behind Lara. I tried to get a nice exposure of the world outside to provide a little interest in the background. We did some against the pillar , and some standing in the open without the shirt, but again they turned out flat and lifeless. I could have made this better by asking Lara to do something more interesting than stand there.

We were rapidly losing the light and starting to freak out about when the occupants would return, so we packed up and left for the outside world. We did some more pictures outside which were my favourite images of the shoot. I slapped a couple of CTO gels onto the flash to bring the flash closer to the sodium streetlights, stuck a cereal-box snoot on it, and stuck it high up to camera left. I tried using a longer shutter speed than normal to get a blurry background and a little light trail while using the flash to freeze Lara. I used a similar setup for the doorway pictures, but the snooted light was closer this time and the ratio between the flash and ambient was lower.

It was starting to get late so we retired to a nearby coffee shop and had a couple of warm drinks (camomile tea for me, hot chocolate with marshmallows for her) and had a look at the pictures. Then we said our goodbyes and went our separate ways.

The Post-processing

Lara is basically stunning, so I didn't have to do anything cosmetic. Everything was compensating for my own mistakes; I cropped down a bit more and tightened up the composition, cloned out some distracting spots and reflections from my light, and tweaked the colour balance to make the lighting a little less orange. I converted a couple of images to black and white, because the colour wasn't adding anything to the image and (in one case) because heavily-grainy images work better in black and white than in colour. I'm still not entirely happy with that one. I also lightened a shadow on Lara's face in one shot to stop it from being too distracting.

I ended up doing more processing than I like on these. Generally I'm a fan of Ansel Adams' idea of previsualising and getting things right in-camera, but I'm not going to beat myself up too heavily over these as it was dark and hard to see what's in the viewfinder (as well as the first shoot I've done for a long time).

The Lessons

  1. I don't care how dark it is, ISO 1600 is only for once-in-a-lifetime things like sporting events and assassinations. Break out the tripod instead or open up as wide as you can go and live with no depth-of-field. If you're shooting wide-angle it's not going to be too bad anyway.
  2. Some abandoned buildings are horrific. Pick ones far away from cities and transport hubs, they're less likely to be drug dens and flop houses.
  3. If you're having trouble with composing in the viewfinder, be sure to pay attention to it on the LCD. Don't just concentrate on the exposure.
  4. The best accessory a photographer can have is an assistant. An assistant with a car.
  5. The second-best accessory is a reflector. (This would have made my one-light setup more flexible and allowed me to provide some fill light).
  6. Asking the model to do something silly often results in a more interesting image.

The Results

These are in a gallery on Ethicsgirls.

Linux Music Players Suck

As some of us already know, all software sucks. But Linux music players seem to suck more than most. I mentioned to a colleague that I was still using the original XMMS to listen to music, and his horror (combined with some niggling little issues) caused me to explore the alternatives to this old, outdated, unmaintained bit of software. It turns out the alternatives suck.

What I want

Some things are absolutely non-negotiable features:

  • Must be able to scrobble (ie. submit music to Last.fm).
  • Must be able to deal with large collections of music (18,000 tracks or thereabouts).
  • Must support UTF-8, for artists with non-ASCII names.

Some things are mere nice-to-haves, varying from "This is standard stuff and I'll be rather annoyed if you don't have it" to "Mere frivolity":

  • Support for embedded artwork. Lots of players are quite keen to fetch artwork from Amazon; I don't necessarily want artwork in my music player, but if you're going to display it at least use the details in the files.
  • Support for watching directories for new files - a kind of auto-playlist-management thing. This ties in with the above requirement of 'not melting when dealing with large collections' - it's no good watching my nominated directories if you're going to rape my CPU every 5 minutes to check for new files.
  • Persistent queues. I generally listen to my entire collection on shuffle, and just queue up albums and tracks I particularly want to hear as and when. Sometimes the queue gets quite long; it should be saved and restored if the music player is quit and re-run.
  • A Winamp 2-style interface. I've never been seduced by the "your media player should look sexy" arguments, but I like the winamp interface because it lets me have the player always on my screen without taking up lots of space (see the top of this screenshot).

What I currently use: XMMS 1

I have been using XMMS for many years now. It has some niggles in it, but mostly it's OK. But, like everything else here, it sucks:

  • Not-quite-there support for UTF-8: some names show OK, others don't. Fortunately it still scrobbles these tracks OK, so I can live with it displaying weirdly in the playlist.
  • No concept of a library, so whenever I buy another CD or download a new track I have to add it to the playlist by hand, or put up with duplicates. Generally I never bother - instead, I periodically clear the entire playlist and re-add the directories where I keep my music.
  • No persistent playqueue. This was the one that made me start to look for a replacement.
  • Not currently maintained. Which is fine, really, as it works fine and doesn't crash. But none of these niggles are ever going to be fixed.

Despite these I've stuck with it at home; it's the only player I've found that takes the 18,000 tracks in my collection in its stride. Changing between tracks is quick, searching and scrolling the list is fast. I can go without the tree-view browsers in other players if they're going to be dog-slow to use.

First attempt at something else: Rhythmbox

Rhythmbox is surprisingly good. But, despite this, it sucks:

  • It does support a library management system, but I can only tell it to watch a single folder! I don't have all my music below a single directory.
  • The library-watcher goes absolutely nuts whenever I add new music to the collection, taking many minutes at 100% CPU to find the 10 new files I've added. It periodically does a similar thing just to find out if I have added something or not.
  • No embedded artwork support.
  • No persistent queues.
  • A disturbing habit of crashing X when I quit it on my work computer. It doesn't do this at home, but I still do not approve. Having everything I'm currently working on disappear is not pleasant.

It gets an honourable mention for working out of the box and having a mostly non-broken artist/album/track browser.

Amarok

Turns out I work with someone who used to be a core developer on Amarok, and I read on his blog how unremittingly awesome it was. I trusted him, and I believed the hype. So I installed it and gave it a spin. Unfortunately it made me viscerally angry on my first attempt at using it. It has a startup wizard that wanted me to set it up a database before I could use it. Once I'd got over the shock of a music player insisting on an SQL backend I told it where my music could be found. It then spent 20 minutes indexing my music, in silence, as it told me to 'please wait'. I've since been told that I could have played stuff direct from the filesystem in that time, but there was nothing on the screen to indicate this. Then when it had finally done this I tried to play some music. It played me the introduction clip from the developers, then gave me an error message telling me it couldn't actually play MP3s after all. This was the final straw; having waited patiently for it to do its thing only to be told that the music player couldn't actually play any music drove me over the edge and I quit in disgust.

But I am a sucker. People kept telling me that I was just unlucky and it was actually very good. So I gave it another spin. Here's why it sucks:

  • It doesn't use quite as much of the CPU when scanning for new files in the library, but it's still noticeable when it does it, and it's not exactly nimble.
  • Laggy when changing tracks and displaying information about what's currently playing.
  • I don't think its queue persists, but I'm not sure.
  • The user interface feels 'big'. It uses a lot of space to display little information. It's also somewhat 'modal' - there's information displayed when the player is stopped that isn't there when it's playing. For instance, it's actually got quite a neat little "recently added" display that shows you stuff new to your library - but you can't get at this when the player's playing. You must stop it first if you want to listen to something new (or find it manually).
  • Library browsing is slow, even though it's got a Postgres database as its backend.
  • Prediction/exploration functions are probably only any good when you've listened to several thousand tracks (I think it's trying to recommend tracks I listen to for playing next); as it is, it just feels cluttered and useless.
  • I think it considers a track played as soon as any of it has been played; skipping it doesn't count as a non-play. If this isn't a case then the user interface needs to be brushed up.

If you're looking for something that's going to insist you explore your music and have the time to devote to letting it build up a decent body of stats to use, Amarok may be worth a look. Personally, I'd give it a miss. Sorry Max.

Audacious

Audacious is either the first or second rewrite of the original XMMS codebase; it's one of those projects that's been forked and forked again. It is, on face value, a maintained version of XMMS. It's got scrobbling support, the Winamp interface I like, and also supports UTF-8. In fact, it's almost good enough to replace XMMS. But, like the others mentioned here, it sucks:

  • No persistent playqueue.
  • No automatic library management.
  • Really slow when dealing with big playlists; scrolling through the list is not possible due to the lag. Displaying the next page takes around 10 seconds on a playlist of 18,000 tracks. It might be quicker when all the metadata has been loaded in already, but it'd have to re-do it whenever I re-loaded the playlist. XMMS displays the filenames of files and redraws them once it's loaded the metadata; it seems Audacious waits to load the data for all the files and then redraws the screen.
  • At least one of the main developers is a jerk. This isn't a big thing for most people, but I was willing to fix the first item, and could probably have a stab at the second two. But having chatted on the IRC channel for a bit I can't face it. The devs apparently want to take Audacious in a different direction, and dealing with such a... forceful personality would not be fun. My motivation to contribute has gone.

As it happens I have switched to Audacious at work - I have a small enough MP3 collection at work that any lag is not enough to annoy me, and the improved UTF-8 support is worth any slowdown.

XMMS2

I haven't actually tried this, but this is why I think it sucks anyway:

  • A client-server model for a music player? You've got to be kidding me. I can see why it would be useful in some cases, but I'm not building a jukebox or placing client units throughout my flat. I just want to listen to music on my computer. Client-server is overkill. I could forgive this, but...
  • All the clients look like 'my first GUI app'. They are pretty much all huge and/or horrible. The few clients that I looked at and thought "I could use this every single day" are either abandoned or missing key functionality. When they say it's not ready for public usage yet, they're not kidding.

Exaile

Apparently some people look at software projects like Amarok and think "Hey, that's neat. Let's rewrite it in Python.". Rhythmbox decided they wanted Amarok in GTK rather than QT, and it's ended up a little different, so maybe the same thing will happen with Exaile. It's a bit more minimal (which is a good thing), but it still sucks:

  • No embedded artwork support.
  • Smart playlists aren't automatically updated - if you have a playlist open on a tab and that playlist gets new tracks added to it, the open tab does not gain them. You must close it and re-open.
  • There's a lag on changing tracks. There's a lag whenever you try and do just about anything, in fact - 3-5 seconds after adding something to your playlist and around 10 seconds when you change the tree browser from 'artist' to 'album' or similar. Naturally there's a lag and a whole load of CPU usage when the library updates itself.
  • I don't think I can close the main window and have it run just in the tray.

It does, however, have persistent playqueues. It would be better if it had more info to begin with (see below).

General Reflections

It would be really useful if there was some source that could give a music player details about everything you've ever listened to; Last.fm would be the obvious source but there's (currently) no feed for your own scrobbles, and you can't get your entire scrobbling history from Last.fm. This is a shame; I have a hunch that Amarok's features would be much better if you could 'prime the pump' with this data; likewise for Exaile's smart playlists.

Before emailing me madly to tell me how wrong I am, please understand I'm not impugning you personally for your choices; if these players work for you, great. Unfortunately, they don't entirely work for me.

.

HOWTO: Automated, encrypted, incremental backups on Linux

I recently decided that I was going to get one small corner of my computing life in order. Yes, my home directory was a mess. Yes, I had way too much stuff sitting around unorganised. Yes, I had about 3 previous generations of hard disk sitting in /usr/disk because I hadn't been bothered to suit through the bits I need and delete the stuff I didn't. I mean, hey - I might really need my NVidia drivers from 5 years ago one day, you know?

Anyway, I decided that I was going to stop living on the edge and get an automatic nightly backup. My previous backup strategy was "Burn stuff to DVD when I remember". I could just about fit all my documents, mail, source code, and other stuff onto one DVD. But my music wasn't backed up (though not such a big deal, as it was on my iPod and I've got the original CDs) and my photos were not fantastically well backed up. This was the clincher: I'd recently bought two 4 gigabyte CompactFlash cards for use with my camera. The upshot of this was that I often had shoots that were > 4Gb - often as much as 8Gb. That won't all fit on one DVD so backing them up was a pain. Finally, backing up to DVD was something I only did once every month or so and DVDs aren't all that permanent anyway. It would be just my luck to suffer a hard disk crash and then find all my backups are unreadable.

Here's what I needed from the new system:

  • Automatic - I shouldn't have to do anything. If it relies on my involvement it will never get done.
  • Secure - Not a massive concern in the real world, but it adds to the psychological feeling of security. I want to know that if someone nicks my backup it's useless to them - they don't get all my cached passwords, financial records, and naked pictures of my girlfriend.
  • Incremental - More of a nice-to-have than a requirement, an incremental backup lets you go back to earlier snapshots if you want to. Rather than taking full backups every day (which would require huge amounts of space) you just store the bits that have changed, although it looks to the system like each one is a full backup.

Step 1: Assumptions and Requirements

I run Debian Linux on my PC so this is written from that perspective, but this should work fine on just about any Linux machine.

In hardware terms you just need a spare hard disk. I got a 500GB External HD which I'm using via USB. The drive needs to be slightly bigger than the data you're backing up. I have 400Gb of data drives in my machine, so 500Gb is ample. Personally I chose to back up the entire system, though some people consider that overkill and just back up /home (where all your documents and personal settings are stored). I also like to have a backup of /etc for my system settings, /root for root's home directory (I have a couple of sysadminny scripts in there, some environment settings, etc), and I've also got a /data partition which is where all my photos end up. So backing up just /home wasn't for me. Rather than figure out what bits I wanted to back up and which bits I could ignore, I just backed everything up.

In software terms you need rsync and LUKS:

apt-get install rsync cryptsetup

Step 2: Encrypt and mount the disk

I found this article useful when trying to figure this out the first time around.

  1. Your first step is to figure out where your disk is. If it's an IDE drive you'll find the device on /dev/hdb or similar, and the partition on /dev/hdb1. If you need to partition the drive then try using cfdisk (my favourite, although not always available) or fdisk.

    My drive's USB, which means it lives on /dev/sda1, but it's better to use one of the links in /dev/disk/. These are automatically created symlinks to devices so you don't have to worry about what order you plug stuff in. This doesn't really matter - we're only going to be referring to the device once - but it's good to know.

    Be very careful when choosing your device, as we're about to torch all the information on it. Set it up as an encrypted LUKS container like this:

    cryptsetup luksFormat /dev/disk/by-label/My_Book

    It'll ask you if you're sure you want to destroy the data on this drive, then prompt you for a passphrase. Try and pick a good one.

  2. Now we open our newly encrypted device and make a filesystem on it. The first command creates a mapped device on /dev/mapper/ and the second sets up a filesystem - I've gone with Ext3, but you can pick your favourite.

    cryptsetup luksOpen /dev/disk/by-label/My_Book crypto_backup
    mkfs.ext3 /dev/mapper/crypto_backup
  3. That's it - you've now got an encrypted drive ready to roll.

    mkdir /mnt/backup
    mount /dev/mapper/crypto_backup /mnt/backup

NB. If you have one of these Western Digital drives, you may find that they don't let you mount them by label after you've encrypted them. Use /dev/disk/by-id instead if this is an issue for you.

Step 3: Set up the backup

I found this article to be a very thorough explanation of backing stuff up using rsync. It may be useful if you want the mucky details.

  1. Perform the initial backup (this is all on one line):

    rsync -av --exclude=/media --exclude=/media --exclude=/mnt / /mnt/backup/backup.0

    The -av puts rsync into archive mode (which makes it mirror things like file permissions, copying symlinks as symlinks, etc), and makes it verbose so it tells you what's going on. The excludes keep it from trying to back up itself, my Ipod if I leave it plugged in overnight, or any CDs I have in the drive. The final two arguments are the source and destination - in this case the filesystem root / and the backup.0 folder in /mnt/backup. That's it - you're all backed up.

  2. Let's create the backup script that performs the incremental backups. Create this, change the BACKUP_ROOT and BACKUP_SOURCE lines to suit and stick it somewhere safe - /root/bin/backupscript for instance:

    #!/bin/bash
    BACKUP_ROOT=/mnt/backup
    BACKUP_SOURCE=/

    rm -rf $BACKUP_ROOT/backup.3
    mv $BACKUP_ROOT/backup.2 $BACKUP_ROOT/backup.3
    mv $BACKUP_ROOT/backup.1 $BACKUP_ROOT/backup.2
    mv $BACKUP_ROOT/backup.0 $BACKUP_ROOT/backup.1
    # This next bit should all be on one line!
    rsync -ua --delete --exclude=/media --exclude=/mnt --link-dest=$BACKUP_ROOT/backup.1 $BACKUP_SOURCE $BACKUP_ROOT/backup.0

    First of all this removes the oldest backup (4 days ago). Then it ages all the backups by one, before backing up the system. After it's run you'll find you've got 4 days worth of backups, but it only takes up a bit more space than one backup. How does that work?

    The magic is in the --link-dest parameter. To explain this I'll have to get a bit abstract, so bear with me. When you see a list of files in a directory, you're not actually seeing the files - you're seeing a bunch of links to certain areas of a disk. You can have more than one link to the same area of disk, and it'll look to your computer like you've got the same file in several places - but really the file's only stored once on the disk itself. When you remove the file you're actually removing a link, and it's only when there's no links left that the computer will use the space for something else.

    By way of analogy consider addresses for houses. You could post stuff to "42 Prudence Avenue, The Village" and it'll arrive at your house - but you could also post stuff to "The Old Windmill, The Village" or "White Cottage, Prudence Avenue, The Village" and it will all arrive. This doesn't mean you've got three houses, it's just three different ways of pointing to them. And it's only when all of them are removed from the council's list of ratepayers that they come and repossess your house.

    Returning to the topic at hand: the --link-dest argument performs a little magic and makes links to files in the given directory if the file hasn't changed. So it looks like you've got 4 copies of a file - one in each day's backup - but really it's only stored once.

Step 4: Automate it

  1. First up you need to edit root's crontab so that the backup runs nightly. su to root then run crontab -e and add the following line:

    # m h dom mon dow command
    0 3 * * * /root/bin/backupscript

    This tells cron to run your backupscript every day at 3AM. Make sure your backup script is executable! chmod +x /root/bin/backupscript

  2. Now we need to make sure that the encrypted container is mapped at boot, and mounted automatically for us. Add a line to /etc/crypttab so it looks something like this:

    # <target name> <source device> <key file> <options>
    crypto_backup /dev/disk/by-id/usb-WD_5000AAJS_Externa_123-part1 none luks

    This tells the system that the /dev/disk/by-id/usb-WDetc device should be mapped to /dev/mapper/crypto_backup on startup as a LUKS container. As no key file is specified it will prompt for a password on bootup.

  3. Now we've told the system how to map the device we can just add it to /etc/fstab like anything else:

    # <file system> <mount point> <type> <options> <dump> <pass>
    /dev/mapper/crypto_backup /mnt/backup ext3 defaults 0 2

Limitations

  • If you're using this to backup a database (eg. MySQL) you are entering a world of pain. MySQL generally stores its databases in a whole bunch of files. To take a snapshot of a database from the filesystem you'd have to stop the database entirely, copy all the files, then start it again - and that's not a supported way of doing things. Otherwise you're just crossing your fingers that nothing changes the database while you're trying to back it up (either a user of the database like a website or a program, or MySQL itself deciding now's a good time to reindex or whatever). Rsync will make sure that your files are not changed during the backup, but it doesn't do it for an entire directory. You're better scheduling a regular backup using mysql_dump or similar to somewhere on your hard disk, and letting those backups get copied by rsync instead.
  • You are not totally safe. If this is your home computer this is a backup regime that you are justified in feeling smug about. If you're an investment bank or a medical facility you should be panicking. What if there's a fire? A flood? An explosion? What happens if your backup is scheduled at 3AM but your hard disk dies at 2:55? A home user can cope with this level of risk, but anyone whose data really truly matters (ie. people will lose lots of money/limbs if data is lost) should have a proper disaster recovery plan, offsite backups, replication, etc.
  • You're trusting people not to destroy your backups. Generally the setup above will let anyone read or write the backups on the system if they have permissions to do so. Instead of setting the mountpoint to 755, you may want to run chmod 700 /mnt/backup. This means that only root can read or write the backup - but this may not be convenient. There is a solution but I decided it was overkill for my needs - I'm the only one using my PC and I trust myself not to destroy it all.
  • This is not a versioning system. The snapshots let you go back a short way in time but think of this as a convenience thing ("Oh no! I really didn't want to delete that document two days ago!") rather than as a way of applying versioning. Use Subversion or CVS for this instead.

Smokers

I didn't mean to have a go at smokers. I mean, it's easy these days, isn't it? They're getting marginalised by the law, by public opinion, and their lungs aren't too happy with them either. They're easy prey and I didn't want to be that obvious.

That said this was always going to read as an anti-smoker rant. If you're going to give someone a kicking you might as well use the hob nailed boots.


I tell you, the sooner we ban smokers the better. Those of a pedantic bent might suggest we ban smoking rather than smokers but I'm taking the hard line here. Frankly I am less concerned about the risks of second-hand smoke and the burden on the health service than I am about the mindless inconsiderate nature of some of the people who smoke.

But perhaps it's not their fault. Maybe they're not inconsiderate - they may just be retarded. You've got to be a few IQ points below par to willingly suck down that chemical-laden, tar-ridden smoke many times a day. When their own filthy habits start intruding into my life it may not be because they don't care, it's because they don't realise. Smoking clogs the arteries and the lungs - the reduction of blood flow to the brain is manifesting itself, that's all.

I have recently started working in central London. The thought process behind moving to our capital was nothing more complicated than "I have no idea what I want to do. I may as well move to London where there's plenty of stuff going on to keep me distracted." City life pulls me in two directions - I enjoy the sheer quantity of diversions and 24 hour services but I also miss the lush, verdant outdoors. Another pertinent side of me is that I treasure my lunch hours. I will take a full hour to sit down, eat, do the crossword, and read the paper. It is one of the anchor points of my day - possibly the only one. These seemingly unrelated factors combine to give me my lunchtime pursuit - sitting in one of London's many parks and eating.

Many other people have the same idea. On overcast days the parks are speckled with people, but when it's busy the places are rammed. That's OK - other people are allowed to like the outdoors as well. We can all sit in the park together and enjoy the trees and the grass, the slightly fresher air, and pretend for a brief slice of time that we're not surrounded by pollution and filth.

Only we can't pretend that, can we? The grass is covered in cigarette butts. London's cleaners do a sterling job keeping the pavement detritus at bay, but you can't brush grass clean. Even if we ignore your discarded dog-ends and settle on the grass we are faced with a larger problem. You see, there is a reason there are butts everywhere. There are smokers in the park too.

Like the lumberjack who works outside because he loves the outdoors, the smokers in the park think nothing of sparking up when they are a few short feet from you. They'll sit there happily puffing away while we try to eat our lunch. I came outside to enjoy what little fresh air I can find, not have it removed by some blonde bint in advertising who talks loudly about when she should text the man she danced with last weekend. This also puts me off my lunch but, admittedly, it may not be relevant.

I'm not bothered about the health issues. I'm not entirely convinced about banning smoking in pubs - it seems a mite hypocritical to protect someone's lungs while encouraging them to poison their livers. You go to a bar, you expect the smoke. The stinking hair and clothes along with the dry throat are the cost you pay for socialising in such locations. I don't expect that from my lunch break.

And how about the degenerate swines who smoke while walking along the street? Double points for having a mobile phone clamped to your ear and the cigarette in that hand so it's not even like you're feeding your nicotine habit. As you walk along and belch out clouds of smoke the poor sods behind you get it in the face every single time. You may think you're clever but one day I'm going to have your ankles. Then we'll see who's the smart one.

Australia has a campaign about cigarette butts. It's based around the slogans "Bin yer butts" and "Don't be a tosser". We need more of that type of wordplay in this country. Quality puns and insults for transgressors. The closest we come to this right now is the pleasure of telling people without seatbelts to belt up.

I don't think there's a solution beyond ghettoising smokers even further. Don't send them outside, where they congregate around doorways like mini smokestacks in their own cliquey industrial revolutions. Stick them in a sealed room in the basement with an air vent. No matter how good the filter is the air will be stale and the walls will yellow and peel. Better yet, put them in a vacuum. They're used to breathing problems and (thanks to the fire triangle) they won't be able to light up at all.

I went to an Aussie Rules match once

I saw Adelaide vs. Port Adelaide at the AFL semi-final last year. It was a bit of a last-minute thing. This weird German girl came up to me on the street, and asked if I was busy that night, as she had a spare ticket. "Try something new!" I thought. I don't get asked out on the street that often and one of the things I'd been trying on my jaunt around Australia was to do new things, things I don't do at home like go to sports matches with people off the street.

God, I wish I'd listened to my inner voice and run for the hills.

So, Crazy German Chick goes home to change and we agree to meet later. We meet, and warning sign #2 (#1 was her asking people on the street to go to a sports match) appears: it's the evening, and we're strictly non-participatory, and she's wearing lycra sports gear. Cycling shorts and a top, along with some ridiculous fingerless gloves. It's Adelaide in September so it's not the warmest of evenings - I was chilly. I look past this and we go to get the bus. Adelaide do this thing where you buy a day travelpass and that lets you use all public transport. I have one and so does she - we board the bus without incident. We make small talk for a while, until she notices some other people going to the game. CGC starts talking to them and asks for some of their alcohol. They laugh but she persists; eventually they give her the dregs of one of their cans. (Asking for alcohol from complete strangers: #3).

We get to the grounds and she chooses this moment to ask for money for the ticket. I point out she invited me because she had a ticket going to waste; she could have sold it to someone at the ground if she'd just wanted to get the cover price back. We haggle and settle for a few bucks off the cover price and I'd buy her a beer. CGC says OK, but tries to sell it to some random bystanders anyway.

We get into the game and find our seats. Although she said she was a fan of the AFL she doesn't know the rules. This doesn't bother her but it bothers me - I like to know what I'm watching. I start talking to the people next to me and get them to explain the rules. Then the game starts. CGC's true nutbar quality starts to shine.

"Go the Crows!" she bellows. Completely at random, throughout the game. People around her were giving her that "Is this person dangerous or merely weird?" look. When people at a football match are looking at you for making too much noise... oh my (#4). At one point she started shouting for a team that wasn't even playing. I pointed this out to CGC. "Well, they must play sometime," she replied (#5). Then she starts cheering for animal rights (#6... I'm not going to keep track any more, we're beyond warning signs now). I'm all for them but I don't see where they enter into a sports match.

But that wasn't the worst part. At least during those moments she was watching the game. See, CGC has decided that I'm a hottie, and she wants a piece. Oh, how she wants a piece. She keeps playing with my hair and telling me "You look cute." At one point she even climbs onto my lap. No thank you! Eventually her pestilent advances get far too much and I fabricate a girlfriend for myself.

"You're very cute."
"Yeah, my girlfriend thinks so too."
"Aww, You have a girlfriend?"
"Yeah, I do."
"Are you... committed?"
"Oh, very much so."

This does not deter her, and I must fend off advances for the entire match. I figure "In for a penny in for a pound," and start fabricating an entire backstory for myself. I'm a 26 year old Scorpio from Birmingham with a job, and so on. I made damn sure she didn't get my surname.

CGC wanders off intermittently, presumably to harrass other members of the crowd, and I breathe a sigh of relief and apologise to the people around me. "She's not with you?" "God no. I'm an unwilling bystander." It's a cold night and I'm chilly. I have a jumper, but it's not doing a vast amount of good. She tries to borrow it occasionally and I explain that no, sorry, it's mine and I'm cold. "Not very gentlemanly," she says. "Well, I'm no gentleman, and you're the one who went to change and came back in tiny lycra."

Eventually the match ends. Port Adelaide got crushed - the game had some entertaining moments but they were very much outclassed. The Adelaide fans are ecstatic; the Port Adelaide fans downcast. We leave the stadium and go to queue up for the bus back to the town centre. CGC starts talking to random people in the queue again; she talks to a morose-looking man with a painted face and head to toe in blue about how much she enjoyed the game and what a good match it was. Similar foot-in-mouth incidents go on for the whole queue but for the most part everything goes fine. Nobody punches her and most people are taking her inane comments in good humour. She panics about not getting a bus and I explain that it's a football match - people will have thought of this. This bus is full but there will be another along in 3 minutes that will be empty, and so on until the stadium is deserted.

We get towards the head of the queue and it's obvious we're going to get onto the next bus. It draws up and people start getting on. It's about 80% full and there are 3 people in front of us. Despite having queued quite patiently up until this point CGC walks past them all, up to the end of the bus without sticking her ticket in the machine, and sits down. A situation is brewing. In the UK if you did this a couple of bag ladies would tut; Australians are not reserved. Why would she ever do this, anyway? She has a valid ticket! She would have got on! The entire bus is now pissed off at her. I wait like a good little Brit and get on, validate my ticket, and explain to the bus driver that she's kind of with me and I'll sort it out.

I go up to the back of the bus where an angry Aussie is in her face. I explain that she does have a valid ticket, and she should go and validate it. Yes, you're on the bus, but there are a lot of people on the bus who hate you and think you're not paying, so for God's sake go and put your ticket in the machine. No buts, go and do it now. She acquiesces and does so; the hostility reduces a little.

She starts to walk back up the bus towards me. In front of her is a heavy-set, middle-aged woman. She's another Port Adelaide fan. Not only is she in blue, but she's got some of those chunky radio headphones on and a big furry jester hat. CGC thinks it would be a good idea to steal the hat - she reaches out and grabs the hat, but gets the headphones too. The woman's just got on the bus so has no idea that CGC is a live one, and she was grabbed from behind so she's got no idea what's going on. The hostility on the bus is back.

"What the bloody hell do you think you're doing!" she bellows at her. CGC looks clueless - what, you're angry? Why? I roll my eyes and jump in again to defuse things, telling myself I only have 30 minutes more of this at most. I tell her to give the hat back, and she does. I apologise for her behaviour but the lady is much smarter than she looks - she refuses to spread her anger around. "It's not you I'm bothered about, it's her!" She tells CGC that she shouldn't be allowed out, and I tell Mrs PA that I agree.

The rest of the bus ride back is uneventful apart from the entire bus staring at her. She's still going on about my girlfriend, and trying to coax me off with her. There's one more incident that sticks in my mind, when she makes a sudden inocuous move and I flinch bigtime. I was that paranoid about what she could do. I lie: two more incidents. She starts eating her bus ticket. God knows why, as she needs it to get home. I try to dissuade her, but it's not my problem so I don't intervene when she carries on.

We get off the bus at the central station and I take the picture I linked to above. I took it for "Yes officer, that's the woman," purposes, as well as to prove to people that she really existed. She tries once more to talk me into coming home with her and to hug me, I rebuff her, and dash off into the station before she can gather her wits to follow me.

Originally published on Kuro5hin.

Camomile tea

I have never liked your standard tea. I don't even know what it should be called; I am not a tea aficionado. My mother drinks it a lot - as a middle-aged British housewife she drank it a lot as I was growing up. I found it a very bland drink and that offended me.

When I was around 14 I discovered the wonders of coffee. That was an adult, a metropolitan drink! The caffeine hit and the social cachet appealed to my adolescent mind and with typical pretentiousness I would bring a flask of it to school with me. These days I no longer drink it.

No, these days I like my tea. Not your PG tips and your Tetley's - these are still a bore. Consider it my own rebellion against the British side of myself. I like the herbal teas and the fruit teas. My word, they're wonderful. This summer I went travelling around Australia and ended up staying for two weeks with a young lady and her father. They got fresh camomile and brewed it up in a clear teapot, straining the flowers out when a cup is poured. I loved it. There's no teabag that comes close to it that I have found. Fortunately, mediocre camomile is still pretty good.

There are other teas I like. My love affair with fruit teas goes back a couple of years to when I was heavily involved with the student union. The University catering service would leave their individually wrapped fruit teabags lying around in meeting rooms after their meetings and I would have meetings afterwards. Well there was no point letting it go to waste, was there? A broad range of fruit teas were there for the taking. The other day I happened across a similar abandoned meeting refreshments table, and my box of fruit tea is now nicely augmented. I particularly recommend anything with a citrus fruit, though they're all good.

A new favourite of mine is jasmine tea. I had a cup of this in a pub recently (I know, I know. What kind of prat drinks tea in a pub? Pleased to meet you) and it was amazing. I went to my local Chinese grocery store and bought a cheap box. It's not up to the standard of the pub stuff, so more experimentation is needed and possible cross-examination of barmaids. Its deficiencies in taste are made up for somewhat through the aesthetic of this particular brand - that peculiar exoticism of something predominantly foreign. What's on the packet in English is translated with typical Chinese aplomb. It's declared as a product of the Fujian Tea Import & Export Co., Ltd. and each individual bag describes itself as Aromatic Flavour Clear Infusion Homely Refresher Ideal Gift.

At present I am not buying any new tea. I have boxes and boxes of the stuff - well over a hundred teabags in my cupboard right now. I'm moving out in a little under a month, and am trying to get through at least 3 cups a day (I am failing) as it feels faintly ridiculous to move teabags with me. My cache was not helped thanks to an overly-helpful supermarket. I had ordered 40 organic camomile teabags, as they had a far better taste than the non-organic kind. Of course they were out of stock and I got 40 non-organic ones. So now I've got at least 2 months of mediocre camomile to drink before I can get back to the nice stuff. Drat.

Originally published on Kuro5hin.