From d4fcf9cf6b534b064d4626a2c702b6c05e50bea7 Mon Sep 17 00:00:00 2001 From: Fabio Kaiser Rauber Date: Wed, 11 Feb 2026 11:17:25 -0300 Subject: [PATCH] Add ScheduledBackup object to caduser --- charts/caduser/v0.1.0/questions.yaml | 12 +++++++ .../postgresql-scheduled-backup.yaml | 31 +++++++++++++++++++ charts/caduser/v0.1.0/values.yaml | 8 +++++ 3 files changed, 51 insertions(+) create mode 100644 charts/caduser/v0.1.0/templates/postgresql-scheduled-backup.yaml diff --git a/charts/caduser/v0.1.0/questions.yaml b/charts/caduser/v0.1.0/questions.yaml index cb3035a..603c12f 100644 --- a/charts/caduser/v0.1.0/questions.yaml +++ b/charts/caduser/v0.1.0/questions.yaml @@ -225,6 +225,18 @@ questions: - "snappy" - "none" required: false + - variable: postgresql.backup.schedule.immediate + default: true + description: "Executar backup imediato quando o ScheduledBackup for criado?" + label: "Backup Imediato" + type: boolean + required: false + - variable: postgresql.backup.schedule.cron + default: "0 0 2 * * *" + description: "Agendamento de backup em cron (segundo minuto hora dia mês dia-da-semana). Padrão: 2:00 AM diariamente" + label: "Agendamento (Cron)" + type: string + required: false # Memcached - variable: memcached.enabled diff --git a/charts/caduser/v0.1.0/templates/postgresql-scheduled-backup.yaml b/charts/caduser/v0.1.0/templates/postgresql-scheduled-backup.yaml new file mode 100644 index 0000000..739235f --- /dev/null +++ b/charts/caduser/v0.1.0/templates/postgresql-scheduled-backup.yaml @@ -0,0 +1,31 @@ +{{- if and .Values.postgresql.enabled .Values.postgresql.backup.enabled }} +apiVersion: postgresql.cnpg.io/v1 +kind: ScheduledBackup +metadata: + name: {{ .Values.postgresql.clusterName }}-scheduled-backup + namespace: {{ .Release.Namespace }} + labels: + {{- include "caduser.labels" . | nindent 4 }} +spec: + # Run an immediate backup when the ScheduledBackup is created + immediate: {{ .Values.postgresql.backup.schedule.immediate }} + + # Schedule backups using cron expression + schedule: {{ .Values.postgresql.backup.schedule.cron | quote }} + + # Use Barman Cloud plugin for backups + method: plugin + + # Configure the Barman Cloud plugin + pluginConfiguration: + name: barman-cloud.cloudnative-pg.io + parameters: + barmanObjectName: {{ .Values.postgresql.clusterName }} + + # Reference to the PostgreSQL cluster + cluster: + name: {{ .Values.postgresql.clusterName }} + + # Set the cluster as the owner of the backup resources + backupOwnerReference: cluster +{{- end }} diff --git a/charts/caduser/v0.1.0/values.yaml b/charts/caduser/v0.1.0/values.yaml index 443fe53..f6a3add 100644 --- a/charts/caduser/v0.1.0/values.yaml +++ b/charts/caduser/v0.1.0/values.yaml @@ -128,6 +128,14 @@ postgresql: data: compression: gzip jobs: 2 + + # Scheduled backup configuration + schedule: + # Run an immediate backup when the ScheduledBackup is created + immediate: true + # Cron schedule for regular backups (every day at 2 AM) + # Format: second minute hour day month day-of-week + cron: "0 0 2 * * *" memcached: enabled: true