Operationalize RC10 data retention
This commit is contained in:
@@ -9,13 +9,19 @@ from typing import Any
|
||||
|
||||
BACKEND_ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(BACKEND_ROOT))
|
||||
REPOSITORY_ROOT = BACKEND_ROOT.parent
|
||||
SCRIPTS_ROOT = REPOSITORY_ROOT / "scripts"
|
||||
if SCRIPTS_ROOT.is_dir():
|
||||
sys.path.insert(0, str(SCRIPTS_ROOT))
|
||||
|
||||
from app.core.config import get_settings
|
||||
from app.db.session import SessionLocal
|
||||
from app.models import Export, Project
|
||||
from release_backup_guard import require_confirmation, verify_current_backup
|
||||
|
||||
|
||||
DEMO_PROJECT_NAME = "GeoIntel Demo - Building QA"
|
||||
DELETE_CONFIRMATION = "DELETE_DEMO_EXPORTS"
|
||||
|
||||
|
||||
def is_within_storage_root(path: Path, storage_root: Path) -> bool:
|
||||
@@ -189,6 +195,21 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
help="Restrict cleanup to an export_type. Repeat for multiple types.",
|
||||
)
|
||||
parser.add_argument("--apply", action="store_true", help="Delete selected export rows and files.")
|
||||
parser.add_argument(
|
||||
"--backup-dir",
|
||||
type=Path,
|
||||
help="Recent checksum-verified release backup mounted read-only in the runtime.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--backup-max-age-hours",
|
||||
type=float,
|
||||
default=24.0,
|
||||
help="Maximum age accepted for the required release backup.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--confirm",
|
||||
help=f"Exact destructive-maintenance confirmation token: {DELETE_CONFIRMATION}",
|
||||
)
|
||||
return parser
|
||||
|
||||
|
||||
@@ -199,6 +220,17 @@ def main() -> int:
|
||||
parser.error("--keep-latest must be greater than or equal to zero")
|
||||
if args.max_delete < 0:
|
||||
parser.error("--max-delete must be greater than or equal to zero")
|
||||
if args.apply:
|
||||
try:
|
||||
require_confirmation(args.confirm, DELETE_CONFIRMATION)
|
||||
if args.backup_dir is None:
|
||||
raise RuntimeError("--backup-dir is required with --apply")
|
||||
verify_current_backup(
|
||||
args.backup_dir,
|
||||
max_age_hours=args.backup_max_age_hours,
|
||||
)
|
||||
except (RuntimeError, ValueError) as exc:
|
||||
parser.error(str(exc))
|
||||
|
||||
summary = cleanup_demo_exports(
|
||||
project_name=args.project_name,
|
||||
|
||||
Reference in New Issue
Block a user