Thursday, November 29, 2007

Bacula to the Rescue (again)

It happened again - disastrous data corruption. Last time it involved my email client (icedove) on my own Linux box. This time it was my wife's email client (Outlook Express) on her Windows machine.

It started when OE asked me, upon being closed, if I'd like it to compact its folders in order to save disk space. This kind of maintenance is recommended by Micro$oft in order to prevent corruption of the message storage files. Compacting is also known to cause corruption...

And guess what? it did. My wife's Inbox, very much like her desk, is filled with stuff - more than 8000 messages. After compacting was done, only 6000 messages were left - 9 months worth of emails were lost.

If this ever happens to you and you're running Windows XP and up than you may be able to restore the original dbx storage files - OE places a copy of the original files in the recycle bin before compacting (but with a .bak extension instead of .dbx).

I didn't know this at the time, so I went ahead and restored those email messages from the Bacula backup. As I described a while ago, I have an elaborate backup procedure that backs up individual email messages instead of the gigantic dbx files. After restoring the messages to a temporary folder on my wife's PC, I simply selected the missing messages (eml files) in Windows Explorer, and then dragged and dropped them into the Inbox folder in OE.

It took a few minutes, but OE (and I) survived this ordeal.

Sunday, November 25, 2007

Are We Running on AC Power?

One of the nice things about using a laptop as a desktop substitute is its battery. This proved important lately as we experienced several successive power failures. We finally managed to find the culprit - a faulty electrical appliance.

In the meantime I needed a way to disable backups when my laptop was running on batteries, because the the external USB backup disk runs on mains power. This is easy enough using the script on_ac_power (part of the powermgmt-base package) - define the following function

check_ac_power ()
{
# must be on AC power
echo -n "Checking AC Power ... "
( on_ac_power > /dev/null && ( echo "ON" ; return 0 ) ) || ( echo "OFF" ; return 1 )
}

and run it at the beginning of the script that's executed by Bacula with the RunBeforeJob directive:

check_ac_power || exit $?

The exit $? bit is used to return the status that was returned by check_ac_power, if it fails (i.e. non-zero status code), to Bacula.

[14 Jul. 2008] UPDATE: the on_ac_power script stopped working after a kernel upgrade... (I've also revised and fixed the contents of this entry).

Wednesday, November 21, 2007

Format and Label a FAT32 External Disk

It took me a while to accept the fact that my backup disk is simply too small. It proved too small even after carefully selecting the files and directories to backup, and calculating the files and job retention periods, and backup rates, to match my 60GB disk. It only takes a few days of leaving large files lying around to fill up the backup disk - it has no slack.

I felt it was time to indulge myself and buy some hardware - I got a Western-Digital 250GB Elements USB external disk. It comes with no software at all, FAT32 formatted, and is readily recognized by my box.

I decided to format it after checking the disk with fsck.vfat (part of the dosfstools package) - it complained about differences between the FAT's on the disk, and about hidden sectors. The interesting bit of trivia regarding FAT32 is that you can't format a FAT32 volume larger than 32GB - get this - under Windows! Under Linux you just run the following:

mkfs.vfat -F 32 -n volume_name /dev/sda1

(you should, obviously, replace /dev/sda1 with the correct device path). The generated file system (233GB in size) is perfectly usable on both Windows and Linux.

As it happens, I did not specify a volume label, and went on to copy the backup files from the old disk to the new disk. I (and my Linux box) only realized that the volume label was now empty, at the next reboot, two days later. So I needed a way to label the disk without formatting it. This can be done with mlabel (part of the mtools package) like this:

mlabel c:volume_label

But you must first edit /etc/mtools.conf to make sure that the drive letter c: maps to the correct Linux device path - in my case it was just a matter of un-commenting the following line:

drive c: file="/dev/sda1"

I don't know why this mapping is necessary, but that's how these tools work.

Slack is good.

[7 Feb. 2008] UPDATE: labeling a disk updates just one FAT, causing fsck.vfat to complain about differences between FAT's on the labeled disk - this seems to be perfectly harmless.

Monday, November 5, 2007

Display IMAP Quota in Icedove 2

For Icedove 1.5 you should install the Display Quota add-on. It works with Icedove 2 (currently available from the unstable repository), but isn't really needed.

Icedove 2 shows the quota in the status area when it goes above some threshold (default is 75%). To make the quota always visible follow this procedure:
  1. Select the menu "Edit -> Preferences"
  2. Select the "Advanced" tab
  3. Click the "Config Editor..." button: a window titled "about:config" should appear
  4. In the filter text box enter "quota"
  5. Modify the value of mail.quota.mainwindow_threshold.show from 75 to 0
  6. Restart Icedove

Saturday, November 3, 2007

Script for Removing GNOME Panel Applets

I was playing around with the GNOME Swallow applet. It's a nice little toy that can "swallow" non-applet applications into the GNOME panel. I used it to convince wmforkplop and wmhdplop to show up in the bottom panel, and then decided it would be nicer to have them on the top panel.

I didn't realize at the time, but it turns out that hitting "cancel" on the swallow applet configuration dialog box, doesn't remove the applet from the panel - it only leaves it un-configured. The only way to actually remove it (when it's not configured) is by directly editing the list of panel applets that's kept in the GNOME configuration database. This can be done manually using gconf-editor, but following this guide I came up with a script to get rid of all the swallow applets on the bottom panel:

#! /bin/sh
applets=`gconftool-2 --get /apps/panel/general/applet_id_list | sed -r -e s/[][]*//g -e s/,/\ /g`
new_applets=""
for applet in $applets ; do
add=$applet
bonobo_iid=`gconftool-2 --get /apps/panel/applets/${applet}/bonobo_iid`
if [ ${bonobo_iid} == "OAFIID:GNOME_Swallow" ]; then
echo $applet
panel=`gconftool-2 --get /apps/panel/applets/${applet}/toplevel_id`
if [ ${panel} == "bottom_panel_screen0" ]; then
add=""
fi
fi
new_applets=${new_applets}","${add}
done
new_applets="["`echo ${new_applets} | sed -r -e s/,+/,/g -e s/^,// -e s/,$//`"]"
gconftool-2 --set -t list --list-type=string /apps/panel/general/applet_id_list ${new_applets}

This probably took longer then it should have, but at least I learned something.