How to migrate Ghost blog content between development and production environments?
Asked Answered
I

2

12

I set up a new Ghost 0.4 blog, created numerous posts, then switched to production mode before setting the site live. To my surprise, the posts I created no longer showed up. Since setting up Ghost 0.3.3, I had forgotten that Ghost uses separate database stores for the production and development environments, and I failed to switch to production mode before creating content.

How can I migrate content from Ghost's development environment to its production environment?

Islamize answered 16/1, 2014 at 18:29 Comment(0)
I
17

Ghost uses SQLite databases, which stores content in a single file for each content, so it's easy to back-up, move or copy an entire database in one go.

To solve the problem of having posts only in my development database, I simply shut down Ghost, and switched the production and development SQLite database files. The files are stored in the Ghost content/data sub-folder:

  • ghost-dev.db is the development database
  • ghost.db is the production database

If you're in the Ghost folder, the following commands will swap the two environment databases:

$ mv content/data/ghost-dev.db content/data/ghost-dev.db-tmp
$ mv content/data/ghost.db content/data/ghost-dev.db
$ mv content/data/ghost-dev.db-tmp content/data/ghost.db

Restart Ghost in either mode to see the changes.

It's even easier to just copy everything from development to production:

$ cp content/data/ghost-dev.db content/data/ghost.db
Islamize answered 16/1, 2014 at 18:29 Comment(0)
C
2

An easy way to change this behavior is to just choose to use the same database for both production and development.

Modify the following line in your config.js under development:database:connection from

filename: path.join(__dirname, '/content/data/ghost-dev.db')

to

filename: path.join(__dirname, '/content/data/ghost.db')
Culpa answered 31/12, 2015 at 1:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.