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.


(Walker Blackwell) #34

Does this Export/Import fully support attachments yet?

I see some very bare code that does export an //upload id in the post json but this seems not to properly call when doing an import back into another discourse and also doesn’t seem to be pointed to an actual file in the uploads (X1,X2, etc) directories.

What would be good.

  1. Export all attachment urls to json (the original files) and also cp these files to an export folder (next to the json)
  2. Then ideally there would be an arg that could be passed during the import_topics or import_category that would tell the import script the location of the attachment folder.
  3. Then attachments + json are imported and optimized images are created for each jpg,png, etc.

Does this already exist somewhere already and I’m just not seeing it?

best all,
Walker


(Neil Lalonde) #35

This tool doesn’t support that, but the discourse_merger tool does.


(Walker Blackwell) #36

oh jeez. :flushed: it’s done then.

Thank you @neil you are a life saver.

-W


(Lee Davy) #37

Hi James,

I would like to copy an existing Category that contains course content, YouTube clips, etc. I have read your posts, but it’s all a bit gobbledygook to me. Is there a way of dumbing the process down for me, please?