Skip to content

Commit

Permalink
Add backup Cronjob
Browse files Browse the repository at this point in the history
Signed-off-by: Stephan Austermühle <[email protected]>
  • Loading branch information
stephan2012 committed Mar 3, 2024
1 parent 9851531 commit 370b130
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 3 deletions.
2 changes: 1 addition & 1 deletion charts/nextcloud/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: nextcloud
version: 4.6.3
version: 4.7.0-1
appVersion: 28.0.2
description: A file sharing server that puts the control and security of your own data back into your hands.
keywords:
Expand Down
20 changes: 20 additions & 0 deletions charts/nextcloud/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,23 @@ Create volume mounts for the nextcloud container as well as the cron sidecar con
subPath: {{ $key }}
{{- end }}
{{- end -}}

{{- define "nextcloud.backupCronJobVolumes" -}}
{{- if and .Values.persistence.nextcloudData.enabled .Values.persistence.enabled }}
- name: nextcloud-data
persistentVolumeClaim:
claimName: {{ if .Values.persistence.nextcloudData.existingClaim }}{{ .Values.persistence.nextcloudData.existingClaim }}{{- else }}{{ template "nextcloud.fullname" . }}-nextcloud-data{{- end }}
{{- end }}
{{- end -}}

{{- define "nextcloud.backupCronJobVolumeMounts" -}}
{{- if and .Values.persistence.nextcloudData.enabled .Values.persistence.enabled }}
- name: nextcloud-data
mountPath: {{ .Values.nextcloud.datadir }}
subPath: {{ ternary "data" (printf "%s/data" .Values.persistence.nextcloudData.subPath) (empty .Values.persistence.nextcloudData.subPath) }}
{{- else }}
- name: nextcloud-main
mountPath: {{ .Values.nextcloud.datadir }}
subPath: {{ ternary "data" (printf "%s/data" .Values.persistence.subPath) (empty .Values.persistence.subPath) }}
{{- end }}
{{- end -}}
31 changes: 31 additions & 0 deletions charts/nextcloud/templates/cronjobs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{- range .Values.nextcloud.backupCronjobs }}
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ template "nextcloud.fullname" $ }}-backup-{{ .name }}
spec:
schedule: {{ .schedule }}
startingDeadlineSeconds: {{ .startingDeadlineSeconds }}
concurrencyPolicy: {{ .concurrencyPolicy }}
successfulJobsHistoryLimit: {{ .successfulJobsHistoryLimit }}
suspend: {{ .suspend }}
jobTemplate:
{{/* Add the volumes */}}
{{- $volumeList := concat (default list .jobTemplate.spec.template.spec.volumes) (include "nextcloud.backupCronJobVolumes" $ | fromYamlArray) -}}
{{- $volumes := dict "spec" (dict "template" (dict "spec" (dict "volumes" $volumeList))) -}}
{{- $jobTemplate := merge $volumes .jobTemplate -}}

{{/* Add the volumeMounts to every container */}}
{{- $containers := list -}}
{{- range .jobTemplate.spec.template.spec.containers -}}
{{- $vm := concat (default list .volumeMounts) (include "nextcloud.backupCronJobVolumeMounts" $ | fromYamlArray) -}}
{{- $this := dict "volumeMounts" $vm -}}
{{- $containers = append $containers (merge $this .) -}}
{{- end -}}

{{- $newContainers := dict "spec" (dict "template" (dict "spec" (dict "containers" $containers))) -}}
{{- $jobTemplate = merge $newContainers $jobTemplate -}}

{{- $jobTemplate | toYaml | nindent 4 -}}
{{- end }}
37 changes: 35 additions & 2 deletions charts/nextcloud/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,48 @@ nextcloud:
# - name: nextcloud-data
# mountPath: /run/nextcloud/data

# Nextcloud data backup Cronjobs
# See https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/
backupCronjobs: []
# - name: backup
# schedule: "15 * * * *"
# concurrencyPolicy: Forbid
# startingDeadlineSeconds: 300
# successfulJobsHistoryLimit: 3
# suspend: true
# jobTemplate:
# spec:
# backoffLimit: 1
# ttlSecondsAfterFinished: 300
# template:
# spec:
# restartPolicy: OnFailure
# initContainers: []
# containers:
# - name: restic
# image: restic/restic:0.16.4
# imagePullPolicy: IfNotPresent
# command:
# - /bin/sh
# - -c
# - restic backup
# # volumeMounts:
# # - name: privatedir
# # mountPath: /srv/private
# # readOnly: false
# # volumes:
# # - name: privatedir
# # emptyDir: {}

# Extra mounts for the pods. Example shown is for connecting a legacy NFS volume
# to NextCloud pods in Kubernetes. This can then be configured in External Storage
extraVolumes:
extraVolumes: []
# - name: nfs
# nfs:
# server: "10.0.0.1"
# path: "/nextcloud_data"
# readOnly: false
extraVolumeMounts:
extraVolumeMounts: []
# - name: nfs
# mountPath: "/legacy_data"

Expand Down

0 comments on commit 370b130

Please sign in to comment.