BackupPC only when mobile device / laptop is plugged in
Thursday, May 22nd, 2008I’m the proud owner of a Nokia N800 Internet Tablet (which I will, of course, write about later) and I’ve been getting around to doing a bit of hardware hackery now that the semester has ended. I wanted to integrate this tasty little Linux machine into my home backup system, which is powered by BackupPC. Unfortunately, running rsync and wireless eats up the battery pretty quickly. Thus, I rigged up this command, which will cause the backup to fail if the tablet is not plugged in.
$Conf{RsyncClientCmd} = '$sshPath -q -x -l root $host grep -q 0 /sys/power/sleep_while_idle && $rsyncPath $argList+';
The key is grep -q 0 /sys/power/sleep_while_idle which queries the kernel to see whether the CPU should sleep when it’s idle. When the N800 is plugged in, the value is 0, grep -q returns a non-zero exit code, and the backup proceeds. When the N800 is on battery, the value is 1, and the backup stops. The string /sys/power/sleep_while_idle is definitely hardware specific, and you’ll need to poke around /sys or /proc for an appropriate filename and value to grep for.


