a73x

deploy/server/backup-cronjob.yaml

Ref:   Size: 1.7 KiB   History

# Nightly dated sqlite backups onto the PVC. Applied only where BACKUPS=1:
# local-path storage does not survive the node, so the off-node copy pulled by
# backup-pull.sh is the real DR story and this is what it pulls.
apiVersion: batch/v1
kind: CronJob
metadata:
  name: eitri-server-backup
  namespace: ${NAMESPACE}
spec:
  schedule: "20 3 * * *"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: Never
          # The image moved from Docker Hub to the plane's own registry when
          # sqlite was baked into it, and a private registry needs the same
          # credential every other workload here pulls with. Without this the
          # job fails on ImagePullBackOff at 03:20 with nobody watching, which
          # is the failure mode baking sqlite in was meant to end.
          imagePullSecrets:
            - name: regcred
          nodeSelector:
            kubernetes.io/hostname: ${NODE_NAME}
          containers:
            - name: backup
              # sqlite is baked in (deploy/server/backup.Dockerfile). It used to
              # be installed on every run, which put a package CDN on the
              # critical path of the only copy of a database nobody can rebuild.
              image: ${BACKUP_IMAGE}
              command: ["/bin/sh", "-c"]
              args:
                - |
                  set -e
                  mkdir -p /data/backups
                  sqlite3 /data/eitri.db ".backup /data/backups/eitri-$(date +%F).db"
                  find /data/backups -name 'eitri-*.db' -mtime +14 -delete
              volumeMounts:
                - {name: data, mountPath: /data}
          volumes:
            - name: data
              persistentVolumeClaim: {claimName: ${PVC_NAME}}