@tryghost/mg-ghost-api
v0.14.0
Published
Export content from an existing Ghost installation using the [Admin API](https://docs.ghost.org/admin-api), and generate a `zip` file you can import into a Ghost installation.
Maintainers
Keywords
Readme
Migrate Ghost API
Export content from an existing Ghost installation using the Admin API, and generate a zip file you can import into a Ghost installation.
Posts are fetched in their native Lexical format and stored in a mg-context SQLite database (cached in the migration's tmp dir). The exporter writes chunked posts.json / posts-N.json files via MigrateContext.writeGhostJson so very large sites stay within Ghost's import file size limits. Re-running the same command is idempotent — posts are deduplicated by their Ghost ID via mg-context's lookupKey.
Install
To install the CLI, which is required for the Usage commands below:
npm install --global @tryghost/migrateTo use this package in your own project:
npm install @tryghost/mg-ghost-api --save
or
pnpm add @tryghost/mg-ghost-api
Usage
To run a Ghost API migration, the required command is:
migrate ghost --url https://example.com --apikey 1234abcdIt's possible to pass more options, in order to achieve a better migration file for Ghost:
--url(required)- Ghost API URL
- string - default:
null
--apikey(required)- Ghost API key
- string - default:
null
-V--verbose- bool - default:
false - Show verbose output
- bool - default:
--zip- bool - default:
true - Create a zip file
- bool - default:
-s--scrape- Configure scraping tasks
- string - default:
all - Choices:
all,assets,noneall: Scrape web metadata and download assetsassets: Only download assets (images, media, files)none: Skip all scraping tasks
-I--info- bool - default:
false - Show initalisation info only
- bool - default:
-b--batch- number - default:
0 - Batch number to run (defaults to running all)
- number - default:
-l--limit- number - default:
15 - Number of items fetched per Ghost Admin API request (fetch batch size)
- number - default:
--postsPerFile- number - default:
2000 - Maximum posts written per output JSON file. Larger sites are split into
posts-1.json,posts-2.json, etc. to keep files at manageable sizes
- number - default:
--posts- bool - default:
true - Import posts (set to false to skip)
- bool - default:
--postFilter- string - default:
null - A string of post filters, as defined in the Ghost Admin API
- string - default:
--pages- bool - default:
true - Import pages (set to false to skip)
- bool - default:
--pageFilter- string - default:
null - A string of page filters, as defined in the Ghost Admin API
- string - default:
--cache- Persist local cache (including the mg-context SQLite DB) after migration is complete (Only if
--zipistrue) - bool - default:
true
- Persist local cache (including the mg-context SQLite DB) after migration is complete (Only if
--tmpPath- string - default:
null - Full path where temporary files (cache + mg-context DB) are stored. Defaults to a hidden tmp dir
- string - default:
--outputPath- string - default:
null - Full path where the final zip file is written. Defaults to CWD
- string - default:
--cacheName- string - default:
null - Unique name for the cache directory. Defaults to a UUID derived from the URL
- string - default:
A more complex migration command could look like this:
migrate ghost --url https://example.com --apikey 1234abcd --batch 5 --limit 10 --postFilter 'tag:[news, press]' --pages false --verboseThis will get the first 50 posts with the tag news or press, in 5 batches of 10 posts, exclude pages, and show all available output in the console.
For very large sites, tune --postsPerFile to control how the output is chunked:
migrate ghost --url https://example.com --apikey 1234abcd --postsPerFile 1000See the Filter documentation for more info.
Develop
This is a mono repository, managed with Nx and pnpm workspaces.
Follow the instructions for the top-level repo.
git clonethis repo &cdinto it as usual- Run
pnpm installto install top-level dependencies.
Run
To run a local development copy, cd into this directory, and replace migrate with pnpm dev, like so:
pnpm dev ghost --url https://example.com --apikey 1234abcdTest
pnpm lintrun just eslintpnpm testrun lint and tests
Copyright & License
Copyright (c) 2013-2026 Ghost Foundation - Released under the MIT license.
