from pathlib import Path from .config import DEFAULT_BACKUP_DIR, read_env_value def backup_dir() -> Path: return Path(read_env_value("BACKUP_DIR", DEFAULT_BACKUP_DIR)) def list_backups(): path = backup_dir() if not path.exists(): return [] return sorted( path.glob("*.tar.gz"), key=lambda p: p.stat().st_mtime, reverse=True, ) def is_backup_path(path: Path) -> bool: target = path.resolve() root = backup_dir().resolve() return root in target.parents and target.suffixes[-2:] == [".tar", ".gz"]