配置 Discourse 的自动备份

:bookmark: 本指南说明了如何为 Discourse 配置自动备份,包括在本地服务器和 S3 兼容存储上的存储选项。

了解如何为您的 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 存储桶 (bucket)。
  2. 在管理面板中设置 s3_backup_bucket
  1. 配置 s3_access_key_ids3_secret_access_keys3_region
  2. backup_location 设置为 “S3”。

image

:warning: 警告

将备份和常规上传存储在相同的存储桶和文件夹中已不再受支持,并且将无法工作

s3_backup_bucket 路径应用于备份。如果您需要使用包含其他文件的存储桶,请确保在配置 s3_backup_bucket 设置时提供一个前缀(示例:my-awesome-bucket/backups),并确保带有该前缀的文件是私有的。

从现在起,所有备份都将上传到 S3,而不再存储在本地。本地存储将仅用于备份和恢复期间的临时文件。

转到管理仪表板中的 Backups (备份) 选项卡以浏览备份——您可以随时下载它们以进行手动异地备份。

app.yml 中使用环境变量

您还可以使用 app.yml 中的环境变量配置 S3 备份。有关更多信息,请参阅 为上传配置 S3 兼容对象存储提供商

请注意,上述文章涵盖了 app.yml 中用于备份文件/图像上传的 S3 设置。如果您想将 S3 用于备份(而不是用于文件/图像上传),则可以从 app.yml 配置中省略以下参数:

  • DISCOURSE_USE_S3
  • DISCOURSE_S3_CDN_URL
  • DISCOURSE_S3_BUCKET

在这种情况下,您也无需配置 after_assets_precompile 步骤,也无需配置 CDN。

请确保包含您的存储提供商所需的所有其他参数,如文章所述。以下是一个仅激活 S3 备份的示例配置(针对 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 上,您还可以启用 Glacier 存储桶生命周期规则的自动迁移,以保持您的 S3 备份成本较低。其他存储提供商通常也有类似的服务。

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 个赞