Skip to content

Commit 75295f9

Browse files
author
Anish Moorthy
committed
Catch and log any errors from backup_status() calls in status_checks.py
Duplicity seems to have pushed a broken release [1]. This doesn't fix that, but it unbreaks the status page (where the actual error can be read off). Side note: my editor seems to have stripped trailing whitespace on a couple of lines. Keeping it in the patch because I'm lazy [1] https://discourse.mailinabox.email/t/duplicity-error-nov-2025/16061/2
1 parent 3cde9a8 commit 75295f9

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

management/backup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
import operator
1818

1919
def backup_status(env):
20+
"""
21+
TODO: Document what the return value actually is.
22+
23+
Will raise an exception if the call to the duplicity binary fails.
24+
"""
2025
# If backups are disabled, return no status.
2126
config = get_backup_config(env)
2227
if config["target"] == "off":
@@ -65,7 +70,7 @@ def parse_line(line):
6570
get_duplicity_target_url(config)
6671
],
6772
get_duplicity_env_vars(env),
68-
trap=True)
73+
trap=True, capture_stderr=True)
6974
if code != 0:
7075
# Command failed. This is likely due to an improperly configured remote
7176
# destination for the backups or the last backup job terminated unexpectedly.

management/status_checks.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,26 +266,30 @@ def check_free_memory(rounded_values, env, output):
266266
def check_backup(rounded_values, env, output):
267267
# Check backups
268268
backup_config = get_backup_config(env, for_ui=True)
269-
269+
270270
# Is the backup enabled?
271271
if backup_config.get("target", "off") == "off":
272272
output.print_warning("Backups are disabled. It is recommended to enable a backup for your box.")
273273
return
274274
else:
275275
output.print_ok("Backups are enabled")
276-
276+
277277
# Get the age of the most recent backup
278-
backup_stat = backup_status(env)
279-
278+
try:
279+
backup_stat = backup_status(env)
280+
except Exception as e:
281+
output.print_error(f"Failed to obtain backup status: {e}")
282+
return
283+
280284
backups = backup_stat.get("backups", {})
281285
if backups and len(backups) > 0:
282286
most_recent = backups[0]["date"]
283-
287+
284288
# Calculate time between most recent backup and current time
285289
now = datetime.datetime.now(dateutil.tz.tzlocal())
286290
bk_date = dateutil.parser.parse(most_recent).astimezone(dateutil.tz.tzlocal())
287291
bk_age = dateutil.relativedelta.relativedelta(now, bk_date)
288-
292+
289293
if bk_age.days > 7:
290294
output.print_error("Backup is more than a week old")
291295
else:
@@ -584,11 +588,11 @@ def check_dns_zone(domain, env, output, dns_zonefiles):
584588
continue
585589
# Choose the first IP if nameserver returns multiple
586590
ns_ip = ns_ips.split('; ')[0]
587-
591+
588592
# No need to check if we could not obtain the SOA record
589593
if SOARecord == '[timeout]':
590594
checkSOA = False
591-
else:
595+
else:
592596
checkSOA = True
593597

594598
# Now query it to see what it says about this domain.
@@ -801,7 +805,7 @@ def check_mail_domain(domain, env, output):
801805
# Stop if the domain is listed in the Spamhaus Domain Block List.
802806
# The user might have chosen a domain that was previously in use by a spammer
803807
# and will not be able to reliably send mail.
804-
808+
805809
# See https://www.spamhaus.org/news/article/807/using-our-public-mirrors-check-your-return-codes-now. for
806810
# information on spamhaus return codes
807811
dbl = query_dns(domain+'.dbl.spamhaus.org', "A", nxdomain=None)

0 commit comments

Comments
 (0)