How can I import/export settings into a file?

Is it possible, after tuning Discourse on local computer, to export all settings into file and upload them into production?

Thanks.

I guess probably you can export your settings from DB.

discourse=>\dt
...
...
 public | single_sign_on_records     | table | discourse
 public | site_customizations        | table | discourse
 public | site_settings              | table | discourse
 public | stylesheet_cache           | table | discourse
...
...

Notice site_settings table. You can also take this data from your backup. It already have a dump of your database inside it.

Then all you need to do is restore this table to your server from your local dump. :thumbsup:

1 个赞

Courtesy of @blake we now have rake tasks to export/import site settings:

rake site_settings:export > settings.yml
rake site_settings:import < settings.yml
13 个赞

For those who do not have access to rake tasks, I also have contributed a settings uploader that uses the API: GitHub - pfaffman/discourse-settings-uploader: Install a Discourse settings JSON file to a site

7 个赞

Hello,

I’ve used discourse-settings-uploader to upload site_settings.json file from the GitHub Jay mentioned. I get this error when I run it:

./discourse-settings-uploader:39:in `<main>': undefined method `each' for nil:NilClass (NoMethodError)

line39: settings['site_settings'].each do |setting|
line40:  jsetting (setting) unless setting['value'] == setting['default']
line41: end

I used an API key for “All Users” and used “system” when I ran discourse-settings-uploader.
Any thoughts?

For future reference some problems I had using discourse-settings-uploader, getting 301 errors:

./discourse-settings-uploader community.mysite.com 22f7d44321ae2365d3e3a5e9224524ba0e7302bd75ed06bfbh31ed5090ec6d3b system site-settings.json
SiteSettingtitle="Mysite"
E! 301 Moved Permanently

I get this error once for each setting. But I can browse the site successfully at those URLs. So I figured out - it’s going through http, and that is disabled.

So now I add https to my site name and I get a different error:

SiteSettingtitle="My sIte"
E! SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate)
something's wrong with https://community.mysite.com/admin/site_settings/title {"title"=>"Mysite", :api_key=>"22f7d44321ae2365d3e3a5e9224524ba0e7302bd75ed06bfbh31ed5090ec6d3b ec6d3b", :api_username=>"system"}

So this boils down to a deficient local configuration of root certificates, it seems. I could go off and waste an afternoon on this, but instead what I did was turn off verify_ssl. It’s very insecure and horrible things will happen to you and your children and your children’s children but for this case, I just didn’t care.

So in the uploader script I added this method:

def put_no_ssl(url, payload, headers={}, &block)
  RestClient::Request.execute(method: :put, url: url, :payload => payload, headers: headers, verify_ssl: false, &block)
end

And below, I changed the call from

r = RestClient.put(url, my_hash)

to

r = put_no_ssl(url, my_hash)

And it worked! :sunglasses:

3 个赞

:scream: :family_man_woman_girl_boy:

6 个赞

大家好,

我需要将生产环境的站点设置导出到预发布环境。我找到了 Discourse-Settings Uploader 的操作指南,并创建了一个包含设置的 JSON 文件,但无法导入它。我不知道在哪里可以运行以下命令:
./discourse-settings-uploader HOSTURL API_KEY API_USER SETTINGS_FILE
这是否需要在终端中执行?我的客户告诉我他们使用的是托管版的 Discourse,没有终端访问权限。这是什么意思?我该如何更好地解决这个问题?我对此还不太熟悉,所以需要大家的帮助。

提前感谢!

请查看 Backup only Site Settings - #5 by pfaffman GitHub 下载脚本,并确保已安装 Ruby。

6 个赞
rake site_settings:import < settings.yml

顺便提一下该命令的 Docker 版本:

d/rake "site_settings:import < settings.yml"

以防你遇到

The input device is not a TTY

的错误。

3 个赞

@pfaffman
我完全按照说明操作了:./discourse-settings-uploader https://discourse.example.com d35989078a system site_settings.json

但我的脚本运行失败了,我不确定原因和解决方法。
每个设置都返回了 E! 404 Not Found 错误。

@Ravi_Teja_Varma

我已移除了您的截图,因为它包含了您的 API 密钥。您可以添加另一张不包含敏感数据(或对敏感数据进行遮挡)的截图。鉴于该密钥已公开,您也应将其轮换,视其为已泄露。

感谢您的及时跟进。从今以后,我会注意此类做法。

如果您收到 404 错误,说明您的 API 密钥不正确,或者脚本无法找到它。

我已经检查过这一点,我所有的 API 都使用同一个密钥正常工作。
我确信脚本应该是在正确的位置查找,因为日志语句中显示的 URL 如下:

{url}/admin/site_settings/title  
{url}/admin/site_settings/site_description  

我已经从一个站点下载了 site_settings.json 文件,现在正尝试将这些设置推送到另一个已存在的站点(site2)。我是否需要对我下载的 site_settings.json 文件进行任何编辑?

奇怪。抱歉,但这已是我能提供的最佳免费建议。如果您有预算,可以给我留言。

如果您在两个站点上都采用自建部署,可以尝试使用一个 rake 任务。

我最近自己并没有使用那个脚本。也许是 Discourse 的某些内容发生了变化,但我不太这么认为。如果您确定使用的是目标站点的 API 密钥,那我就不敢妄加猜测了。

1 个赞

我尝试使用 rake site_settings:export > settings.yml。我注意到在 Discourse 服务器上配置的标签和标签组并未被导出。这是为什么呢?

标签就是标签,并非站点设置。据我所知,没有迁移标签的方法。

1 个赞

是否也可以导出 插件 主题组件的设置?

1 个赞