{{- if .Values.pvcBackup.enabled -}} apiVersion: batch/v1 kind: CronJob metadata: name: {{ include "home-assistant.fullname" . }}-pvc-backup {{- if .Values.namespaceOverride }} namespace: {{ .Values.namespaceOverride }} {{- end }} labels: {{- include "home-assistant.labels" . | nindent 4 }} spec: schedule: {{ .Values.pvcBackup.schedule | quote }} jobTemplate: spec: template: spec: containers: - name: pvc-backup image: {{ .Values.pvcBackup.image }} command: - /bin/sh - -c - | set -e BACKUP_DIR="/backup/{{ include "home-assistant.fullname" . }}" TIMESTAMP=$(date +%Y%m%d-%H%M%S) mkdir -p "$BACKUP_DIR" # Create compressed tar of config PVC tar czf "$BACKUP_DIR/config-${TIMESTAMP}.tar.gz" -C /config . # Retention: Delete backups older than specified days find "$BACKUP_DIR" -name "config-*.tar.gz" -mtime +{{ .Values.pvcBackup.retentionDays }} -delete volumeMounts: - name: config mountPath: /config readOnly: true - name: backup-storage mountPath: /backup volumes: - name: config persistentVolumeClaim: claimName: {{ .Values.persistence.config.existingClaim | default (include "home-assistant.fullname" .) }} - name: backup-storage hostPath: path: {{ .Values.pvcBackup.storagePath }} type: DirectoryOrCreate restartPolicy: OnFailure {{- if .Values.pvcBackup.node }} affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - {{ .Values.pvcBackup.node }} {{- else }} {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 10 }} {{- end }} {{- with .Values.affinity }} affinity: {{- toYaml . | nindent 10 }} {{- end }} {{- end }} {{- with .Values.tolerations }} tolerations: {{- toYaml . | nindent 10 }} {{- end }} {{- end }}