mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 20:23:39 +09:00
The legacy per-instance backup script printed `echo DB_LIST=$(...)` instead of assigning DB_LIST, leaving it unset. The cleanup loop `for db in $DB_LIST` then ran zero iterations, so `restic forget` and `restic prune` never executed and snapshots accumulated in object storage indefinitely despite the configured cleanupStrategy. The Job still reported success, hiding the failure. Assign DB_LIST from the shuffled table list so the retention cleanup loop runs. Add a helm-unittest regression asserting the rendered backup.sh assigns DB_LIST and no longer contains the `echo DB_LIST=` typo. Fixes #3758 Assisted-By: Claude <noreply@anthropic.com> Signed-off-by: Alexey Artamonov <aleksei.artamonov@aenix.io>
62 lines
2.6 KiB
YAML
62 lines
2.6 KiB
YAML
{{/*
|
|
Legacy. Backup script Secret consumed by the chart-emitted CronJob in
|
|
backup-cronjob.yaml. Gated identically (including the `useSystemBucket`
|
|
exclusion) so the script is only materialised when the legacy CronJob
|
|
renders.
|
|
*/}}
|
|
{{- if and .Values.backup.enabled .Values.backup.schedule (not .Values.backup.useSystemBucket) }}
|
|
---
|
|
apiVersion: v1
|
|
kind: Secret
|
|
metadata:
|
|
name: {{ .Release.Name }}-backup-script
|
|
stringData:
|
|
backup.sh: |
|
|
#!/bin/sh
|
|
set -e
|
|
set -o pipefail
|
|
|
|
JOB_ID="job-$(uuidgen|cut -f1 -d-)"
|
|
TABLE_LIST=$(clickhouse-client --host "$CLICKHOUSE_HOST" -q 'SHOW TABLES;' | grep -v '^.inner.' || true)
|
|
DB_LIST=$(echo "$TABLE_LIST" | shuf) # shuffle list
|
|
echo "Job ID: $JOB_ID"
|
|
echo "Target repo: $REPO_PREFIX"
|
|
echo "Cleanup strategy: $CLEANUP_STRATEGY"
|
|
echo "Start backup for:"
|
|
echo "$TABLE_LIST"
|
|
echo
|
|
echo "Backup started at `date +%Y-%m-%d\ %H:%M:%S`"
|
|
for table in $TABLE_LIST; do
|
|
(
|
|
set -x
|
|
restic -r "s3:${REPO_PREFIX}/$table" cat config >/dev/null 2>&1 || \
|
|
restic -r "s3:${REPO_PREFIX}/$table" init --repository-version 2
|
|
restic -r "s3:${REPO_PREFIX}/$table" unlock --remove-all >/dev/null 2>&1 || true # no locks, k8s takes care of it
|
|
clickhouse-client --host "$CLICKHOUSE_HOST" -q "SHOW CREATE TABLE ${table}" | awk '{gsub(/\\n/, "\n")} {gsub(/\\'\''/, "'\''")} 1' | \
|
|
restic -r "s3:${REPO_PREFIX}/$table" backup --tag "$JOB_ID" --tag index --stdin --stdin-filename index.sql
|
|
clickhouse-client --host "$CLICKHOUSE_HOST" -q "SELECT * FROM ${table} FORMAT TabSeparated" | \
|
|
restic -r "s3:${REPO_PREFIX}/$table" backup --tag "$JOB_ID" --tag data --stdin --stdin-filename data.tsv
|
|
restic -r "s3:${REPO_PREFIX}/$table" tag --tag "$JOB_ID" --set "completed"
|
|
)
|
|
done
|
|
echo "Backup finished at `date +%Y-%m-%d\ %H:%M:%S`"
|
|
|
|
echo
|
|
echo "Run cleanup:"
|
|
echo
|
|
|
|
echo "Cleanup started at `date +%Y-%m-%d\ %H:%M:%S`"
|
|
for db in $DB_LIST; do
|
|
(
|
|
set -x
|
|
# keep completed snapshots only
|
|
restic forget -r "s3:${REPO_PREFIX}/$db" --group-by=tags --keep-tag "completed" --tag index
|
|
restic forget -r "s3:${REPO_PREFIX}/$db" --group-by=tags --keep-tag "completed" --tag data
|
|
restic forget -r "s3:${REPO_PREFIX}/$db" --group-by=tags $CLEANUP_STRATEGY --tag index
|
|
restic forget -r "s3:${REPO_PREFIX}/$db" --group-by=tags $CLEANUP_STRATEGY --tag data
|
|
restic prune -r "s3:${REPO_PREFIX}/$db"
|
|
)
|
|
done
|
|
echo "Cleanup finished at `date +%Y-%m-%d\ %H:%M:%S`"
|
|
{{- end }}
|