Move topics from one Discourse instance to another

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 settings
    • :warning: if any of the groups have ‘membership requests’ enabled, it will crash. Turn this off before the export
  • all topics and posts in the category and subcategories
  • all users who posted, and assigns them to the groups

Begin: Identify the IDs

First, identify the ID(s) of the =Export= that you wish to export. You’ll find this at the end of the URL used to access it.

  • https://meta.discourse.org/t/how-to-contribute-to-discourse/53797

  • https://meta.discourse.org/t/how-to-contribute-to-discourse/53797/12
    (in this case you are in the middle of a topic - grab the first number)

  • https://meta.discourse.org/c/howto/faq/4

Category or Topic ID(s)

Multiple topics

You can select more than one topic by adding IDs separated by a space; this works in the field above (I don’t think that this works for categories though):

  • 53797 200943 124096

Run the Export Script

The tool can be run as a root user inside the container:

cd /var/discourse
./launcher enter app

Run this command:

discourse export_=Export= =ID=

The output should look something like this:

Starting export of =Export=…

Where are the new users all coming from?
Export saved to =Export=-export-2021-08-27-015437.json

Done

Move the Exported File

The exported .json file needs to be moved from the inside of the application container where you did the export to the inside of the container of the receiving instance. This takes a few steps.

Copy it to the ‘outside’

Exit the container if you haven’t already

exit

You should now have a prompt like this:

root@yourserver:/var/discourse

Use docker to copy the file out of the container (you can’t move it I don’t think)

docker cp app:/var/www/discourse/=FileName= .

Move it to the other instance

This is beyond the scope of this guide, but this might help you get there:

Copy it into the container in the receiving instance

SSH into your receiving instance as root and get to the Discourse directory:

cd /var/discourse

Use docker once again to copy the file into the other container

docker cp =FileName= app:/var/www/discourse

Import the Content

Enter the container in the receiving instance:

./launcher enter app

Run the import script

discourse import_=Export= =FileName=

:cake: Done!

You might need to tidy up some loose ends, but hopefully, it should all be done.

Advanced Tips

Missing Ruby Gem

When doing a complex category import, my instance was missing the ‘Listen’ Ruby.
This was solved by doing this: (using the Discourse user inside the container)

./launcher enter app
su discourse
bundle config --delete without
bundle config --delete with
bundle install
exit
exit

This broke the rails console, necessitating a rebuild afterwards

./launcher rebuild app

Multisite

In a multisite environment, use the RAILS_DB env variable.

RAILS_DB=xxxmoves discourse export_=Export= =ID=
RAILS_DB=dancerehab discourse import_=Export= =FileName=

Please report bugs in the Contribute > Bug category, and request enhancements in the Contribute > Feature category.


Related Topics


Last Reviewed by @SaraDev on 2022-07-13T00:00:00Z

Last edited by @hugh 2024-05-29T06:25:11Z

Check documentPerform check on document:
45개의 좋아요
UI: Topic and Category Export/Import
CLI command to migrate a single category
Moving topics between sites?
Category/Topic export fails with error "database "discourse_development" does not exist"
Easiest way to export a single topic?
Saving a Conversation
How to export user data from a category on a hosted site
Import CSV User Activity from one Discourse to Another
How use API to convert topic in discourse1.com to discourse2.com
Can sub-forums of the same instance split up and move to new independent servers (or discourse instances)?
Help migrating category from one instance to another without admin on the source instance
I wonder how to add hundreds of users into a group? Is there any api?
How to download Comments and Topics
Adding default sets of topics, categories and users to a new Discourse
Can we combine 2 separate discourse sites?
Tracking and resolving a schema drift cause
Merge two Discourse forums into one
Moving topics from a forum on one website to a forum on another website
Transfer topics between forums?
Forum Aquisition
Transfering inbox group messages to another instance?
Transfering inbox group messages to another instance?
Imported categories are not in parent category
Copy categories / topics
Downloading Content
Selective backups skipping settings and config
Test driving admin/moderation features
Add backup to existing Discourse instance
Merging two Discourse forums
Migrating vBulletin onto existing and live Discourse instance
Migrate topics from one discourse instance to another?
A system where people have to start at lesson 1, and cannot see the other lessons?
How to divide my community into 2 parts
Migrate user custom fields to another instance
Error Importing Categories from a Discourse Instance to Another

다시 한 번 시도해 볼 생각입니다.

관련 업로드를 주제(Topics)와 함께 이전하는 쉬운 방법이 있을까요?

1개의 좋아요

별로 없습니다. 대부분 잘 되는 방법은 해당 업로드들을 모두 가져온 후, 이동하려는 사이트의 어떤 게시글이든 원본 URL을 붙여넣는 것입니다. 그러면 원래대로 그 업로드들이 동일한 SHA로 생성되어 그냥 잘 동작해야 합니다.

즉, 게시글 안의 내용을 URL로 변환하는 작업을 통해 그 URL들을 얻어야 합니다. (그 방법을 정확히 기억을 못 해서 매번 다시 찾아봐야 합니다.)

1개의 좋아요

