{{- if .Values.velero.backup.enabled }}
apiVersion: velero.io/v1
kind: Schedule
metadata:
  name: {{ include "portalmodelo.fullname" . }}-monthly
  namespace: {{ .Values.velero.namespace }}
spec:
  # generate a random backup time between 1 and 5 AM on first day of every month
  schedule: {{ mod (randNumeric 2) 60 }} {{ mod (randNumeric 1) 6 }} 1 * *
  template:
    includedNamespaces:
    - {{ .Release.Namespace }}
    {{- with .Values.velero.backup.excludedResources }}
    excludedResources:
      {{- toYaml . | nindent 8 }}
    {{- end }}
    snapshotVolumes: {{ .Values.velero.backup.snapshotVolumes }}
    # every weekday backup is good for the next year (365 days)
    ttl: 8760h0m0s
    defaultVolumesToRestic: {{ .Values.velero.backup.defaultVolumesToRestic }}
    hooks:
      resources:
      - name: repozo
        includedResources:
          - pods
        labelSelector:
          matchLabels:
              app.kubernetes.io/instance: {{ .Release.Name }}
              app.kubernetes.io/name: portalmodelo
              app.kubernetes.io/component: zeoserver
        pre:
          - exec:
              command: 
                - "/bin/bash"
                - "-c"
                - "/plone/Python-2.7/bin/python /plone/instance/bin/backup" 
              timeout: 3600s
              onError: Continue
  useOwnerReferencesInBackup: false
{{- end }}