瀏覽代碼

Fixing backup jobs' exit code handling

bodicsek 1 年之前
父節點
當前提交
5ac5b2e829
共有 2 個文件被更改,包括 21 次插入5 次删除
  1. 10 2
      backup.cronjob.yaml
  2. 11 3
      backup.remote.cronjob.yaml

+ 10 - 2
backup.cronjob.yaml

@@ -19,7 +19,10 @@ spec:
               # Execute the original entrypoint with all arguments
               /usr/bin/restic "$@"
               # Capture the exit code
-              echo $? > /shared/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:
@@ -49,14 +52,19 @@ spec:
               AUTH_HEADER="Authorization: Bearer tk_up3glyzhhojl1w5lt32jq5vqjzdgb"
               URL="http://ntfy/backup"
               MESSAGE="Local restic backup"
+              EXIT_CODE=$(cat /shared/exit-code)
 
-              if [ "$(cat /shared/exit-code)" -eq 0 ]; then
+              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

+ 11 - 3
backup.remote.cronjob.yaml

@@ -49,7 +49,10 @@ spec:
               # Execute the original entrypoint with all arguments
               /usr/local/bin/rclone "$@"
               # Capture the exit code
-              echo $? > /shared/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:
@@ -82,15 +85,20 @@ spec:
               
               AUTH_HEADER="Authorization: Bearer tk_up3glyzhhojl1w5lt32jq5vqjzdgb"
               URL="http://ntfy/backup"
-              MESSAGE="Remote restic backup"
+              MESSAGE="Remote rclone restic repo backup"
+              EXIT_CODE=$(cat /shared/exit-code)
 
-              if [ "$(cat /shared/exit-code)" -eq 0 ]; then
+              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