apiVersion: batch/v1 kind: CronJob metadata: name: backup spec: schedule: "30 3 * * 1,3,5" jobTemplate: spec: template: spec: initContainers: - name: prepare-wrapper image: busybox command: ["/bin/sh", "-c"] args: - | cat > /shared/wrapper.sh << 'EOF' #!/bin/sh # Execute the original entrypoint with all arguments /usr/bin/restic "$@" # Capture the exit code EXIT_CODE=$? echo $EXIT_CODE > /shared/exit-code echo "Exit code is $EXIT_CODE" exit $EXIT_CODE EOF chmod +x /shared/wrapper.sh volumeMounts: - name: shared-data mountPath: /shared containers: - name: restic image: restic/restic:0.18.1 command: ["/shared/wrapper.sh"] args: ["backup", "--verbose", "--repo", "/data/repo", "--insecure-no-password", "/data/glusterfs"] imagePullPolicy: IfNotPresent volumeMounts: - name: restic-repo-vol mountPath: /data/repo - name: backup-data-vol mountPath: /data/glusterfs - name: shared-data mountPath: /shared - name: notify image: curlimages/curl command: ["/bin/sh"] args: - -c - | while [ ! -f /shared/exit-code ]; do sleep 1; done AUTH_HEADER="Authorization: Bearer tk_up3glyzhhojl1w5lt32jq5vqjzdgb" URL="http://ntfy/backup" MESSAGE="Local restic backup" EXIT_CODE=$(cat /shared/exit-code) echo "Captured exit code is $EXIT_CODE" if [ "$EXIT_CODE" -eq 0 ]; then STATUS="was successful" else STATUS="FAILED" fi curl -X POST -H "$AUTH_HEADER" -d "${MESSAGE} ${STATUS}." "$URL" exit $EXIT_CODE volumeMounts: - name: shared-data mountPath: /shared volumes: - name: restic-repo-vol hostPath: path: /data/backup type: Directory - name: backup-data-vol hostPath: path: /mnt type: Directory - name: shared-data emptyDir: {} restartPolicy: Never nodeSelector: kubernetes.io/hostname: raspberrypi4