# This is a template CronJob definition that can be used to create an entity
#   in Kubernetes that will rsync one directory to another.
# It creates a job that runs one rsync comment between two volumes of choice.
# Currently only supports NFS shares
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: ${CRONJOB_NAME}-backup
spec:
  schedule: "0 * * * *"
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 3
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: OnFailure
          imagePullSecrets: 
            - name: registry.internal.aleemhaji.com
          containers:
            - name: rsync
              image: registry.internal.aleemhaji.com/rsync:latest
              command:
                - sh
                - -cex
                - |
                  echo >&2 "/data/source is ${SOURCE_NFS_SERVER}:${SOURCE_NFS_SHARE}"
                  echo >&2 "/data/dest is ${DESTINATION_NFS_SERVER}:${DESTINATION_NFS_SHARE}"
                  rsync ${RSYNC_OPTIONS} "/data/source${SOURCE_PATH}" "/data/dest${DEST_PATH}"
              volumeMounts:
                - name: source
                  mountPath: /data/source
                - name: destination
                  mountPath: /data/dest
          volumes:
            - name: source
              nfs:
                server: ${SOURCE_NFS_SERVER}
                path: ${SOURCE_NFS_SHARE}
            - name: destination
              nfs:
                server: ${DESTINATION_NFS_SERVER}
                path: ${DESTINATION_NFS_SHARE}
