Discourse の自動バックアップを設定する

:bookmark: このガイドでは、ローカルサーバーおよびS3互換ストレージでのストレージオプションを含め、Discourseの自動バックアップを設定する方法を説明します。

Discourseプラットフォームの自動バックアップを設定する方法を学びましょう。

このガイドでは、自動バックアップの設定、ローカルサーバーまたはS3互換ストレージへの保存、Amazon Glacierなどのストレージ保持オプションの管理について説明します。

自動バックアップの設定

  1. /admin設定に移動します。
  2. Backupセクションを選択します。
  3. backup_frequencyを希望の間隔(日数)に設定します。デフォルトは7(週次)です。日次バックアップの場合は1に設定し、自動バックアップを無効にする場合は0に設定します。最大値は30です。

backup_frequencybackup_frequency100%75%50%

追加のバックアップ設定

  • backup_time_of_day — バックアップが実行される時刻(UTC)。デフォルト: 3:30
  • backup_with_uploads — スケジュールされたバックアップにアップロードを含めます。デフォルト: 有効。これを無効にすると、データベースのみがバックアップされます。
  • maximum_backups —保持するバックアップの最大数。古いバックアップは自動的に削除されます。デフォルト: 5
  • remove_older_backups — 指定された日数より古いバックアップを削除します。無効にする場合は空白のままにします。

バックアップをローカルサーバーに保存する

デフォルトでは、バックアップはローカルサーバーに保存されます。セルフホスト型インスタンスの場合、/var/discourse/shared/standalone/backups/defaultでアクセスできます。

バックアップをS3互換ストレージに保存する

管理パネルの使用

  1. S3バケットを作成します。
  2. 管理パネルでs3_backup_bucketを設定します。
  1. s3_access_key_ids3_secret_access_key、およびs3_regionを設定します。
  2. backup_locationを「S3」に設定します。

image

:warning: 警告

バックアップと通常のアップロードを同じバケット同じフォルダーに保存することは、もはやサポートされておらず、機能しません

s3_backup_bucketパスはバックアップ専用として使用する必要があります。他のファイルを含むバケットを使用する必要がある場合は、s3_backup_bucket設定でプレフィックス(例: my-awesome-bucket/backups)を指定し、そのプレフィックスを持つファイルがプライベートであることを確認してください。

これ以降、すべてのバックアップはS3にアップロードされ、ローカルには保存されなくなります。ローカルストレージは、バックアップと復元の間のテンポラリファイルにのみ使用されます。

管理ダッシュボードのBackupsタブに移動してバックアップを参照してください。いつでもダウンロードして手動でオフサイトバックアップを実行できます。

app.ymlで環境変数を使用する

app.ymlで環境変数を使用してS3バックアップを設定することもできます。詳細については、Configure an S3 compatible object storage provider for uploadsを参照してください。

上記の記事では、ファイル/画像アップロードとバックアップの両方でS3を設定するapp.ymlを扱っています。アップロード(ファイル/画像)用ではなく、バックアップ用にのみS3を使用したい場合は、app.yml設定から次のパラメーターを省略できます。

  • DISCOURSE_USE_S3
  • DISCOURSE_S3_CDN_URL
  • DISCOURSE_S3_BUCKET

この場合、after_assets_precompileステップを設定したり、CDNを設定したりする必要もありません。

記事で言及されているように、ストレージプロバイダーに必要な他のすべてのパラメーターを含めてください。S3をバックアップのみにアクティブにする場合の1つの設定例(Scaleway S3の場合)を次に示します。

DISCOURSE_S3_REGION: nl-ams
DISCOURSE_S3_ENDPOINT: https://s3.nl-ams.scw.cloud
DISCOURSE_S3_ACCESS_KEY_ID: my_access_key
DISCOURSE_S3_SECRET_ACCESS_KEY: my_secret_access_key
DISCOURSE_S3_BACKUP_BUCKET: my_bucket/my_folder
DISCOURSE_BACKUP_LOCATION: s3

低コストストレージへのアーカイブ

AWS S3では、S3バックアップコストを低く抑えるために、Glacierバケットへの自動移動のライフサイクルルールを有効にすることもできます。他のストレージプロバイダーも同様の機能を提供していることがよくあります。

