I just lost my blog...

If you are reading this then I was able to fix it.

For the past few days I have been living the proverb, "The shoemaker's children go barefoot."

I often say, "The value of a backup is not the backup, but the ability to restore from a backup." I did not have a backup, when I initially setup my blog I just set it up and started using it. It was only an experiement at the time so it did not occur to me that I should think about backing it up. Fast forward a year later and I have been posting an article or two every now and then, building up content and then...

...my blog stopped working.

My blog is a ghost container running on a docker host...so I tried to migrate the blog to a new host and that did not work. I tried to copy the sqlite database to the new host...that did not work. I got a new blog working on a new host and then it would break. I spent a few days banging my head against a wall (figuratively).

This morning I took a deep breath and went to tackling the problem again. Here is what I learned...

Getting things working...

The first think I did was clean up the old docker host. I migrated all the containers and content from the old host to a new host.

Second, I got a new ghost installation working under a different URL.

Next, I took a look at getting the old blog working. I started by shutting down the container and starting it back up using the command:

docker-compose up

This enabled me to see the output of container in the console. Ghost was complaining that the database migration was locked and if the database was ok I could just run some sort of command to fix it. The actual message was:

wmc-blog | [2020-02-13 08:56:41] ERROR
wmc-blog |
wmc-blog | NAME: MigrationsAreLockedError
wmc-blog | MESSAGE: Migrations are running at the moment. Please wait that the lock get's released.
wmc-blog |
wmc-blog | level:normal

Since this is a small blog it was setup to use SQLite. I had never worked with SQLite so I did a quick Google search for "sqlite cli client" and ran

sudo apt-get install sqlite3

to install the sqlite client.

I then stopped the container and opened the database. My first action was to delete the migrations table and restart the container. For some reasons I was under the impression that this would work...It did not.

When I reopened the database I noticed that the migrations table was recreated. Going back to the console message further on I found the message:

wmc-blog | If your database looks okay, you can manually release the lock by running UPDATE migrations_lock set locked=0 where lock_key='km01';.

I opened up the database again and ran the UPDATE command. Victory! My old blog was up and running again.

Migrating to new blog...

Then I did something stupid...actually I had been doing something stupid for a while...assuming that the way to migrate the content of the old blog was to tar up the contents and copy them to the new host.

Actually, it was not really stupid. When I first started working on this the old blog was not running so this was my only option and now that the old blog was running a quick Google search told me that the way to migrate the blog content was to export all the articles into a single JSON file and then import into the new blog.

This worked.

However, I am still interested to find out if there is a way to copy data from an old ghost install to a new installation without having to have the old install working. If anybody knows how to do this please let me know.

Upgrading Ghost

The new ghost install was up and running. On the blog admin page there was a message saying that I was running the old version (1.25 or something and that version 2 is available). On the Ghost website (https://www.ghost.org) it says that version 3 is available.

Again to Google. The results were really unclear. Ultimately, I figured out that all I needed to do was update image in my docker-compose.yml file from:

image: ghost:1-alpine

to

image: ghost:2-alpine

I also tried to upgrade to version 3, but ghost crashed. So, I just reverted back to version 2. For now this should be fine.

Fixing the URL

One thing I noticed that that my new install was creating all links as "localhost:2368" and not "test.williammax.com:2368". This had not been an issue on the old host. Again to Google. Adding:

- url=https://test.williammax.com

in the environment section of my docker-compose.yml file fixed this.

my working docker-compose.yml file looks like this:

version: '3.1'
 
 services:
 
   wmc-blog:
     image: ghost:2-alpine
     restart: unless-stopped
     container_name: wmc-blog
     environment:
        - VIRTUAL_HOST=blog.williammax.com
        - LETSENCRYPT_HOST=blog.williammax.com
        - LETSENCRYPT_EMAIL=max@williammax.com
        - PGID=1001
        - PUID=1001
        - url=https://blog.williammax.com
 
     volumes:
        - ./blog:/var/lib/ghost/content
 
     expose:
        - 2368
 
 networks:
    default:
       external:
          name: nginx-proxy

If you find this information useful, please send me an email and let me know.

Cheers!

Max.