Migrate staff users to another server

Hi everyone. I’m migrating my Ghost install to a new server. Everything on the new server is up and running except for the users (staff). The member export/import was easy. But what about the main staff/users? I haven’t been able to find any help in backing up or exporting the users so I can import them into the new install. I’m using docker-compse in both the old and new installs. When I enter the old install container and try to run the ghost cli it gives me an error about running the cli as root being forbidden.

  1. Is there a way to copy/migrate staff to a new server that doesn’t require the ghost cli?
  2. If not, how do I enter the ghost container and run the cli as non-root?
  3. Does the cli actually backup the staff users?

This seems extremely important to me because on the new server all the posts and pages now point to staff who don’t exist in the db yet. It seems to me that staff export should be part of the site export feature in settings under the import/export section.

Thanks for your assistance. Cheers.
Justin

In a Ghost-to-Ghost migration, I always recommend using a database backup, rather than the exports from Ghost.

Quite frankly, the though is nice, and they are great for quick things, but for full migrations they are lacking details, like staff users, newsletter statistics, comments, etc.

If you still have access to both stacks, I’d recommend that way. If you’re running your MySQL database in your Docker stack as well, the MySQL container should have mysqldump:

mysqldump -u [your_user] -p [your_database] > backup.sql

In the new one, you can use this to import the backup again:

mysql -h localhost -P 3306 -u [your_user] -p [your_database_name] < backup.sql

You will need to restart Ghost after you imported the backup.

Staff users are in the main export .json file.
But Jannis is otherwise right that a database dump is probably preferable.

2 Likes

*runs to check the export file*

Oh yes, they are. I thought they were only in there as authors, not as actual users :exploding_head:

1 Like

Not only are they in the export JSON, but if you’ve already got posts in the target instance you can import a JSON that only has meta & staff users. This would be a perfectly cromulent import:

{
  "meta": {
    "exported_on": 1676913455963,
    "version": "2.0.0"
  },
  "data": {
    "users": [
      {
        "email": "contributorone@example.com",
        "slug": "contributor-one",
        "name": "Contributor One",
        "roles": [
          "Contributor"
        ]
      },
      {
        "email": "contributortwo@example.com",
        "slug": "contributor-two",
        "name": "Contributor Two",
        "roles": [
          "Contributor"
        ]
      },
      {
        "email": "contributorthree@example.com",
        "slug": "contributor-three",
        "name": "Contributor Three",
        "roles": [
          "Contributor"
        ]
      },
      {
        "email": "contributorfour@example.com",
        "slug": "contributor-four",
        "name": "Contributor Four",
        "roles": [
          "Contributor"
        ]
      }
    ]
  }
}

That way you’re not duplicating posts etc

Hi all,

Thanks for your feedback. @Cathy_Sarisky, you’re right, the user data is in the main export json file. There are a few different reasons this wasn’t apparent to me right away; but I’ll just admit I’m a dummy for not looking more closely at the json file.

One important step in the import process is to refresh your browser window after importing the main json file.

@jannis, thanks for your valuable db backup method. I was successful without having to use it, but I’m sure it’s a good method. The main export does in fact export the users, though I can’t comment on newsletter stats. I can confirm it does not export post comments (not a big problem for me this time around).

Here are the steps I’ve successfully taken to migrate docker Ghost websites, in case someone finds this forum topic and is looking for migration help.

  1. Create new folder for docker files on new server, with a subfolder for Ghost data.
  2. Copy docker-compose.yml from old to new server. Edit URL in this file to a temporary name. Add this temporary URL to the domain registrar’s DNS entries. We’ll delete it later.
  3. Copy the Images/ Files/ and /Media folders from you old Ghost data folder to the new server’s Ghost data folder.
  4. Spin up the container, go to siteurl/ghost to log into the admin. First user creation is the new site owner (we’ll delete this user later).
  5. Log into the old site’s frontend and export data to local hard drive.
    |i.| Settings → Import/Export → Export → Export Content
    |ii.| Settings → Theme → Change Theme → Installed → (hamburger for active theme) → download
    |iii.| Settings → Labs → Open → Download current redirects
    |iv.| Settings → Labs → Open → Download current routes
    |v.| Dashboard → Members → (gear wheel) → Export all members
  6. Log into the new site’s frontend and import the five files from above.
  7. Using two different browsers, log into the new frontend with the old site’s owner credentials and in the other browser log in with the newly created owner. Make the new frontend owner the person you want it to be. Delete the newly created owner.
  8. Make sure that everything works on the new server, reloading the page in your browser.
  9. Change URL in docker-compose.yml and restart the container.
  10. Change your DNS settings to reflect the IP address of the new server.
  11. Do a “clear cache and reload” on your browser for this stie.
  12. After double checking that everything works, remove temporary URL from DNS settings.
1 Like