Plan Django retention from snapshot records

This commit is contained in:
2026-05-19 11:24:48 +02:00
parent 659377d894
commit 254f915051
6 changed files with 405 additions and 84 deletions

View File

@@ -7,10 +7,8 @@ from typing import Any
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from pobsync.commands.retention_apply import run_retention_apply
from pobsync.commands.retention_plan import run_retention_plan
from pobsync_backend.config_source import DjangoConfigSource
from pobsync_backend.models import HostConfig
from pobsync.errors import ConfigError
from pobsync_backend.retention import run_sql_retention_apply, run_sql_retention_plan
class Command(BaseCommand):
@@ -27,29 +25,25 @@ class Command(BaseCommand):
def handle(self, *args: Any, **options: Any) -> None:
host = options["host"]
if not HostConfig.objects.filter(host=host, enabled=True).exists():
raise CommandError(f"Missing enabled HostConfig {host!r}")
config_source = DjangoConfigSource()
if options["apply"]:
if not options["yes"]:
raise CommandError("--yes is required with --apply")
result = run_retention_apply(
prefix=Path(options["prefix"]),
host=host,
kind=options["kind"],
protect_bases=bool(options["protect_bases"]),
yes=True,
max_delete=int(options["max_delete"]),
config_source=config_source,
)
else:
result = run_retention_plan(
prefix=Path(options["prefix"]),
host=host,
kind=options["kind"],
protect_bases=bool(options["protect_bases"]),
config_source=config_source,
)
try:
if options["apply"]:
if not options["yes"]:
raise CommandError("--yes is required with --apply")
result = run_sql_retention_apply(
prefix=Path(options["prefix"]),
host=host,
kind=options["kind"],
protect_bases=bool(options["protect_bases"]),
yes=True,
max_delete=int(options["max_delete"]),
)
else:
result = run_sql_retention_plan(
host=host,
kind=options["kind"],
protect_bases=bool(options["protect_bases"]),
)
except ConfigError as exc:
raise CommandError(str(exc)) from exc
self.stdout.write(json.dumps(result, indent=2, sort_keys=False))