apiVersion: batch/v1
kind: Job
metadata:
  name: immich-db-nfs-to-longhorn
  namespace: immich
spec:
  backoffLimit: 2
  template:
    spec:
      restartPolicy: Never
      containers:
        - name: migrate-db
          image: alpine:3.20
          command:
            - sh
            - -c
            - |
              set -e
              apk add --no-cache rsync
              test -d /source/postgres
              mkdir -p /target/postgres
              rsync -aHAX --numeric-ids /source/postgres/ /target/postgres/
              test -f /target/postgres/PG_VERSION
              test -d /target/postgres/base
          volumeMounts:
            - name: source-nfs
              mountPath: /source
              readOnly: true
            - name: target-longhorn
              mountPath: /target
      volumes:
        - name: source-nfs
          nfs:
            server: 192.168.178.166
            path: /export/fastData/immichDB
        - name: target-longhorn
          persistentVolumeClaim:
            claimName: immich-db-pvc