A week early but management surprised me with an early gift.
Archive for January, 2008
I finally cobbled together an incredibly ugly but functional script for recovering or setting up a slave. The pure hideousness stems from the brute force, lack of error checking, cram that data down the db’s throat method that I am leveraging. See, I know just enough to get the job done but not nearly enough to do it with any elegance, flair, or care and concern for stability. Running with scissors, at night, with a blindfold, through a roomful of children’s toys and cats is my style.
Anyways, here we go…
This script is executed on the slave instance and will fetch the most recent copy of the db from the master, stop the slave, drop the db, recreate the db, read in the backup, issue the change master command, start the slave, and then display the slave status after a minute.
#!/bin/bash
# Recover slave post crash
# run backup from master
# transfer it to the slave
echo "Getting backup, this may take a while."
ssh master "/scripts/slave_recovery.sh WHATSLAVE"
echo
# untar backup
echo "Expanding backup and getting ready to import."
cd /mnt/tmp/recovery
recover=$(ls | grep yourdb)
tar -xf $recover
# set variables
recodir=${recover:0:21}
mastfle=$(ls $recodir/ | grep master)
fullbin=$(cat $recodir/$mastfle | grep A.)
binlog=${fullbin:2}
fullpos=$(cat $recodir/$mastfle | grep B.)
positn=${fullpos:2}
echo "Here's what I have..."
echo $recodir
echo $recover
echo $mastfle
echo $binlog
echo $positn
# stop slave
echo "Stopping slave..."
mysql -e "slave stop;"
# drop database
echo "Dropping the database..."
mysql -e "drop database yourdb;"
# recreate database
echo "Recreating the database..."
mysql -e "create database yourdb;"
# source database from backup
echo "Importing the database..."
mysql yourdb < $recodir/$recodir.sql
# issue change master command
echo "Issuing the change master command..."
mysql -e "CHANGE MASTER TO MASTER_HOST='master', MASTER_USER='USERNAME', MASTER_PASSWORD='PASSWORD', MASTER_LOG_FILE='$binlog', MASTER_LOG_POS=$positn;"
# start slave
echo "I am starting the slave..."
mysql -e "slave start"
# clean up
rm -r *yourdb*
# check status
echo "I'm waiting one minute the checking the status of the slave..."
sleep 1m
mysql -e "show slave status \G;"
echo
echo "I am all done."
Now, you might have noticed that on the seventh line I call another script on the master and you might have noticed a variable trailing it. WHATSLAVE is whatever you called your slaves in the host file on the master in my unimaginative case it is slavea and slaveb but you could have Tom, Dick, and Harry, or the names of your favorite Hostess snackcake characters.
#! /bin/bash
# This script runs on the master and is built off the backup script
# set date variables
DAYNOW=$(date +%j)
TIMENOW=$(date +%H%M)
# grab info about the binlog and position of the database
status1=$(mysql -e 'show master status \G' | grep mysql)
status2=$(mysql -e 'show master status \G' | grep Position)
sql=${status1:18}
posit=${status2:18}
mkdir /mnt/tmp/backup/slave-yourdb-$DAYNOW-$TIMENOW
echo A.$sql >> /mnt/tmp/backup/slave-yourdb-$DAYNOW-$TIMENOW/master-$DAYNOW-$TIMENOW.txt
echo B.$posit >> /mnt/tmp/backup/slave-yourdb-$DAYNOW-$TIMENOW/master-$DAYNOW-$TIMENOW.txt
# dump database
mysqldump yourdb > /mnt/tmp/backup/slave-yourdb-$DAYNOW-$TIMENOW/slave-yourdb-$DAYNOW-$TIMENOW.sql
# tar SQL dump
cd /mnt/tmp/backup
tar -chf - slave-yourdb-$DAYNOW-$TIMENOW | gzip - > slave-yourdb-$DAYNOW-$TIMENOW.tar.gz
rm -r /mnt/tmp/backup/slave-yourdb-$DAYNOW-$TIMENOW/
# copy tar to slaves
scp /mnt/tmp/backup/slave-yourdb-$DAYNOW-$TIMENOW.tar.gz root@$1:/mnt/tmp/recovery/slave-yourdb-$DAYNOW-$TIMENOW.tar.gz
#clean up
rm /mnt/tmp/backup/*.gz*
echo "I'm all done!"
This is just our basic backup script but rather than trying to pass all the variables through ssh I decided to be lazy and just execute the script remotely.
Some of the things I would like to add would be more flexibility in reading the backup name and error checking. Down the line I want to see if I can just backup the schema and import that into the slave db so that I don’t loose all that time reading the db back in (500MB+ can take awhile) and it would help with rapid recovery from data migrations. If you have any comments or suggestions, particularly if they trip your “WTF is wrong with this guy?” sensor I’m all ears.
One of the more addictive features that the team has rolled out is the Money Confessions section where people can either publicly declare something or mutter behind the cloak of anonymity. Some of them are outright funny, like musing if buying a hooker a car is a bad idea, but sometimes they are heart wrenching displays of humanity.

It is that combination of irreverence and poignancy that makes the feature so addictive to follow.
This is a case of too much yet not enough.
I tried, really tried, but this weighted tome dragged me under and held me until sputtering and choking I put it down for bright skies and fresh air. Melville could have used a good editor as the liberal use of semi-colons left me eyes bulged and teeth gritted waiting for the sweet relief of a period. Coupled with the near worthless expositions of natural history, metaphysics, and self-congratulatory displays of knowledge about biblical and ancient myths the worthwhile parts are stretched too far apart like so few of those whaling stations he wrote so fondly about.
I dashed that out late Saturday night after tossing the book aside in frustration but is it really a problem with the prose? After some honest self reflection, I’d say no. This is a classic “It’s me, not you” situation. Too put it in perspective my time and resources are over taxed, over allocated, and poorly invested. I subscribe to over 200 RSS feeds, participate in dozens of online communities, chase after my year-old, work a full-time job, consult on the side, and try to cook a decent meal. When I carve out a moment to read, like I have been trying to do for over two years with my reading list, the most I can concentrate on is linear fluff. Melville is too dense and while wandering around the woods with Gabi I came to the conclusion that I need to carve up my life and discard those pieces that are superfluous.
200 feeds, seriously I would wake up in the morning with some 1800 unread items and after skimming 200 items I would just make the whole stack as read. What is the point of that? Wasted time, wasted energy, and the whole process left me feeling both mentally fatigued and scatterbrained. After hacking my feed list up and sanding it down it now stands at 53 feeds and when I wake up I have around 80 items unread.
Online communities? Paring it down as I type with the goal of abandoning nearly all with the exception of where my co-workers and friends hangout: Facebook/Twitter/Geezeo for work and a private site for my friends. I’m still following the blogs of friends and will chat there but gone are the days of commenting on Digg, Reddit, eMusic, Last.fm, ad nauseum. One thing that I have learned is that soaking in it can be mentally toxic; how many Ron Paul stories can you read and how many posts can a lonely divorcee make while drunk to what was once my favorite music destination? Really, I don’t give a fuck how much Chardonnay you drank or how horny The National makes you and Ron Paul? Get serious, he is a Class A fuckwit. A post or two might elicit a chuckle, but any number beyond that makes me want to hurl my laptop right out the front door. The noise is overwhelming the signal.
Getting back to basics. It is really more like reconstructing my pre-Internet life: time to read and listen to music, time to work, time with family, time to be creative, and time to be active. While I might not be able to drop everything and hit the trails for an epic ride like I did some 10 years ago I can carve out time for a walk. Better yet, we signed up at a local community center which has everything you could wish a health and fitness center could and would: daycare, playscape, Olympic sized pool, exercise classes, free weights, cardio room. It will give us a chance to spend time as a family as well as provide us a place to maybe get a little less doughy.
So what does this have to do with Moby Dick? My life as I have been living it is keeping me from being able to really read it and that is a symptom of a bigger issue. If I cannot put forth the time to read a book typically assigned in a high school English class what else am I missing out on and who else is getting shorted when it comes to my attention and energy. So, while I’m putting it down and picking up something a little more trashy, I am not willing to give up on it completely. Maybe after I put things back in perspective you might find me banging out some sets on a recumbent while polishing off the closing chapters of Melville’s love letter to the semi-colon.









