15
August
2008

Backing up and restoring all your MySQL databases with Ruby scripts

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.

11
December
2005

personal

Tagged as:
, , .

Here we go…

So after a few hours of backing stuff up to the external HD, I’m ready to go. No, really, I am. I’m going to take a whole-disk image as further precaution (in case I forgot anything), but other than that, I think I’m ready to go.

I’m going to reformat the disk and give this computer a nice clean start. With any luck, all my iPhoto and iTunes libraries can be restored in a flash, and then I can go about the boring process of patching the computer and reinstalling applications. My mail database seems up-to-date, even if the program itself is stuffed.

Erk. Nerves. Here we go…

Update: slowly, we’re getting somewhere. Just recovering Mail now…

Links & notes for this month

Endnotes