「いいね!」 59

You are able to Archive Backups from your S3 Bucket to Glacier.
It is cheaper, but an Restore attemps more Time.

This Site will Help you to reduce Backup costs.:

「いいね!」 11

Setting this up can be rather confusing. Here’s a simple guide to help you out.

  • Log into your Discourse admin panel
  • Configure daily backups
  • Set maximum backups to 7
  • Log into your Amazon Web Services account
  • Go in the S3 Dashboard
  • Open the bucket containing the backups
  • Click on the properties tab
  • Activate versioning
  • Open the Lifecycle menu
  • Add a rule for the whole bucket
  • Set current version to expire after 15 days
  • Set previous version to
  • Archive to Glacier after 1 days
  • expire after 91 days
  • Save and logout

How it works

Versioning will keep backups automaticly deleted by Discourse. One day after beeing deleted it will be moved to the Glacier storage. After 91 days it will be delete from the Glacier storage.

Warning

Amazon charge you for item stored in Glacier for 90 days even if you delete them before. Make sure your Glacier Lyfecicle keep your file at least 90 days.

「いいね!」 11

I may have missed this, but how to I make sure a bucket for backups is private the proper way? Setting up file and image uploads to S3 doesn’t seem to be described here.

「いいね!」 1

Looks like there is no such option anymore.

UPD: ah, now it’s split into 2 steps of this wizard.

So I guess it should be like this:

「いいね!」 2

Does S3 backup functionality play nice without IAM access key and secret if using AWS roles assigned to the instance and s3 use iam profile is enabled in the settings menu?

Edit: The answer is YES! Just ensure you have region set appropriately.

「いいね!」 1

I had this problem too, which was resolved by adding a couple of lines to the policy document:

"Resource": [
        "arn:aws:s3:::your-uploads-bucket",
        "arn:aws:s3:::your-uploads-bucket/*",
        "arn:aws:s3:::your-backups-bucket",
        "arn:aws:s3:::your-backups-bucket/*"
      ]

Should this be added to the OP (which isn’t a wiki)? Or perhaps in the OP of Set up file and image uploads to S3?

「いいね!」 2

Is there a good reason not to make daily backups aren’t the default?

Fixes needed for OP

Add something about moving S3 backups to Glacier?
Delete the S3 stuff and link to Configure an S3 compatible object storage provider for uploads

It’d be overkill and expensive. Same reason we don’t recommend changing the oil in your car every 500 miles?

You back up your servers once a week?

I think your 500 mile oil change analogy would be a good answer for “why not keep 30 backups?”, but it doesn’t make sense to me here.

Do you not think that if you’re going to have 5 backups most people would rather have backups every day so that if they do have to revert to a backup they’ve lost no more than a day? The only time I remember an older backup being useful is when images fell out of tombstone.

If they have so little disk space that they can’t hold 5 backups, it would seem better to learn that in 5 days when they still have some memory of what they did than wait 4-5 weeks.

「いいね!」 1

Yes, that is correct, for my self hosted servers.

If you prefer different settings, feel free to edit them from the defaults. What’s stopping you from doing so?

「いいね!」 1

Well, I’ll be!

I’m cleaning up topics like this one. If the defaults were changed, it wouldn’t be needed!

I’m convinced that the defaults won’t be changed, so I’ll move ahead. :wink

「いいね!」 2

Once a week is a good starting point and a solid default.

「いいね!」 1

I had the very same problem!

i suggest to add a note regarding this on the initial post too!

「いいね!」 3

Would be nice if this could be used to upload to a different S3 compatible provider, such as running MinIO.

If you want to use minio, see Using Object Storage for Uploads (S3 & Clones). If you want different services for backups and assets then you’re out of luck (though there are ways to set up triggers to copy from one bucket 8 another)

No, just want for backups, so they get automatically pushed to a different machine on my network.

Then the guide I linked is what you’re looking for.

「いいね!」 1

Is it possible to be more frequent than once per day? I’d rather not make assumptions and set backup freqeuncy to a float

「いいね!」 1

If you want more frequent backups you’ll need to do them externally.

「いいね!」 3