---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: duplicity
  namespace: backup
spec:
  # every Sunday @ 2AM
  schedule: "0 2 * * 0"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      completions: 1
      backoffLimit: 0
      template:
        metadata:
          labels:
            app: duplicity
        spec:
          # decide on this and keep it; duplicity will complain when you change it
          hostname: duplicity
          securityContext:
            fsGroup: 1000

          restartPolicy: Never
          containers:
            - name: duplicity
              image: intrand/duplicity-backup:latest
              imagePullPolicy: Always

              resources:
                requests:
                  cpu: "50m"
                  memory: "100Mi"
                limits:
                  cpu: "2000m"
                  memory: "500Mi"

              # env:
              #   - name: backup_gpg_public
              #     value: ""

              #   - name: backup_log_dir
              #     value: ""

              #   - name: backup_log_file
              #     value: ""

              #   - name: backup_source_baseDir
              #     value: ""

              #   - name: backup_dest_baseDir
              #     value: ""

              #   - name: backup_dest_proto
              #     value: "rsync"

              #   - name: backup_dest_user
              #     value: ""

              #   - name: backup_dest_host
              #     value: ""

              #   - name: backup_dest_host
              #     value: ""

              #   - name: backup_dest_port
              #     value: 22

              #   - name: backup_dest_uri
              #     value: ""

              #   - name: backup_directories
              #     value: ""

              #   - name: backup_full
              #     value: "false"

              #   - name: backup_args
              #     value: ""

              securityContext:
                runAsUser: 1000
                runAsGroup: 1000
                allowPrivilegeEscalation: false

              volumeMounts:
                - name: mydata
                  mountPath: /mnt/mydata

                - name: ssh
                  mountPath: /home/duplicity/.ssh

                - name: gnupg
                  mountPath: /home/duplicity/.gnupg

                - name: cache
                  mountPath: /home/duplicity/.cache/duplicity

                - name: config
                  subPath: backup.yml
                  mountPath: /opt/backup.yml

          # You will almost *certainly* need to customize this section yourself:
          volumes:
            # Directory containing the ssh key you want to use:
            - name: ssh
              hostPath:
                path: /home/user/.ssh

            # Directory containing your GPG keys used to encrypt your backup:
            - name: gnupg
              hostPath:
                path: /home/user/.gnupg

            # State tracking information for duplicity is kept here:
            - name: cache
              hostPath:
                path: /home/user/.cache/duplicity

            # Data you wish to backup:
            - name: mydata
              hostPath:
                path: /mnt/mydata

            # Your configuration file, if you're using one (you probably should):
            - name: config
              configMap:
                name: duplicity
                # octal UNIX permissions 0644 == 420 decimal notation
                defaultMode: 420
