| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- 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
- echo $? > /shared/exit-code
- EOF
- chmod +x /shared/wrapper.sh
- volumeMounts:
- - name: shared-data
- mountPath: /shared
- containers:
- - name: restic
- image: restic/restic:0.17.2
- command: ["/shared/wrapper.sh"]
- args: ["backup", "--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"
- if [ "$(cat /shared/exit-code)" -eq 0 ]; then
- STATUS="was successful"
- else
- STATUS="FAILED"
- fi
- curl -X POST -H "$AUTH_HEADER" -d "${MESSAGE} ${STATUS}." "$URL"
- 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
|