Migrating Ghost content

Today I went from manually running a docker on a VM to running a fully managed Ghost docker image on DigitalOcean.

For reference, this is how I initially set up my blog. And this is how I set up the new one. What was left then was to migrate all the data from the old blog to the new one.

In the settings of the old blog, I can export everything to a JSON file. So that's what I did.

Then I went to the same settings page in the new blog and imported that file. However, it failed verification with a cryptic message about something missing. I simply removed the offending line in the json, and import worked fine.

That's all it took. Suddenly all the posts appeared! Or so I thought. I opened one of the blog posts to check, and the images were missing. It turns out, the Ghost export tool does not export images nor theme settings, as documented here.

Theme settings

To transfer theme settings, I had to manually copy/paste the Site Header and Site Footer. Easy enough.

Images

For images, I had to ssh into the machine hosting the old blog. My docker image was storing all the data into a blog_data folder. In it, I compressed the whole image folder:

tar -zcvf blog_images.tar.gz images

Then I transfered the file to the new VM:

scp blog_images.tar.gz root@new_vm:~/
ssh root@new_vm

# On the new VM:
cd /var/www/ghost/content
mv ~/blog_images.tar.gz .
# Unpack from content, so that its images folder goes where it should.
tar -zxf blog_images.tar.gz

After this, images started to appear again!

Images show up again on the new blog.

But image upload started failing.

Couldn't upload new images to the new blog anymore.

So I checked the logs:

/var/www/ghost/content/logs# cat https___www_wafrat_com_production.error.log

[...]"statusCode":500,"responseTime":"140ms"},"err":{"id":"809f61a0-fc43-11ec-8fe1-6328307dffb6","domain":"https://www.wafrat.com","code":"EACCES","name":"InternalServerError","statusCode":500,"level":"critical","message":"EACCES: permission denied,[...]

So this clearly looks like a file permission error. I checked file permissions and sure enough the user was different:

/var/www/ghost/content# ls -l
total 36
drwxrwxr-x 2 ghost     ghost     4096 Jul  5 07:55 apps
drwxrwxr-x 2 ghost     ghost     4096 Jul  5 07:55 data
drwxrwxr-x 2 ghost     ghost     4096 Jul  5 07:55 files
drwxr-xr-x 9 ghost-mgr ghost-mgr 4096 Jan  1  2022 images
drwxrwxr-x 2 ghost     ghost     4096 Jul  5 07:58 logs
drwxrwxr-x 2 ghost     ghost     4096 Jul  5 07:55 media
drwxrwxr-x 2 ghost     ghost     4096 Jul  5 07:59 public
drwxrwxr-x 2 ghost     ghost     4096 Jul  5 07:59 settings
drwxrwxr-x 2 ghost     ghost     4096 Jul  5 07:58 themes

So I changed the full folder to belong to ghost:ghost like the rest of the files:

chown -R ghost:ghost images

And when I tried to upload an image again, it worked!