running-grass / posthog-migrate-meta

Migrate metadata from one organization to another

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PostHog migrate metadata

This tool helps move your metadata (ie everything but events) from one PostHog instance to another, for example from your self hosted PostHog instance to PostHog cloud.

Usage

yarn
ts-node index.ts --source [posthog instance you want to migrate from] --sourcekey [personal api key for that instance] --destination [posthog instance you want to migrate to.] --destinationkey [personal api key for destination instance]

Options

  • --source URL of the PostHog instance you want to move from, without a trailling /. Example: https://posthog.example.com. Defaults to https://app.posthog.com
  • --sourcekey Person API key, created on the source instance. See these intructions on how to generate the personal api key
  • --destination URL of the PostHog instance you want to move to, without a trailling /. Example: https://posthog.example.com. Defaults to https://app.posthog.com
  • --destinationkey Person API key, created on the destination instance. See these intructions on how to generate the personal api key
  • --projects A list of project ids to move over. Will default to moving all projects. Example: --projects 1 2
  • --projectmap If you've already created a project on the new instance and you want to move existing projects there, you can map them. Example: --projectmap 81250:1

How to use

  1. Set up an organization on the new PostHog instance
  2. Move events over using the Replicator app's export historical events job.
  3. Use this script as outlined above.

Using this tool to copy across the same instance or organisation

You can also use this tool to copy settings across the same instance and organisation. Just use the same settings for both source and destination. The new project will have (copy) added to the name.

How it works

It'll migrate the following objects

  • Projects (you can pick projects using the --projects option)
  • Dashboards
  • Insights
  • Actions
  • Cohorts
  • Feature Flags
  • Experiments
  • Annotations

Note! It won't move over the following

  • Project API Key. You'll need to replace the API key in your code with the new API key.
  • Events/Persons. You'll need to use the Migrator 3000 app to move events over. Do this first.
  • "created by" information. Every object will appear as if it was created by you.
  • "created at" information. Every object will appear as if it was created on the time you ran this script.

You can safely run this script multiple times using the same parameters as it'll write the objects it's already moved over to state.json.

About

Migrate metadata from one organization to another


Languages

Language:TypeScript 100.0%