apiVersion: batch/v1
kind: Job
metadata:
  name: mysql-backup-onetime
  namespace: fabricnlp 
spec:
  template:
    spec:
      containers:
      - name: mysql-backup-onetime
        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: Never
      volumes:
      - name: mysql-persistent-storage-backup
        persistentVolumeClaim:
          claimName: nlp.mysqlbackup             
  # job failures: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/
  backoffLimit: 1