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.
- one or more topics and their replies
- the users who posted in the topic
- the category and all its subcategories
- its security settings
- custom groups mentioned in the security settings
- 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
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.
(in this case you are in the middle of a topic - grab the first number)
Category or Topic ID(s)
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
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
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.
Exit the container if you haven’t already
You should now have a prompt like this:
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= .
This is beyond the scope of this guide, but this might help you get there:
SSH into your receiving instance as root and get to the Discourse directory:
Use docker once again to copy the file into the other container
docker cp =FileName= app:/var/www/discourse
Enter the container in the receiving instance:
./launcher enter app
Run the import script
discourse import_=Export= =FileName=
You might need to tidy up some loose ends, but hopefully, it should all be done.
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
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=
Last Reviewed by @SaraDev on 2022-07-13T00:00:00Z