One thing I usually forget to do when I backup a computer is back up my MySQL databases. Partly, because they’re not stored in my Library (I don’t think); partly because I forget how many I have. mysqldump only backs up one database at a time, unfortunately. What would be great is something that dumps all of the databases in the system.

Anyhow, whilst on hold to my ISP this morning, I decided to solve this problem once and for all.

The end result is a pair of Ruby scripts which you can get from github.

The first will iterate over every db on your system (when run with an appropriate username and password) and spit out a .sql file with a filename corresponding to that database. The second look at a folder of .sql files named similarly, and for each one, drop a databases with that name, re-create it, and restore from the .sql file.

I’m sure I could do it just fine in a bash script, but it made sense to use the tool that comes most quickly to my hands, and that means Ruby. Once you’ve got Ruby installed, the rest is easy. Clone them, patch them, fix them; they’re basic, as maintenance goes, but handy.

Get the scripts from github.

Making bridges talk

28 February 2008

I’ve written before about how wonderful Twitter can be as a messaging bus for physical objects. The idea of overhearing machines talking about what they’re doing is, to my mind, quite delightful.

So when I found an untapped data source for such an object, I thought it was worth having a poke. Half an hour of scripting later and Tower Bridge was on Twitter. It tells you when it’s opening and closing, what vessel is passing through, and which way that vessel is going. The times are determined by taking the scheduled time for the “lift” and subtracting five minutes for the opening, and adding five minutes for closing – the official site suggests that, at rush hour, lifts should take five minutes to open and close tops.

That’s it, really; it’s just a simple case of scraping some data and outputting it. It’s not a hugely frequent event, so won’t disturb you very much; if anything, it’s just a little insight into the heartbeat of the Thames.

As a note on its design: it’s very important to me that the bridge should talk in the first person. Whilst I’m just processing publicly available data on its behalf, Twitter is a public medium for individuals; I felt it only right that if I was going to make an object blog, the object should express something of a personality, even if it’s wrapped up in an inanimate object describing itself as “I”.

And, if you want proof that it works… how about this:

Tower Bridge on Twitter

I’d set the server up yesterday; suddenly, this morning, it twittered into life, and we charged out of the office around the corner to the bridge, where the MV Dixie Queen was getting into position for its lift. As it went through, I took a picture. That was a very satisfying moment.

(Thanks to Tom for helping me bash a crontab and a few other server-shaped things into shape. If you’re interested in the technology, which is really not very relevant, it’s about thirty lines of Ruby that glues together a combination of: wget, Hpricot, John Nunemaker’s Twitter gem, and cron.)

Updated June 22nd 2011 with the new URL for the bot, following this whole series of events.

Adam Greenfield recently mentioned this:

“The ability to ‘read’ a medium means you can access materials and tools created by others. The ability to ‘write’ in a medium means you can generate materials and tools for others. You must have both to be literate.”

That neatly taps into a lot of what I’m thinking about (and failing to write about here) at the moment. Things like this, and mixing your own paint, and programming-as-act-in-its-own-right versus programming-as-necessary-evil, and a whole host of other questions (such as what it is I actually do).

Things are slowly coalescing. This quotation coalesced a great deal, and deserved more than a mere del.icio.us link…