음 – 여전히 조금 혼란스럽습니다. 말씀하신 것이 이게 정상적으로 동작한다는 뜻인가요?

  1. 첫 번째 사이트의 모든 업로드 파일을 가져온다
    • 어떻게?
  2. 이들을 단일 토픽에 넣는다
  3. 그러면 이전 사이트에서 가졌던 것과 동일한 상대 링크가 생성되어 마법처럼 작동한다?

아니면 이걸 말씀하신 건가요?

  1. 이전 사이트에서 관심 있는 카테고리의 모든 절대 URL을 가져온다
  2. 이들을 토픽에 붙여넣는다
  3. 그러면 모두 동일한 SHA로 새 사이트에 다운로드되고 기존 링크가 모두 마법처럼 정상 작동한다?

아니면 전혀 다른 걸 말씀하신 건가요?

1개의 좋아요

두 방법 중 어느 쪽이든 작동할 것 같습니다. 새 사이트로 이미지를 가져오는 방식이 무엇이든, 동일한 sha가 생성되어 기존 토픽의 링크가 자동으로 작동하게 될 것입니다.

아래와 같은 방식으로 해볼 수 있습니다.

cat_id=123
Topic.where(category_id: cat_id).each do| t|
  Post.where(topic_id: t.id) do |p|
      p.cooked.match(image url)....
         puts(the match) 

그렇게 한 후 해당 링크를 사이트의 어떤 게시물에 붙여넣으면, 모든 이미지가 로컬로 다운로드되고 동일한 sha가 생성되어 링크가 정상적으로 작동할 것입니다. 수동으로 몇 개를 테스트해 보실 수 있습니다.

지금이 한밤중이라 제 경험과 다를 수 있습니다.

2개의 좋아요

안녕하세요, 이 튜토리얼이 제가 하고자 하는 내용인지 확실하지 않지만, 여기서 질문을 올리겠습니다.

서버에 Discourse를 설치했는데, 트래픽 증가로 인해 더 강력한 서버로 이전해야 하는 경우, 이것이 올바른 단계인가요?

예를 들어, 백업 옵션은 어떻게 되나요? 다른 서버에 Discourse를 설치한 후, 해당 옵션을 통해 기존 인스턴스의 백업 복원을 수행할 수 없나요?

필요할 때 어떻게 이전해야 하는지, 그리고 최근까지 해온 작업을 잃지 않으려면 어떻게 해야 하는지 알고 싶으므로, 답변을 기다리고 있습니다.

1개의 좋아요

아니요. 더 큰 서버로 이전하려면 간단한 백업과 복원만 있으면 됩니다. 또한 rsync를 사용하여 Discourse 사이트를 다른 VPS로 이동할 수도 있습니다.

1개의 좋아요

오래전부터 업로드 마이그레이션 문제를 해결하고 싶었는데, 이제 AI 챗봇의 도움으로 마침내 해결했습니다. 관심을 가져주시는 분들을 위해 제 노트를 공유합니다! Jay의 위 게시물에는 시작하는 데 필요한 핵심 정보가 포함되어 있어 감사드립니다.

제 첫 번째 시도는 Jay가 예측한 대로 정확히 작동했습니다. 이동하려는 사이트의 이미지 URL 목록을 생성하여 새 사이트의 게시물에 붙여넣으면 이미지들이 다운로드됩니다. 이 기능이 작동하려면 Download remote images to local(원격 이미지 로컬 다운로드)이 활성화되어 있어야 합니다.

AI 챗봇이 이를 위한 스크립트를 작성해 주었는데, 후속 작업에 도움이 될 수 있도록 여기에 공유합니다.

요약

Rails 콘솔에서 다음을 실행하세요:

topic = Topic.find(=TOPIC_ID=)
posts = Post.where(topic_id: topic.id)
urls = []

posts.each do |p|
  UploadReference.where(target: p).each do |ref|
    urls << "=SOURCE_URL=#{ref.upload.url}"
  end
end

puts urls.uniq.join("\n")
puts "\nTotal: #{urls.uniq.count} upload(s)"

:bulb: 전체 카테고리를 이동하려는 경우? 처음 두 줄을 다음과 같이 교체하세요:

topic_ids = Topic.where(category_id: =TOPIC_ID=).pluck(:id)
posts = Post.where(topic_id: topic_ids)

이 경우 =TOPIC_ID=는 Admin → Categories에서 URL 끝에 찾을 수 있는 카테고리 ID입니다.

하지만 제 경우에는 이것만으로는 충분하지 않았습니다. 자동으로 로컬에 다운로드되지 않는 PDF 파일도 있기 때문입니다.

그래서 챗봇에게 업로드를 마이그레이션하는 Python 스크립트를 작성해 달라고 요청했습니다. 꽤 잘 작동하므로 이것도 공유하고자 합니다. 직접 시도해 보거나 피드백을 남기고 싶으시다면 여기에 저장소가 있습니다.

또한 챗봇에게 주제나 카테고리를 이동하는 더 완전한 런북(runbook)도 작성해 달라고 요청했는데, 이는 제 discourse에 올라와 있습니다.

2개의 좋아요