# CLI command to migrate a single category

**URL:** https://meta.discourse.org/t/cli-command-to-migrate-a-single-category/35728
**Category:** Feature
**Tags:** rfc, spec
**Created:** [November 18, 2015, 6:16am UTC](https://meta.discourse.org/t/cli-command-to-migrate-a-single-category/35728 "2015-11-18T06:16:57Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [November 18, 2015, 6:16am UTC](https://meta.discourse.org/t/cli-command-to-migrate-a-single-category/35728/1 "2015-11-18T06:16:57Z")

</div>

We need to build a general purpose tool for moving a category from one Discourse instance to another.

This has come up on one of our customers and is also useful for a variety of use cases:

### Use cases for category import / export

1. (current need) During huge migrations we may need to avoid long term downtime, so we need to run a temporary site on one domain and then ship the content (eventually) to the new imported site

2. In some cases category partitioning is not strong enough, we have seen this issue at the site @BCHK hosts. In cases like this it may be desirable to partition a site into 2 seperate sites.

3. In some cases many tiny Discourse sites are created unnecessarily and an amalgamation is desirable

### A CLI tool only

The scope of this spec is for a command line tool **only**. There will be no GUI at all for the first version.

### Topic export with layered category export

At the heart of it we need a mechanism to export a single topic as a stand alone unit that can be imported into another instance. Format wise we need to export all users , user actions and posts as single tar-csv, xml or json blob.

We are only interested in exporting “involved” users, that is, users that have tracking state, user actions or direct involvement with the topic.

Once applied to a category the export will avoid double exporting users, the format should specify users first and then content in each of the exported entities.

For v1 we need to cover user case (1) and have an importer.

### Example usage

```plaintext
discourse export some_category > my_export.tar
discourse import < my_export.tar

```

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [November 18, 2015, 1:12pm UTC](https://meta.discourse.org/t/cli-command-to-migrate-a-single-category/35728/2 "2015-11-18T13:12:24Z")

</div>

I’ve been wanting to build a discourse\_cli app for sometime now so that it’s possible to do admin tasks like this and have it use the discourse\_api gem.

Is this something you would like to have as a separate discourse\_cli project or do you think it needs to live in discourse so that it can make actual sql queries?

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [November 19, 2015, 6:13pm UTC](https://meta.discourse.org/t/cli-command-to-migrate-a-single-category/35728/3 "2015-11-19T18:13:43Z")

</div>

I just created a CLI Tool that we can use for admin tasks like migrating categories.

[https://github.com/blake/discourse\_cli](https://github.com/blake/discourse_cli)

This is just the basic structure for the CLI tool, it doesn’t haven any features yet other than displaying a list of categories.

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [January 25, 2016, 5:17pm UTC](https://meta.discourse.org/t/cli-command-to-migrate-a-single-category/35728/4 "2016-01-25T17:17:43Z")

</div>

> [@sam](#):
>
> tar-csv, xml or json blob.

This is very deja vu. It’s basically the original spec for our backup/restore, which didn’t work because it broke whenever the db schema changed. We need to limit the scope of what it means to export a user, user action, topic, post, etc. otherwise this tool will become impossible to maintain.

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [February 2, 2016, 10:14pm UTC](https://meta.discourse.org/t/cli-command-to-migrate-a-single-category/35728/5 "2016-02-02T22:14:08Z")

</div>

The tool is described here:

> [@Move topics from one Discourse instance to another](https://meta.discourse.org/t/topic-and-category-export-import/38930):
>
> Need to move some stuff from one instance of Discourse to another? There is a command line tool to export a topic, a set of topics, or an entire category, and another to import them in at the other end. Topic Export/Import one or more topics and their replies the users who posted in the topic Category Export/Import the category and all its subcategories its security settings custom groups mentioned in the security settingswarning if any of the groups have ‘membership requests’ enable…

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 2, 2016, 10:15pm UTC](https://meta.discourse.org/t/cli-command-to-migrate-a-single-category/35728/6 "2016-02-02T22:15:01Z")

</div>


