Skip to content
Snippets Groups Projects
Verified Commit d86bf0e7 authored by Tom Teichler's avatar Tom Teichler :beers:
Browse files

Use seperate settings for db and media backup

parent eb80b193
No related branches found
No related tags found
1 merge request!495Resolve "Add health check for dbbackup"
Pipeline #6019 passed
......@@ -28,34 +28,36 @@ class BaseBackupHealthCheck(BaseHealthCheckBackend):
"""Common base class for backup age checks."""
critical_service = False
content_type = None
configured_seconds = None
def check_status(self):
storage = get_storage()
last_backup = storage.list_backups(content_type=self.content_type)[-1]
last_backup_time = dbbackup_utils.filename_to_date(last_backup)
time_gone_since_backup = last_backup_time - datetime.now()
backups = storage.list_backups(content_type=self.content_type)
if backups:
last_backup = storage.list_backups(content_type=self.content_type)[-1]
last_backup_time = dbbackup_utils.filename_to_date(last_backup)
time_gone_since_backup = last_backup_time - datetime.now()
# Check if backup is older than configured time
if time_gone_since_backup.seconds > settings.DBBACKUP_SECONDS:
self.add_error(_(f"Last backup {time_gone_since_backup}!"))
# Check if backup is older than configured time
if time_gone_since_backup.seconds > self.configured_seconds:
self.add_error(_(f"Last backup {time_gone_since_backup}!"))
else:
self.add_error(_("No backup found!"))
class DbBackupAgeHealthCheck(BaseBackupHealthCheck):
"""Checks if last backup file is less than configured seconds ago."""
content_type = "db"
def identifier(self):
return self.__class__.__name__
configured_seconds = settings.DBBACKUP_CHECK_SECONDS
class MediaBackupAgeHealthCheck(BaseBackupHealthCheck):
"""Checks if last backup file is less than configured seconds ago."""
content_type = "media"
def identifier(self):
return self.__class__.__name__
configured_seconds = settings.MEDIABACKUP_CHECK_SECONDS
class BackupJobHealthCheck(BaseHealthCheckBackend):
......@@ -64,13 +66,10 @@ class BackupJobHealthCheck(BaseHealthCheckBackend):
critical_service = False
def check_status(self):
task = TaskResult.objects.filter(task_name="aleksis.core.tasks.backup_data")
task = TaskResult.objects.filter(task_name="aleksis.core.tasks.backup_data").last()
# Check if state is success
if not task.last():
if not task:
self.add_error(_("No backup result found!"))
if task.last() and task.last().status != "SUCCESS":
self.add_error(_(f"{task.last().status} - {task.last().result}"))
def identifier(self):
return self.__class__.__name__
elif task and task.status != "SUCCESS":
self.add_error(_(f"{task.status} - {task.result}"))
......@@ -730,6 +730,7 @@ HEALTH_CHECK = {
"MEMORY_MIN": _settings.get("health.memory_min_mb", 500),
}
DBBACKUP_SECONDS = _settings.get("backup.seconds", 7200)
DBBACKUP_CHECK_SECONDS = _settings.get("backup.database.check_seconds", 7200)
MEDIABACKUP_CHECK_SECONDS = _settings.get("backup.media.check_seconds", 7200)
PROMETHEUS_EXPORT_MIGRATIONS = False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment