kind: CronJob
apiVersion: batch/v1beta1
metadata:
  name: couchbase-cluster-backup-create
spec:
  schedule: "*/5 * * * *"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            #Delete backup-with-periodic-merge script so that new one can be pulled with each run
            - name: delete-script
              image: couchbase/server:enterprise-6.5.0
              command: ["rm", "/backups/backup-with-periodic-merge.sh"]
              volumeMounts:
                - name: "couchbase-cluster-backup-volume"
                  mountPath: "/backups"
          initContainers:
            #Download the backup script from the git repo
            - name: wget-backup-script
              image: couchbase/server:enterprise-6.5.0
              command: ["wget", "https://raw.githubusercontent.com/couchbaselabs/cboperator-hol/master/eks/cb-operator-guide/files/sh/backup-with-periodic-merge.sh", "-P", "/backups/."]
              volumeMounts:
                - name: "couchbase-cluster-backup-volume"
                  mountPath: "/backups"
            #Change the mod of the backup script to execution
            - name: chmod-script
              image: couchbase/server:enterprise-6.5.0
              command: ["chmod", "700", "/backups/backup-with-periodic-merge.sh"]
              volumeMounts:
                - name: "couchbase-cluster-backup-volume"
                  mountPath: "/backups"
            #Run the script so it can do a) Backup b) Compaction c) Merge with each snapshot
            - name: periodic-merge
              image: couchbase/server:enterprise-6.5.0
              env:
                - name: RESTOREPOINTS
                  valueFrom:
                    configMapKeyRef:
                      name: cb-restore-points
                      key: restorepoints
                - name: CB_USERNAME
                  valueFrom:
                    secretKeyRef:
                      name: cb-auth
                      key: username
                - name: CB_PASSWORD
                  valueFrom:
                    secretKeyRef:
                      name: cb-auth
                      key: password
                - name: CLUSTER
                  valueFrom:
                    secretKeyRef:
                      name: cb-url
                      key: url
              command: ["/bin/sh", "-c" ,"/backups/backup-with-periodic-merge.sh"]
              volumeMounts:
                - name: "couchbase-cluster-backup-volume"
                  mountPath: "/backups"
          volumes:
            - name: couchbase-cluster-backup-volume
              persistentVolumeClaim:
                claimName: backup-pvc
          restartPolicy: Never