Mysql Mishap

Last week I learned a valuable lesson about backing up MySQL, it was this:

  • It is not enough to copy the files out of /var/lib/mysql or wherever if you want to backup your databases.

The thing with copying files is that if the mysql daemon is still running, there’s no guarantee that the physical files are up to date or even consistent. MySQL can do its own housekeeping whenever it would like to which means file write operations. It also keeps information in memory and will write it to disk at a later time to suit itself. The recommended backup method for MySQL is to use the mysqldump tool – more on that later.

The Scenario

Having had a server failure and discovered that file backups taken while the mysql server was running was all we had, I was unsure if we were going to get everything back. I did manage to recover the databases, by doing the following:

  1. Find a server with a similar version of mysql. Happily my “lost” server was 5.0.21 and our development box runs 5.0.24 so I wasn’t too worried about changes in file formats.
  2. Stop the mysqld on that box
  3. Copy the files into /var/lib/mysql (this is on ubuntu but I think its a pretty similar setup on other distros). I didn’t have any data on this machine to start with which made things simpler. MyISAM stores its data in directories called the name of the database.
  4. Check the file permissions – the files need to be owned by the user that mysql runs as. This caught me out the first time around.
  5. Bring up mysqld and hold your breath.

In the event we seem to have most things and to be honest that’s more than I dared hope. There are some corrupt tables but nobody can swear that they weren’t like that before so with a bit of luck we won’t make any nasty discoveries further down the line [1].

MySQL Backup Strategy

I’ve been doing some setup on the new servers and backing up what was salvaged from the old one. I’ve devised a simple loop which dumps and zips each database in turn, using a shell script. The code for the script is below:

#!/bin/sh
for i in `mysql -B -u root -e “show databases” | tail -n +2`; do
echo $i
mysqldump -u root $i | gzip -9 > mysql/$i.`date —iso-8601`.gz
done

Its nothing that isn’t used by sysadmins everywhere but its simple and it works for me so its here (for when I forget what I did!). This example writes a .gz file for each database into a folder called mysql in the same location as where you call the script from. You probably also need to add -p switches to both the mysql and the mysqldump calls unless you are running with no root password which is rarely a good idea.

I hope this is all helpful to someone; I know I learned some useful lessons this week!

1 I’d also like to point out that this was an internal server with little critical information on it and a backup routine that’s been running so long nobody can remember setting it up. Which isn’t great but its less bad that it might be.

Don’t close the door!

I know I’ve been pretty quiet around here lately but we’re still without internet at home (don’t ask – a story for another day) and work is frantic so I’m struggling to find time. While everyone is waiting I thought I’d let you know that the trap in my house has been disarmed.

Its the downstairs loo door – here are the photos of it from either side:

Can you spot the deliberate mistake?

The cross-piece bit that over hangs the door has been switched sides at some point, so that the handle and latch-lifting bits now don’t operate anywhere near the bit they’re supposed to. So if you go inside, and shut the door, …. then the latch drops and you are locked in!

Happily I’ve removed the hook for the cross-piece. OK so you can’t shut the door on the loo but at least you can’t shut yourself in :) Sing while you’re in there?

Wedding Weekend

Some of you know this young lady and I’m sure she won’t mind me posting a little shot of where I was this weekend:

Boxes and Labels

I’ve packed the camera as I’m away this weekend, so I’m sorry but a word-related house post is all there is for today.

We’ve got most of the furniture assembled now, or at least in the room it is destined for, and the process of unpacking begins. Remember that quite a lot of stuff has been in storage for 18 months. I’ve been entertained by some of the labelling on the boxes and though I’d share.

  • Lorna Burford 2005 (the other label on the box reads “stereo, placements, pebble lamp, coasters” which gives you a clue that I’m not actually in the box)
  • Things Lorna Can Live Without Jan 06 (ironically, its been unsealed so I can get something at some point!)
  • An IKEA Uplighter and a 30cm Farnell Ruler. How Useful
  • Contents of Tall Shelves. Burford Jan 06 Can you remember what possessions you haven’t seen in a year and a half were on a shelf in a house you longer live in?? No, me neither!
  • My personal favourite: Mugs. Other Things. (on a very large box)
  • Spotted yesterday when looking for a bit of N64: Contains the Internet

