I somehow managed to break my blog...
Update: Blog online, data missing. I'm currently working on recovering it.
update: As of 10:15 PM EDT, the blog is back online!
What happened? Well, It all started when I decided it would be a great idea to update my Ghost installation to 0.4.2. I'd done an upgrade before without much trouble so I thought everything would be okay. Unfortunately, Ghost wasn't on board with my plan.
I started out by checking out the latest version of ghost on my server, which went smoothly. Next, I ran
sudo sh -c "npm install; bower install; grunt; grunt prod" to get all the dependencies and build all the assets. This went off without a hitch. I restarted my Ghost service and verified it was running.
This is where things get strange. My blog's content seemed to be just fine. But when I attempted to log into the admin console, it would reject the username and password for my account. I was a little annoyed, but not too concerned. I figured I could just reset the password. Nope. Upon trying to send a reset email, I was given an error message claiming that the Gmail account I configured for reset emails couldn't be authenticated. Thats when it hit me: The account was a dummy account I created with the sole purpose of sendign me password reset emails. The very same dummy account that I had gotten an email from Google about one week prior stating it was being closed due to TOS violations. -.-
A simple fix really. Just have to update those settings! Since I have a nice new AWS account with a bunch of credit to burn through, I figured I'd hook it up to SES. I logged into my console, and generated the creds to send emails using SES. I plugged them in, rebooted the service, fired up the forgotten password page and.... Nope! More errors. This time something about bad credentials. AWS is great, but it can be incredibly picky about permissions. After some more fiddling and prodding though, I did manage to get password reset emails working.
I clicked the link in the email from my blog, and it brought me to the password reset page. I filled in a new password and hit submit. Navigating back to the login screen, I proceeded to enter in the new login and password. Upon hitting submit, I was greeted with a lovely error about it not being the right username/password ......WAT?!?
Something's not right, I thought. I'm going to run the service manually and take a peek at the output. What I saw was pretty disturbing (for me at least). Something along the lines of "Your database is incompatible with this version of Ghost - You will have to create a new one". No problem, I though, I'll just switch back to the old version!
I checked out the previous version I was running, ran the scripts to set everything up and booted up the service manually. I loaded my home page, which displayed perfectly. I then tried to get to the login screen. This is when I really started to sweat... It wouldn't load! I would wait for a dozen seconds or so, and nginx (used for proxying) would 502 me! Looking in the console, I saw a message along the lines of "Unhandled exception: session table doesn't exist". I had no idea what was up.
Things didn't look good for chrisdecairos.ca... I decided my only option was to copy my contents directory (contains the sqlite db file, images, and themes directory) and my configuration file somewhere safe so that I could wipe the slate clean on my ghost installation. I downloaded the official release zip of ghost 0.4.2 and replaced my installation with its contents. I double checked that all the dependencies were in plave and that all assets were built. I copied over my config file, and started up the service.
It worked. I was able to log into a new account and regain access to the admin tools. I re-instated all the themes settings to get the look and feel of the blog back. With everything back up and running, the only thing left for me was to migrate all my posts and tags into the new db file. With a bit of research, I found what I needed:
sqlite3 ghost.db .dump > ghost.sql
Which dumps the sql to create your DB into a file. I opened up that file and deleted all the statements that weren't related to posts, tags and posts_tags. I also removed the create sytax for those tables. I should mention that I compared the schemas between the old db file and the new, and they were identical. This meant that once I ran the script, I should be back in business. Anyways, I scp'ed the script to my server, logged in and ran:
sqlite3 content/data/ghost.db < ~/ghost.sql
and crossed my fingers.....
When I reloaded my blog, everything was back to normal! I had succeeded! I had also lost most of my evening -.-
The takeaways from this are two:
- Back up your database, you dummy!
- Git checkout is a horrible way to update blog software.
But hey, at least I know how to recover my blog in situations like this.