diff --git a/README.md b/README.md index b0c97d2..74a7046 100644 --- a/README.md +++ b/README.md @@ -41,4 +41,6 @@ SMTP_AUTH_USER= SMTP_AUTH_PASSWORD= SMTP_FROM= > SMTP_TO= + +ALWAYS_EXIT_ZERO= ``` diff --git a/backup.sh b/backup.sh index 6eb4184..070edd3 100644 --- a/backup.sh +++ b/backup.sh @@ -2,9 +2,20 @@ set -e +handleFailureExitCode() { + if [ "x$ALWAYS_EXIT_ZERO" = "xtrue" ]; then + exit 0 + fi + + # abort + exit 1 +} + handleError() { 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'" + echo ${MSG} + if [ "x$ENABLE_ERROR_MAIL" = "xtrue" ]; then OPTS="" @@ -13,7 +24,6 @@ handleError() { fi echo ${MSG} | \ - mailx -v -s "$ERROR_MAIL_SUBJECT" \ -S smtp="$SMTP_HOST:$SMTP_PORT" \ ${OPTS} \ @@ -21,13 +31,10 @@ handleError() { -S smtp-auth-user="$SMTP_AUTH_USER" \ -S smtp-auth-password="$SMTP_AUTH_PASSWORD" \ -r "$SMTP_FROM" \ - $SMTP_TO - else - echo ${MSG} + $SMTP_TO || handleFailureExitCode fi - # abort - exit 1 + handleFailureExitCode } DATE=$(date +%Y-%m-%d-%H-%M-%S) diff --git a/openshift-postgresql-s3-backup-scheduledJob.yaml b/openshift-postgresql-s3-backup-scheduledJob.yaml index 36f6476..1b6bbca 100644 --- a/openshift-postgresql-s3-backup-scheduledJob.yaml +++ b/openshift-postgresql-s3-backup-scheduledJob.yaml @@ -37,6 +37,7 @@ items: spec: # 30 minutes timeout activeDeadlineSeconds: 1800 + restartPolicy: OnFailure containers: - name: postgresql-s3-hourly-backup image: willemvd/postgresql-client-side-encrypted-s3-backup:1.1.0 @@ -100,7 +101,8 @@ items: value: "" - name: SMTP_TO value: "" - restartPolicy: OnFailure + - name: ALWAYS_EXIT_ZERO + value: "true" - apiVersion: batch/v2alpha1 kind: ScheduledJob metadata: @@ -114,6 +116,7 @@ items: spec: # 30 minutes timeout activeDeadlineSeconds: 1800 + restartPolicy: OnFailure containers: - name: postgresql-s3-daily-backup image: willemvd/postgresql-client-side-encrypted-s3-backup:1.1.0 @@ -177,4 +180,5 @@ items: value: "" - name: SMTP_TO value: "" - restartPolicy: OnFailure \ No newline at end of file + - name: ALWAYS_EXIT_ZERO + value: "true" \ No newline at end of file