On the other hand, every box is labelled and dated, which makes me feel like I might be quite organised. There was a comedy moment when someone helping us unpack brought a box off a sainsburys dinner service and asked what was in it as we hadn’t labelled it … the answer is “the dinner service”!!

Timber!

There’s a tree in the new garden which shouldn’t be there. In general I’m in favour of trees, but this was a horrible big conifer which blocked the light from our garden and next door’s.

Here’s the offender:

And the “after” shot:

Ah, that’s better :)

Ding! Dong! The doorbell’s … gone

So we’ve just moved into our new house – its quite large and the mobile signal is quite poor. We’ve got a wireless doorbell and can take the chime around the house with us which is very useful. We had not got round to screwing it to the wall yet so for the last few days its been hanging off the front door handle.

Yesterday, the doorbell rang and when I went to the door, the doorbell had been stolen!! Someone had walked off with it and was ringing it. That’s a really great welcome to a new neighbourhood, isn’t it?

Fun With Unix: MOTD

I’ve been having fun over the last few weeks, writing about the fun things that you can do with Unix (see earlier articles about cowsay, fortune, mesg and go fish). This is the last in the mini series unless anyone has any other good suggestions for things that should belong here, and its MOTD or “Message of the Day”.

When you log into a unix box (or linux box, I’m using the term fairly indiscriminately in this instance) you will get a standard greeting message, usually telling you what kind of a system it is and adding a bit of a disclaimer. They aren’t very interesting messages but they are easy to change. Look at the contents of /etc/motd and you will see the text that gets displayed to a user on log in.

Traditionally this file is used by sysadmins to let users know of any changes that have happened or perhaps to warn of scheduled down time. However its also pretty usual to find something a bit more light-hearted there. My particular favourite is to add some ascii art as a welcoming banner to the user … what’s yours?

Photos from the house: day one

Following the news about our recent house purchase, I promised everyone some photos, so here they are. I’ve only got internet connection at work so I’m afraid I’ve just picked a few of the ones we took on Friday, with the house exactly as we found it.


our bedroom


the basement kitchen


the living room (yes, I straightened my hair, I know it looks different)


one of the top floor rooms … before we touched anything.

So we’ve had thirty bags of rubbish out of the house so far, and the front room looks like a bomb has hit it as we’ve got all our wordly posessions in there while we sort the house out.

The gas is on a card, which is fine but you have to get a new card when you move in and its been a bank holiday so it only arrived today … have you tried cleaning a four storey house with no hot water unless you put a pan on the stove? It felt very victorian! Fingers crossed we might have hot water later on today if Kevin can get the boiler lit.

New Home

We did it … we got to the end of the process and we are now Home Owners :)

Its been a rocky road right until the last minute, I hadn’t wanted to blog the completion date being today in case I jinxed the whole thing … and just as well because there was a couple of days in the middle of the week where we didn’t think it was going to happen! The vendor wasn’t able to clear the house in time (he’s only had 5 months warning after all!) and couldn’t move until next week. We had a time constraint on our mortgage so in the end we agreed to pay £2,000 for the contents of the house … with no idea what was actually there.

Suffice to say we’ve got an awful lot of rubbish for that money – some good furniture but also wardrobes still full of clothes, kitchen still equipped and more other things besides. We’ve been there most of the day, cleaning madly and filling rubbish sacks.

Its late now and tomorrow I’m off to fetch furniture from storage, but I wanted to update with my news (and not before it actually happened). Thanks to everyone for their moral support along the way – more stories and photos to follow I promise!

Making your blog number one

I’ve come across lorelle’s blog challenges before but this one caught my eye. The challenge is to come us with a search phrase that you are the top hit for in google. Here’s mine:

cowsay house

I think that pretty much sums up this whole site in fact! Can you rise to the same challenge? Let me know what your number-one-in-google phrase is.