---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: backup-test
  labels:
    app: backup-test
spec:
  suspend: false
  schedule: "*/10 * * * *"
  failedJobsHistoryLimit: 3
  successfulJobsHistoryLimit: 3
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          affinity:
            podAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                - labelSelector:
                    matchExpressions:
                      - key: app.kubernetes.io/name
                        operator: In
                        values:
                          - radarr
                  topologyKey: "kubernetes.io/hostname"
          restartPolicy: OnFailure
          dnsPolicy: ClusterFirst
          containers:
            - name: backup-test
              image: alpine
              imagePullPolicy: Always
              env:
                - name: KEEPFILES
                  value: "3"
                - name: TIMESTAMP
                  value: "date '+%Y%m%d%H%M%S'"
              volumeMounts:
                - mountPath: /mnt/persistentvolume/radarr
                  name: radarr
                - mountPath: /mnt/target
                  name: target
                - name: backupscript
                  mountPath: /script
              resources:
                limits:
                  memory: 1000Mi
                  cpu: 1000m
              command: ["/bin/sh"]
              args: ["/script/backup.sh"]
          volumes:
            - name: radarr
              persistentVolumeClaim:
                claimName: radarr-config
            - name: target
              nfs:
                server: 10.20.30.40
                path: "/volume1/Multimedia/backup"
            - name: backupscript
              configMap:
                name: script-configmap
