snapshot: preserve reliability hardening and Workdock identity pass
This commit is contained in:
@@ -12,6 +12,7 @@ from pathlib import Path
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
from django.utils.dateparse import parse_datetime
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from .models import WorkflowConfig
|
||||
@@ -113,6 +114,55 @@ def list_backup_bundles() -> list[dict]:
|
||||
return rows
|
||||
|
||||
|
||||
def latest_backup_health_snapshot(stale_after_hours: int = 48) -> dict:
|
||||
rows = list_backup_bundles()
|
||||
if not rows:
|
||||
return {
|
||||
'status': 'missing',
|
||||
'label': str(_('Kein Backup vorhanden')),
|
||||
'summary': str(_('Es wurde noch kein Backup-Bundle erstellt.')),
|
||||
'bundle_name': '',
|
||||
'is_stale': True,
|
||||
}
|
||||
|
||||
latest = rows[0]
|
||||
verified_at_raw = latest.get('verified_at') or ''
|
||||
verified_at = parse_datetime(verified_at_raw) if verified_at_raw else None
|
||||
if verified_at and timezone.is_naive(verified_at):
|
||||
verified_at = timezone.make_aware(verified_at, timezone.get_current_timezone())
|
||||
|
||||
if latest.get('verify_status') != 'verified' or not verified_at:
|
||||
return {
|
||||
'status': 'unverified',
|
||||
'label': str(_('Nicht verifiziert')),
|
||||
'summary': str(_('Das neueste Backup-Bundle wurde noch nicht erfolgreich verifiziert.')),
|
||||
'bundle_name': latest['name'],
|
||||
'verified_at': verified_at_raw,
|
||||
'is_stale': True,
|
||||
}
|
||||
|
||||
age = timezone.now() - verified_at
|
||||
is_stale = age.total_seconds() > stale_after_hours * 3600
|
||||
if is_stale:
|
||||
return {
|
||||
'status': 'stale',
|
||||
'label': str(_('Verifikation veraltet')),
|
||||
'summary': _('Die letzte erfolgreiche Backup-Verifikation ist älter als %(hours)s Stunden.') % {'hours': stale_after_hours},
|
||||
'bundle_name': latest['name'],
|
||||
'verified_at': verified_at_raw,
|
||||
'is_stale': True,
|
||||
}
|
||||
|
||||
return {
|
||||
'status': 'healthy',
|
||||
'label': str(_('Verifikation aktuell')),
|
||||
'summary': str(_('Das neueste Backup-Bundle wurde erfolgreich und rechtzeitig verifiziert.')),
|
||||
'bundle_name': latest['name'],
|
||||
'verified_at': verified_at_raw,
|
||||
'is_stale': False,
|
||||
}
|
||||
|
||||
|
||||
def _remote_backup_config() -> dict:
|
||||
config = WorkflowConfig.objects.filter(name='Default').order_by('-id').first() or WorkflowConfig.objects.order_by('id').first()
|
||||
if not config:
|
||||
@@ -264,8 +314,6 @@ def verify_backup_bundle(backup_name: str) -> dict:
|
||||
output=restore.stdout,
|
||||
stderr=restore.stderr,
|
||||
)
|
||||
with connection.cursor() as cursor:
|
||||
pass
|
||||
table_count = subprocess.check_output(
|
||||
['psql', *args, '-d', verify_db, '-t', '-A', '-c', "SELECT COUNT(*) FROM pg_tables WHERE schemaname='public';"],
|
||||
env=env,
|
||||
|
||||
Reference in New Issue
Block a user