13 November 2006

Barn Raising

Grandpa left a couple of presure treated 4×4 posts at our house a couple of months ago. I kept looking at them thinking it was a waste to have them just sitting on the ground. What could I do with them? The best thing I could think of was to build a shed. So it was off to Home Depot… A few hundred dollars later and a quite a few hours (spread over a few months) later and I almost have a shed to put my gardening stuff in.

So I really didn’t/don’t know how to build a shed. I just started asking questions to people who I thought might know something about it. I learned a lot from talking to them and then started hammering nails into some boards. It is going pretty well. The real problem is that I don’t have any time to work on it during the day, and it gets dark by 5:00 now. So Saturday is the only real time I have to work on it. Well, I will persevere and hopefully have it done before Christmas!

09 November 2006

Backup Plan

So I have recently setup a backup plan for our mysql database. I am pretty happy with how it came out. I use Amazon S3 as the final storage device for all of the backups. A fairly simple ruby script (below) runs mysqldump and then pushes the result out to S3.

I wanted a weeks worth of daily backups, a months worth of weekly backups, and monthly backups for all of eternity. After figuring out how to use the ruby date object the rest was pretty easy. The ruby cookbook held the only decent documentation that I could find on how to actually use the date object. Thanks for the excellent documentation!

I also used some information from a great post on the Mission Data Blog. The current code I had opened a file read it into memory and then transferred that to S3. The mentioned blog post explained how to change Net::HTTP to stream a file.

Here is the interesting part of the code I wrote:

# create AWS connection
conn = S3::AWSAuthConnection.new(AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
USE_SSL)

today = Date.today
system("mysqldump --opt dbname |
bzip2 -c > /var/backups/dbname-#{today.to_s}.sql.bz2")

#put out today's backup
putfile conn, :bucket => "db-backup",
:key => "dbname-#{today.to_s}.sql.bz2",
:file => "/var/backups/dbname-#{today.to_s}.sql.bz2"

#remove old copies
if today.day % 7 == 1
delete conn, :bucket => "db-backup",
:key => "dbname-#{(today < "db-backup", :key => "dbname-#{(today - 7).to_s}.sql.bz2"
end

#remove old local copies
FileUtils.rm "/var/backups/dbname-#{(today - 7).to_s}.sql.bz2",
:force => true

If anyone has any interesting ideas on how to implement a better backup plan I would be very interested in hearing some more ideas.

07 November 2006

What the world needs now...

No, not love sweet love, but another blog! After fighting destiny for so many years, the oocha blog is officially started! I will put my first real post up soon. First it is off to the docs to figure out how this crazy contraption works.

paul