Is it possible, after tuning Discourse on local computer, to export all settings into file and upload them into production?
Thanks.
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. ![]()
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
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
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! 
![]()
こんにちは、コミュニティの皆様
本番環境からステージング環境へサイト設定をエクスポートする必要があります。「Discourse-Settings Uploader」という手順を見つけ、設定を含む JSON ファイルを作成しましたが、それをインポートする手段がありません。このコマンドを実行できる場所がわかりません。
./discourse-settings-uploader HOSTURL API_KEY API_USER SETTINGS_FILE
ターミナル経由で実行する必要があるのでしょうか?クライアントからは、コミュニティ用の Discourse を利用しており、ターミナルへのアクセスがないと伝えられました。これはどういう意味でしょうか?この問題を解決するにはどうするのが最善でしょうか?私はこの分野にまだ慣れていないため、ご助力が必要です。
あらかじめありがとうございます。
Backup only Site Settings - #5 by pfaffman をご覧ください。GitHub からスクリプトをダウンロードし、Ruby をインストールする必要があります。
rake site_settings:import < settings.yml
Docker 版のコマンドも念のため記載します:
d/rake "site_settings:import < settings.yml"
もし以下のようなエラーが発生した場合です:
The input device is not a TTY
@pfaffman さん、こんにちは
指定された通りに試してみました:./discourse-settings-uploader https://discourse.example.com d35989078a system site_settings.json
しかし、スクリプトが失敗してしまい、その理由や方法がわかりません。
すべての設定に対して E! 404 Not Found が返ってきます。
API キーが含まれているため、スクリーンショットを削除しました。機密データが含まれていない、または隠されている別のスクリーンショットを追加してください。また、このキーは公開されてしまったため、侵害されたものとして扱う必要があります。キーのローテーション(再生成)も実施してください。
即座のフォローアップをありがとうございます。今後はそのような対応を心がけます。
404 エラーが表示される場合は、API キーが正しくないか、スクリプトがそれを検出できない場所に配置されています。
確認しました。すべての API が同じキーで動作しています。また、ログに以下のような URL が表示されているため、スクリプトが正しい場所を参照していると確信しています。
{url}/admin/site_settings/title
{url}/admin/site_settings/site_description
あるサイトから site_settings.json をダウンロードし、既存の site2 に設定をプッシュしようとしています。ダウンロードした site_settings.json に何か編集を加えるべきでしょうか?
奇妙ですね。申し訳ありませんが、これが無料で提供できる最善の回答です。予算がある場合は、メッセージをお送りください。
両方のサイトがセルフホストされている場合、試せるラケータスクがあります。
私は最近、そのスクリプトを使っていません。Discourse の何か変更があったのかもしれませんが、それは疑問です。書き込もうとしているサイトの API キーを確実に使用しているなら、私には推測もつきません。
rake site_settings:export > settings.ymlを実行しましたが、Discourseサーバーで設定していたタグやタググループがエクスポートされていないことに気づきました。その理由は何でしょうか?
タグはタグであり、サイト設定ではありません。タグの移行方法については存じ上げておりません。