Blog

Badly Scripted Blog Winds Up In Casulty

Posted on Sunday 24th June 2007 at 00:00
As those of you who have looked at my site in the last couple of hours will know, earlier this afternoon, I made a bit of a cock up.

Actually, that is an understatement. I totally screwed up the database for the blog in the most spectacular way possible. It all began when I tried to make some adjustments to the delayed posting script. This script is designed so that I can submit blog posts in advance and specify a day in the future on which I wish them to be posted onto the blog. The idea is that if I know I'm not going to be free on a particular day, I can write a post before hand and set it to go live on the day I'm busy in order to keep a steady flow of posts coming.

The trouble was that the posts were being date stamped when I submitted them instead of when they went live, which was looking rather messy, especially for posts that I wrote several days in advance. So, I wanted the script to adjust the time and date to read the current time and date as and when it made the posts live.

Simple enough job really, just a small bit of additional code to insert into the script. Bingo! I saved the script and executed it to check it worked. Unfortunately for me, when I wrote the script in the first place, I was, shall we say, a touch sloppy with my coding. Normally if I'm writing a script that can edit the database, I put in a number of fail safe features designed to stop it overwriting anything it shouldn't, but on this occasion I'd left them out to save time.


The result was that when I ran the script I changed the date of every single post I'd ever written to today's date. Oh. My. Bloody. God. Quite a lot of my blog scripts rely on those dates being correct; not least things like the archive feature, which checks the posting date on each post in order to construct that list with the months and the number of posts in each month. All that box now said was 'June 2007 (208)', which was very bad indeed.

At this point, I almost burst into tears, because database edits cannot be reversed.


I did, as it transpired, have a back up of the database, but it was a month old, and didn't contain any of my June posts, or their comments or anything like that. Still, it was better than nothing, so I backed up the database again, and then prepared to merge the two back ups.


For those who don't know, when you get a database to back itself up, it dumps every word, letter, number and symbol into a single text file, without any structure or line breaks. This text file is vast, and for the most part completely incomprehensible. It contains every post, every comment, every date and time, every picture, every user name and every......every thing that has ever been put into my site.


Finding where the old file ended and where the new one needed to be added wasn't too difficult. Discovering that all 208 records in the file needed to be updated to include an extra column I'd added since the month old back up was carried out, did prove to be rather tricky. As in two-hours-spent-scrolling-through-text-and-replacing-certain-speech-marks-and-commas tricky.


Needless to say, it has not been the best afternoon of my life, and as soon as I have posted this entry, I shall be writing a series of new scripts that back up my database several times over... just in case ;)

Recent Posts


<-- Bizzare BloggingEvilpedia -->