Skip to content

Commit ffccb8b

Browse files
author
willemvd
committed
prevent issues with restarting of pods and spam mailing in case of errors
1 parent 356dd6e commit ffccb8b

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ SMTP_AUTH_USER=<username to login to the SMTP server>
4141
SMTP_AUTH_PASSWORD=<password for the SMTP user>
4242
SMTP_FROM=<name and email of the sender in the format: Name <full email adres> >
4343
SMTP_TO=<email address to send to, multiple addresses can be used with a comma seperated list>
44+
45+
ALWAYS_EXIT_ZERO=<when true, always return 0 as exit code to prevent failure detection by other scripts (prevent restarts and spam mailing)>
4446
```

backup.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@
22

33
set -e
44

5+
handleFailureExitCode() {
6+
if [ "x$ALWAYS_EXIT_ZERO" = "xtrue" ]; then
7+
exit 0
8+
fi
9+
10+
# abort
11+
exit 1
12+
}
13+
514
handleError() {
615
MSG="Failed to run backup of database '$PGDATABASE' from '$PGHOST:$PGPORT/$PGDATABASE' with user '$PGUSER' to 's3://$S3_BUCKET_NAME/$BACKUP_TYPE/$BACKUP_FILE_NAME'"
716

17+
echo ${MSG}
18+
819
if [ "x$ENABLE_ERROR_MAIL" = "xtrue" ]; then
920

1021
OPTS=""
@@ -13,21 +24,17 @@ handleError() {
1324
fi
1425

1526
echo ${MSG} | \
16-
1727
mailx -v -s "$ERROR_MAIL_SUBJECT" \
1828
-S smtp="$SMTP_HOST:$SMTP_PORT" \
1929
${OPTS} \
2030
-S smtp-auth=$SMTP_AUTH \
2131
-S smtp-auth-user="$SMTP_AUTH_USER" \
2232
-S smtp-auth-password="$SMTP_AUTH_PASSWORD" \
2333
-r "$SMTP_FROM" \
24-
$SMTP_TO
25-
else
26-
echo ${MSG}
34+
$SMTP_TO || handleFailureExitCode
2735
fi
2836

29-
# abort
30-
exit 1
37+
handleFailureExitCode
3138
}
3239

3340
DATE=$(date +%Y-%m-%d-%H-%M-%S)

openshift-postgresql-s3-backup-scheduledJob.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ items:
3737
spec:
3838
# 30 minutes timeout
3939
activeDeadlineSeconds: 1800
40+
restartPolicy: OnFailure
4041
containers:
4142
- name: postgresql-s3-hourly-backup
4243
image: willemvd/postgresql-client-side-encrypted-s3-backup:1.1.0
@@ -100,7 +101,8 @@ items:
100101
value: ""
101102
- name: SMTP_TO
102103
value: ""
103-
restartPolicy: OnFailure
104+
- name: ALWAYS_EXIT_ZERO
105+
value: "true"
104106
- apiVersion: batch/v2alpha1
105107
kind: ScheduledJob
106108
metadata:
@@ -114,6 +116,7 @@ items:
114116
spec:
115117
# 30 minutes timeout
116118
activeDeadlineSeconds: 1800
119+
restartPolicy: OnFailure
117120
containers:
118121
- name: postgresql-s3-daily-backup
119122
image: willemvd/postgresql-client-side-encrypted-s3-backup:1.1.0
@@ -177,4 +180,5 @@ items:
177180
value: ""
178181
- name: SMTP_TO
179182
value: ""
180-
restartPolicy: OnFailure
183+
- name: ALWAYS_EXIT_ZERO
184+
value: "true"

0 commit comments

Comments
 (0)