mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2025-11-25 23:10:54 +00:00
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
This commit is contained in:
parent
3cde9a8893
commit
75295f95ac
@ -17,6 +17,11 @@ from utils import load_environment, shell, wait_for_service
|
|||||||
import operator
|
import operator
|
||||||
|
|
||||||
def backup_status(env):
|
def backup_status(env):
|
||||||
|
"""
|
||||||
|
TODO: Document what the return value actually is.
|
||||||
|
|
||||||
|
Will raise an exception if the call to the duplicity binary fails.
|
||||||
|
"""
|
||||||
# If backups are disabled, return no status.
|
# If backups are disabled, return no status.
|
||||||
config = get_backup_config(env)
|
config = get_backup_config(env)
|
||||||
if config["target"] == "off":
|
if config["target"] == "off":
|
||||||
@ -65,7 +70,7 @@ def backup_status(env):
|
|||||||
get_duplicity_target_url(config)
|
get_duplicity_target_url(config)
|
||||||
],
|
],
|
||||||
get_duplicity_env_vars(env),
|
get_duplicity_env_vars(env),
|
||||||
trap=True)
|
trap=True, capture_stderr=True)
|
||||||
if code != 0:
|
if code != 0:
|
||||||
# Command failed. This is likely due to an improperly configured remote
|
# Command failed. This is likely due to an improperly configured remote
|
||||||
# destination for the backups or the last backup job terminated unexpectedly.
|
# destination for the backups or the last backup job terminated unexpectedly.
|
||||||
|
|||||||
@ -266,26 +266,30 @@ def check_free_memory(rounded_values, env, output):
|
|||||||
def check_backup(rounded_values, env, output):
|
def check_backup(rounded_values, env, output):
|
||||||
# Check backups
|
# Check backups
|
||||||
backup_config = get_backup_config(env, for_ui=True)
|
backup_config = get_backup_config(env, for_ui=True)
|
||||||
|
|
||||||
# Is the backup enabled?
|
# Is the backup enabled?
|
||||||
if backup_config.get("target", "off") == "off":
|
if backup_config.get("target", "off") == "off":
|
||||||
output.print_warning("Backups are disabled. It is recommended to enable a backup for your box.")
|
output.print_warning("Backups are disabled. It is recommended to enable a backup for your box.")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
output.print_ok("Backups are enabled")
|
output.print_ok("Backups are enabled")
|
||||||
|
|
||||||
# Get the age of the most recent backup
|
# Get the age of the most recent backup
|
||||||
backup_stat = backup_status(env)
|
try:
|
||||||
|
backup_stat = backup_status(env)
|
||||||
|
except Exception as e:
|
||||||
|
output.print_error(f"Failed to obtain backup status: {e}")
|
||||||
|
return
|
||||||
|
|
||||||
backups = backup_stat.get("backups", {})
|
backups = backup_stat.get("backups", {})
|
||||||
if backups and len(backups) > 0:
|
if backups and len(backups) > 0:
|
||||||
most_recent = backups[0]["date"]
|
most_recent = backups[0]["date"]
|
||||||
|
|
||||||
# Calculate time between most recent backup and current time
|
# Calculate time between most recent backup and current time
|
||||||
now = datetime.datetime.now(dateutil.tz.tzlocal())
|
now = datetime.datetime.now(dateutil.tz.tzlocal())
|
||||||
bk_date = dateutil.parser.parse(most_recent).astimezone(dateutil.tz.tzlocal())
|
bk_date = dateutil.parser.parse(most_recent).astimezone(dateutil.tz.tzlocal())
|
||||||
bk_age = dateutil.relativedelta.relativedelta(now, bk_date)
|
bk_age = dateutil.relativedelta.relativedelta(now, bk_date)
|
||||||
|
|
||||||
if bk_age.days > 7:
|
if bk_age.days > 7:
|
||||||
output.print_error("Backup is more than a week old")
|
output.print_error("Backup is more than a week old")
|
||||||
else:
|
else:
|
||||||
@ -584,11 +588,11 @@ def check_dns_zone(domain, env, output, dns_zonefiles):
|
|||||||
continue
|
continue
|
||||||
# Choose the first IP if nameserver returns multiple
|
# Choose the first IP if nameserver returns multiple
|
||||||
ns_ip = ns_ips.split('; ')[0]
|
ns_ip = ns_ips.split('; ')[0]
|
||||||
|
|
||||||
# No need to check if we could not obtain the SOA record
|
# No need to check if we could not obtain the SOA record
|
||||||
if SOARecord == '[timeout]':
|
if SOARecord == '[timeout]':
|
||||||
checkSOA = False
|
checkSOA = False
|
||||||
else:
|
else:
|
||||||
checkSOA = True
|
checkSOA = True
|
||||||
|
|
||||||
# Now query it to see what it says about this domain.
|
# Now query it to see what it says about this domain.
|
||||||
@ -801,7 +805,7 @@ def check_mail_domain(domain, env, output):
|
|||||||
# Stop if the domain is listed in the Spamhaus Domain Block List.
|
# Stop if the domain is listed in the Spamhaus Domain Block List.
|
||||||
# The user might have chosen a domain that was previously in use by a spammer
|
# The user might have chosen a domain that was previously in use by a spammer
|
||||||
# and will not be able to reliably send mail.
|
# and will not be able to reliably send mail.
|
||||||
|
|
||||||
# See https://www.spamhaus.org/news/article/807/using-our-public-mirrors-check-your-return-codes-now. for
|
# See https://www.spamhaus.org/news/article/807/using-our-public-mirrors-check-your-return-codes-now. for
|
||||||
# information on spamhaus return codes
|
# information on spamhaus return codes
|
||||||
dbl = query_dns(domain+'.dbl.spamhaus.org', "A", nxdomain=None)
|
dbl = query_dns(domain+'.dbl.spamhaus.org', "A", nxdomain=None)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user