Topic and Category Export/Import


(Erlend Sogge Heggen) split this topic #13

4 posts were split to a new topic: “Let’s get discussion started” still shows after importing posts

(James Cook) #14

Just a heads up for anyone else using this to do a site migration, this won’t transfer media. You will need to copy it from your existing uploads folder on your server to your new uploads folder.

(James Cook) #15

I was wondering how trivial it would be to also transfer across user site stats (likes, bookmarks etc) and private messages. A few of my regulars have complained that since I did the site migration they’ve lost access to that stuff. I’m sure they built up quite a collection over the two years.

I don’t mind giving it a go myself if somebody can point me in the right direction.


(Stefano Costa) #16

Could this reply be incorporated in the main topic post since it provides crucial howto steps that are missing from the original?

(Neil Lalonde) #17

Good idea. I linked to his post from near the beginning of the first post.

(Matthew Gaudet) #18

One heads up, it’s not clear if this still works; My recent attempt to migrate media along with a category hasn’t been successful as of yet.

(Yvonne Brill) #19

Hi James, I’m a community manager, not a developer but I’m doing some research on ways to export topics from a category and display them in an Excel spreadsheet or similar. Would your instructions allow that, or is your solution for things like migrating the information to another site/platform?

We want to use our community to gather information/ideas and then export it out to allow us to group the data into different themes and further inform some work we’re doing internally.

(Jay Pfaffman) #21

The data Explorer plugin will let you export any data in discourse to a csv.

(Sam Saffron) #22

For CSV you can use Data Explorer, to export the results of a query. We can easily install that for you and create an initial query if you let us know what your spec is for it.

Are you looking for a CSV containing post bodies and links to posts or is this just a category overview?

(Jay Pfaffman) #23

I have a potential client who is a hosted customer who wants to merge data from Ning to his existing Discourse instance. This seems like a way to do that.

I don’t see attachments mentioned as part of what gets exported, but it seems like if it didn’t include attachments it wouldn’t be very useful.


This seems to work differently for Multisites. Not sure how to do it though. I was a bit surprised to use DISCOURSE_DB_NAME and it worked… Then during import I understood it was only to (re-)import data already present on this very same site! Using RAILS_DB at least seems to break, so it’s on the right path. :wink:

Any more up-to-date documentation on this. Maybe if @hawk shows us how to write a run-book with Discourse we can have that one available!

(Neil Lalonde) #25

Exporting and importing from a multisite setup will need RAILS_DB.

RAILS_ENV=production RAILS_DB=sitename bundle exec script/discourse export_category 1
RAILS_ENV=production RAILS_DB=othersite bundle exec script/discourse import_category ...

How does it break?


Thank you for your help @neil!

There’s an (unrelated) error message:

/var/www/discourse/app/models/topic_tracking_state.rb:249: warning: circular argument reference - archive_user_id

Then the category-export file is empty: {"categories":[],"groups":[],"topics":[],"users":null}

I tried with RAILS_DB=sitename where entries in data.yml are like sitename: followed by the list of pups commands, addressing a database name that’s different. I tried adding DISCOURSE_DB_NAME as well without result. I got the category_id from the Rails console: Category.find_by_name('Example Name').id

(Neil Lalonde) #27

That’s only a warning. The output should look like this:

Starting export of categories...

/var/www/discourse/app/models/topic_tracking_state.rb:249: warning: circular argument reference - archive_user_id
Topic title here
Another topic title
Export saved to category-export-2018-03-19-142232.json


What’s your output?


Hi @neil, sorry I didn’t respond, I was swamped under the workload but now it’s over and I may start looking into it again, although I don’t really have a reason anymore. It might be some time before it happens though. Just notifying the topic so others can take over if they encounter the same difficulties.

(Nick Veitch) #29

Slightly related question - is there any way to extract the raw text of a post from discourse, rather than a cooked string?
I expect this can probably be done through postgres, but I was hoping there was a less hacky way

(Jay Pfaffman) #30

Something like

(Nick Veitch) #31

ah, many thanks :grinning: , I didn’t see that mentioned in the API docs

(Christoph) #32

This could be used for splitting up a forum into two forums, for example when some sub-community/category wants to run its own community on a separate site, right?

(Jeff Atwood) #33

Yes, that is definitely one of the goals here.