Topic and Category Export/Import

import

(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.


#24

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?


#26

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

Done

What’s your output?


#28

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 https://meta.discourse.org/raw/38930/29


(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.