Configurar backups automáticos para Discourse

:bookmark: Este guia explica como configurar backups automáticos para o Discourse, incluindo opções de armazenamento em servidores locais e armazenamento compatível com S3.

Aprenda a configurar backups automáticos para sua plataforma Discourse.

Este guia abrange a configuração de backups automáticos, seu armazenamento em servidores locais ou armazenamento compatível com S3, e o gerenciamento de opções de retenção de armazenamento como o Amazon Glacier.

Configurando backups automáticos

  1. Navegue até as configurações /admin.
  2. Selecione a seção Backup.
  3. Defina backup_frequency para o intervalo desejado em dias. O padrão é 7 (semanal). Defina como 1 para backups diários, ou 0 para desabilitar backups automáticos. O máximo é 30.

backup_frequencybackup_frequency100%75%50%

Configurações adicionais de backup

  • backup_time_of_day — a hora do dia (UTC) em que os backups são executados. Padrão: 3:30.
  • backup_with_uploads — inclui uploads nos backups agendados. Padrão: habilitado. Desabilitar isso fará backup apenas do banco de dados.
  • maximum_backups — o número máximo de backups a serem mantidos. Backups mais antigos são excluídos automaticamente. Padrão: 5.
  • remove_older_backups — remove backups mais antigos que o número de dias especificado. Deixe em branco para desabilitar.

Armazenar backups no servidor local

Por padrão, os backups são armazenados em seu servidor local. Para instâncias auto-hospedadas, acesse-os em /var/discourse/shared/standalone/backups/default.

Armazenar backups em armazenamento compatível com S3

Usando o painel de administração

  1. Crie um bucket S3.
  2. Defina s3_backup_bucket no painel de administração.
  1. Configure s3_access_key_id, s3_secret_access_key e s3_region.
  2. Defina backup_location como “S3”.

image

:warning: AVISO

Armazenar backups e uploads normais no mesmo bucket e pasta não é mais suportado e não funcionará.

O caminho s3_backup_bucket deve ser usado apenas para backups. Se você precisar usar um bucket que contenha outros arquivos, certifique-se de fornecer um prefixo ao configurar a configuração s3_backup_bucket (exemplo: meu-bucket-incrível/backups) e certifique-se de que os arquivos com esse prefixo estejam privados.

A partir de agora, todos os backups serão enviados para o S3 e não serão mais armazenados localmente. O armazenamento local será usado apenas para arquivos temporários durante backups e restaurações.

Acesse a guia Backups no painel de administração para navegar pelos backups – você pode baixá-los a qualquer momento para fazer um backup manual fora do local.

Usando variáveis de ambiente em app.yml

Você também pode configurar backups S3 usando variáveis de ambiente em app.yml. Para mais informações, consulte Configurar um provedor de armazenamento de objetos compatível com S3 para uploads

Observe que o artigo acima cobre a configuração S3 no app.yml para backups e para uploads de arquivos/imagens. Se você apenas deseja usar S3 para backups (e não para uploads de arquivos/imagens), então você pode omitir os seguintes parâmetros da sua configuração app.yml:

  • DISCOURSE_USE_S3
  • DISCOURSE_S3_CDN_URL
  • DISCOURSE_S3_BUCKET

Você também não precisa configurar a etapa after_assets_precompile neste caso, nem configurar uma CDN.

Certifique-se de incluir todos os outros parâmetros necessários para seu provedor de armazenamento, conforme mencionado no artigo. Aqui está um exemplo de configuração que ativa o S3 apenas para backups (para 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

Arquivamento para armazenamento com custo menor

Note que na AWS S3, você também pode habilitar uma regra de ciclo de vida de movimentação automática para o bucket Glacier para manter baixos os custos de backup do S3. Outros provedores de armazenamento geralmente têm uma oferta semelhante.

59 curtidas

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 curtidas

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 curtidas

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 curtida

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 curtidas

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 curtida

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 curtidas

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 curtida

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 curtida

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 curtidas

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

1 curtida

I had the very same problem!

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

3 curtidas

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 curtida

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 curtida

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

3 curtidas