apiVersion: batch/v1
kind: Job
metadata:
  generateName: mysql-restore-job-${MYSQL_DATABASE_NAME}-
spec:
  template:
    spec:
      restartPolicy: Never
      imagePullSecrets:
        - name: registry.internal.aleemhaji.com
      containers:
        - name: mysql-restore
          image: registry.internal.aleemhaji.com/mysql:5.7.26
          command:
            - sh
            - -c
            - find restore/${MYSQL_DATABASE_NAME} -iname *.sql -print | while read filename; do mysql -h ${MYSQL_HOST} -u root --database=${MYSQL_DATABASE_NAME} < $filename; done
          env:
            - name: MYSQL_PWD
              valueFrom:
                secretKeyRef:
                  name: mysql-root-password
                  key: value
            - name: MYSQL_HOST
              value: mysql
          volumeMounts:
            - name: mysql-restore-storage
              mountPath: /restore
      volumes:
        - name: mysql-restore-storage
          nfs:
            server: 192.168.96.4
            path: /mnt/dump/mysql-restore
