Tonight, at precisely 6:50pm, my bag with my laptop was stolen right from under me. Literally right from under me. I was at a food court downtown with some friends having dinner. I always keep my bag on the floor between my feet specifically in case something like this happens, but the chair I was sitting on made it hard to feel the bag. The silver bag with “Oracle” embroidered on the front that my dad brought back from Oracle OpenWorld last year was stolen less than three minutes, and I didn’t feel a thing.
Fortunately my laptop was the only thing of any value in the bag, but the real loss was my files. Ordinarily I use Unison to backup my files to my desktop computer. Unison is great, because it merges the source and destination directories, so my files on both systems should be more or less identical. But, since I recently reinstalled my desktop machine, barely any of my files were backed up. It seems I’ve lost everything I’ve done on my disk since September 9, 2012.
The real loss is all the code I’ve written. Fortunately, I didn’t do much coding over the past semester, but I’ve spent around 10 solid hours so far on a WordPress plugin that I’ve been developing, and I wrote a program for summer camps that sorts campers into tables and generates charts for them. Both of these programs are totally gone, and will have to be rewritten.
As I rode my bike home, having done all I could with mall security to get proof that my laptop had been stolen for insurance purposes, the thought of my missing files weighed on me. I wasn’t too angry that I hadn’t completed a full backup – I’ve lost plenty of files over the years, and I guess I’m hardened to it. But I knew that I couldn’t let this happen again. I needed a backup solution that would work. And I needed it to work without my having to do anything. I wrote that solution tonight, and it took me only 19 lines in bash.
You can download the bash script here: Incremental Backup Script. All it does is ping the ip of the device, and if it’s found, and if it’s been 30 minutes since the last backup, the script uses rdiff-backup to backup the device. I’ve put this in my crontab to run every five minutes. This way, whenever I power on my new laptop and connect to my wireless network, my machine will be backed up. This counts on passwordless ssh logins with ssh keys being setup, which isn’t difficult to do.
You never really see backups as a priority until you lose a lot of files. Back in highschool, I lost tons of files due to careless fresh-installs, during a phase of experimentation with various Linux distros. The experience hardened me in some way to the experience of data loss, but I’m now facing the reality that I had a lot of useful files on my laptop that will never be retrieved. My business card template, the programs I mentioned before, most of my pictures – they’re all gone, and aren’t recoverable. And nineteen little lines of bash code could have saved them.Other than using the backup script to backup my files, I plan to implement a few other tricks on my next laptop. First, I’ll encrypt my home directory. I hadn’t done it before, because I hadn’t gotten around to it, and because hard disk encryption is relatively easy to defeat. Nevertheless, it reduces the probability that the person stealing my laptop knows how to get into my files, and that’s a good thing. Second, I want to set up a cron job on my new laptop that will connect to my desktop (which is accessible through a domain managed with dynamic DNS) and check on its status. If I have marked the device as stolen, it will erase my files, and possibly transmit any changes that haven’t been backed up yet. I’m thinking about ways to add some sort of executable code to the master boot record (or the equivalent on a GPT partition, since I’ll be buying a Mac) once the laptop realizes that it’s been stolen, so that instead of loading the operating system, it will appear to hang as it wipes the disk. Finally, another option I’m considering is using a service like Skyhook to feed me the location of my laptop, similarly to the way that software like MacTrak does.
It’s a bummer that I lost my laptop, and that I lost my files, but at least some good has come of this: I’ll be properly backing up my files, and if someone steals my next laptop (which hopefully they won’t… fingers crossed), they’ll find it rather difficult to get my files.