Download scripts/audit_backup.py from Stevesolun/ctx: direct link, hf CLI and curl.
- Browser
- Download file 2.95 kB
-
https://huggingface.co/datasets/Stevesolun/ctx/resolve/main/scripts/audit_backup.py
- Command line
-
hf download hf://datasets/Stevesolun/ctx/scripts/audit_backup.py
-
curl -L -o audit_backup.py https://huggingface.co/datasets/Stevesolun/ctx/resolve/main/scripts/audit_backup.py
2.95 kB
| """audit_backup.py -- Summarize a backup snapshot and flag what is missing.""" | |
| from __future__ import annotations | |
| import json | |
| import os | |
| import sys | |
| from collections import Counter | |
| from pathlib import Path | |
| CLAUDE_HOME = Path(os.path.expanduser("~/.claude")) | |
| BACKUPS = CLAUDE_HOME / "backups" | |
| USAGE = """usage: python scripts/audit_backup.py [SNAPSHOT] | |
| Summarize a backup snapshot and flag expected ~/.claude files missing from it. | |
| Arguments: | |
| SNAPSHOT Optional backup snapshot directory. Defaults to the latest | |
| directory under ~/.claude/backups. | |
| """ | |
| def latest_snapshot() -> Path: | |
| snaps = sorted(p for p in BACKUPS.iterdir() if p.is_dir()) | |
| return snaps[-1] | |
| def _snapshot_arg(argv: list[str]) -> Path: | |
| if len(argv) > 1 and argv[1] in {"-h", "--help"}: | |
| print(USAGE) | |
| raise SystemExit(0) | |
| return Path(argv[1]) if len(argv) > 1 else latest_snapshot() | |
| def main() -> int: | |
| snap = _snapshot_arg(sys.argv) | |
| manifest = json.loads((snap / "manifest.json").read_text(encoding="utf-8-sig")) | |
| print(f"snapshot: {snap}") | |
| print(f"entries: {len(manifest['entries'])}") | |
| total = sum((e.get("size") or 0) for e in manifest["entries"]) | |
| print(f"bytes: {total:,}") | |
| print("\n--- Top-level files ---") | |
| for e in manifest["entries"]: | |
| d = e["dest"] | |
| if "/" not in d and "\\" not in d: | |
| print(f" {d:<32} {e['size']:>8}B") | |
| print("\n--- Tree coverage ---") | |
| roots: Counter[str] = Counter() | |
| for e in manifest["entries"]: | |
| head = e["dest"].replace("\\", "/").split("/", 1)[0] | |
| roots[head] += 1 | |
| for root_name, count in roots.most_common(): | |
| print(f" {root_name:<32} {count:>5} files") | |
| # Audit what's in ~/.claude but NOT in the backup. | |
| print("\n--- Candidate files in ~/.claude NOT backed up ---") | |
| backed_up_sources = {Path(e["source"]).resolve() for e in manifest["entries"]} | |
| candidates = [ | |
| CLAUDE_HOME / "skill-system-config.json", | |
| CLAUDE_HOME / "intent-log.jsonl", | |
| CLAUDE_HOME / "skill-registry.json", | |
| CLAUDE_HOME / "CLAUDE.md", | |
| CLAUDE_HOME / "claude.json", | |
| CLAUDE_HOME / ".claude.json", | |
| ] | |
| for candidate in candidates: | |
| if candidate.is_file() and candidate.resolve() not in backed_up_sources: | |
| print(f" MISSING: {candidate} ({candidate.stat().st_size}B)") | |
| elif candidate.is_file(): | |
| print(f" OK: {candidate}") | |
| else: | |
| print(f" absent: {candidate}") | |
| # Also check common config locations. | |
| cfg_glob = list((CLAUDE_HOME).glob("*.json")) + list((CLAUDE_HOME).glob("*.md")) | |
| print("\n--- All top-level files in ~/.claude ---") | |
| for p in sorted(cfg_glob): | |
| in_backup = p.resolve() in backed_up_sources | |
| tag = "OK" if in_backup else "MISSING" | |
| print(f" [{tag:<7}] {p.name} ({p.stat().st_size}B)") | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |