apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: mysql-cron-backup
  namespace: fabricnlp
spec:
  #crontab schedule: https://crontab.guru
  # run every day at 1am
  schedule: "0 1 * * *"
  # run every 5 minutes
  # schedule: "*/5 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: mysql-cron-backup
            image: healthcatalyst/fabric.mysqlclient
            imagePullPolicy: Always  
            # # this overrides the CMD command in docker
            args: ["backup"]
            # environment variables
            env:
              - name: MYSQL_PASSWORD
                valueFrom:
                  secretKeyRef:
                    name: mysqlpassword
                    key: password
              - name: MYSQL_DATABASE
                # set the value of this environment variable directly
                value: nlpmt
              - name: MYSQL_USER
                value: NLP_APP_USER
              - name: MYSQL_SERVER
                value: mysqlserver
              - name: BACKUP_NAME_PREFIX
                value: "nlpsql"
            volumeMounts:
              - name: mysql-persistent-storage-backup
                # point the /var/lib/mysql folder inside the container to the volume called mysql-persistent-storage
                mountPath: /var/lib/mysql
                subPath: mysqlbackups              
          restartPolicy: OnFailure
          volumes:
          - name: mysql-persistent-storage-backup
            persistentVolumeClaim:
              claimName: nlp.mysqlbackup             
