Sunday, June 05, 2005

Python on Windows

I've just written my first ever Python script for Windows.

And yes it is big, and it is clever.

My Linux box (mixolydian) is up all the time and every night it backs up a number of things (such as my WebDAV Subversion repository for example). Very nice, but what if that machine's hard drive was to die? Bye bye data.

The easiest solution is to back the files up to another machine: my Windows box (locrian). I much prefer that things like this are done automatically, so ideally I'd mount a Windows share hosted on locrian (from mixolydian) and copy the files that way.

The trouble is that locrian is not left on all the time: it's only on when I use it. To get around that I'd have to write code to make mixolydian poll for the availability of locrian and only copy when it's there. Definitely overkill and a waste of mixolydian's time (which currently is mainly concerned with maintaining a load overage of 0.00).

The solution is to make locrian pull the data rather than having mixolydian push it. To do that, I've written a short Python script in Windows which runs at startup. This lists the files in the two backup directories on each machine and copies across all files that are on mixolydian that aren't on locrian. It runs very quickly, and so hardly makes any difference to the startup time of WIndows.

You probably could do that with a Windows batch file but frankly the Windows command interpreter is such a bitch to work with I simply couldn't be arsed. Plus I just wanted an excuse to write a Python script for Windows (I installed Python on locrian some time ago and afterwards wondered why I had done it: I didn't have anything to run on it.)

So anyway, now I can sleep a little more soundly, knowing that my data is backed up on two hard drives.

Next stop, automatic backing up to CD/DVD...

No comments: