نقل المواضيع من مثال Discourse إلى آخر

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 discourse import_=Export= =FileName=

Please report bugs in the bug category, and request enhancements in the 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:
43 إعجابًا

سأحاول مرة أخرى.\n\nهل هناك طريقة سهلة لترحيل الملفات المرفوعة ذات الصلة مع المواضيع؟

ليس حقًا. الشيء الذي يعمل في الغالب هو إذا حصلت على كل هذه التحميلات ولصقت عنوان URL الأصلي في أي منشور في الموقع الذي تنتقل إليه، فعندئذ ما يجب أن يحدث هو أن هذه التحميلات سيتم إنشاؤها بنفس SHA وستعمل ببساطة.

لذلك ستقوم بالشيء الذي يحول الأشياء في المنشور إلى عنوان URL للحصول على عناوين URL هذه. (لا يمكنني أبدًا تذكر كيفية القيام بذلك، لذا يجب عليّ معرفة ذلك في كل مرة).

هممم - ما زلت مرتبكًا بعض الشيء بسبب ذلك. هل تقصد أن هذا سيعمل؟

  1. احصل على جميع ملفات التحميل من الموقع الأول
    • كيف؟
  2. قم بإسقاطها في موضوع واحد
  3. سيتم إنشاء نفس الرابط النسبي الذي كان لديهم في الموقع القديم وسحر!

أم كنت تقصد هذا؟

  1. احصل على جميع عناوين URL المطلقة في فئات اهتمامك من الموقع القديم
  2. الصق هذه في موضوع
  3. سيتم تنزيلها جميعًا إلى الموقع الجديد بنفس التجزئة وستعمل جميع الروابط الموجودة بسحر

أم شيء آخر تمامًا؟

أعتقد أن أيًا من هذين الخيارين يجب أن يعمل. ومع ذلك، يمكنك نقل هذه الصور إلى الموقع الجديد، ويجب أن تُنشئ نفس الـ 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، وبالتالي ستعمل هذه الروابط. يمكنك تجربة عدد قليل يدويًا لترى.

إنه منتصف الليل. قد تختلف النتائج.

إعجاب واحد (1)

مرحباً، لست متأكداً مما إذا كان هذا البرنامج التعليمي هو ما أريد القيام به، ولكني أطرح السؤال هنا.

إذا قمت بتثبيت Discourse على خادم، ولكن بسبب النمو أحتاج إلى الانتقال إلى خادم أقوى، فهل هذه هي الخطوات؟

ماذا يحدث، على سبيل المثال، مع خيار النسخ الاحتياطي؟ ألا يمكنني القيام بذلك، وتثبيت Discourse على خادم آخر ثم استعادة النسخة الاحتياطية من المثيل الآخر من هذا الخيار؟

أنتظر توضيحك، حيث أريد أن أعرف كيفية الترحيل عندما أحتاج إلى ذلك وعدم فقدان العمل الذي كنت أقوم به مؤخرًا.

لا. للانتقال إلى خادم أكبر، فإن النسخ الاحتياطي والاستعادة البسيط هو كل ما هو مطلوب. يمكنك أيضًا نقل موقع Discourse إلى VPS آخر باستخدام rsync