aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Wilk <colin@wilk.cx>2026-06-22 15:15:42 +0200
committerColin Wilk <colin@wilk.cx>2026-06-22 15:15:42 +0200
commitdfeca121000dfc62f4337221ff35a48a4655580e (patch)
tree03b3fc909c7f123f372ce586fc886c474978a4ba
parent8d02cba3ed34c09b394dcca8bae8f2d36d513b2b (diff)
downloadansible-role-borgbackup-1.0.5.tar.gz
ansible-role-borgbackup-1.0.5.zip
Add option to configure SuccessExitStatusv1.0.5
Useful for letting systemd services not get marked as failed state when borg throws warnings. Keeping default to only accept exit code 0 as a successful state. Related: PR #2 https://github.com/kliwniloc/ansible-role-borgbackup/pull/2
-rw-r--r--defaults/main.yml18
-rw-r--r--templates/borg_backup.service.j24
2 files changed, 21 insertions, 1 deletions
diff --git a/defaults/main.yml b/defaults/main.yml
index c915ef9..c594c21 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -130,6 +130,24 @@ borg_backup_timer_name: borg_backup
# will be called {{ borg_backup_service_name }}@{{ borg_backup_argument }}
borg_backup_service_name: borg_backup
+# Includes a list of successful exit codes that are accepted as a successful
+# backup and not throw a systemd failure in addition to exit code 0.
+#
+# For borg specifically, you may want to ignore code 1 as it is a general
+# warning, not a failure of the backup. Be default however, since you should
+# check warnings on borg, we do fail the systemd service on exit code 1. You
+# can change that here. Full list of error codes that borg may return:
+# https://borgbackup.readthedocs.io/en/stable/usage/general.html#return-codes
+#
+# The list of axit codes will be appended in the systemd SiccessExitStatus
+# field separated by spaces, so that:
+# borg_backup_service_successful_exit_status: [TEMPFAIL, 250, SIGKILL]
+# will render to:
+# SuccessExitStatus=TEMPFAIL 250 SIGKILL
+# in the systemd service.
+# https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#SuccessExitStatus=
+borg_backup_service_successful_exit_status: []
+
# The backup argument is appended to systemd timer / systemd service and the
# backup script. It is used to distinguish backup targets from one another
# meaning it should be unique per target.
diff --git a/templates/borg_backup.service.j2 b/templates/borg_backup.service.j2
index 09cb23f..5bbd90f 100644
--- a/templates/borg_backup.service.j2
+++ b/templates/borg_backup.service.j2
@@ -7,7 +7,9 @@ Type=oneshot
ExecStart={{ borg_backup_script_location }}
User=root
Group=root
-SuccessExitStatus=1
+{% if borg_backup_service_successful_exit_status | length > 0 %}
+SuccessExitStatus={{ borg_backup_service_successful_exit_status | join(' ') }}
+{% endif %}
[Install]
WantedBy=multi-user.target