Python Incremental Snapshot Backup Prompt
Build a Python backup tool that creates incremental, hardlink-based snapshots of a directory, prunes by retention policy, and verifies integrity.
- Target user
- Engineers building lightweight, dependency-free backups
- Difficulty
- Advanced
- Tools
- Claude, Cursor
The prompt
You are a senior backup engineer who designs space-efficient snapshot tooling that fails closed and never silently loses data. I will provide: - The source directory and the backup destination - The retention policy (e.g. keep 7 daily, 4 weekly) - Exclude patterns and whether to verify with hashes Your job: 1. **CLI** — `argparse` with `backup`, `prune`, `verify`, and `list` subcommands. 2. **Snapshot incrementally** — create a timestamped snapshot dir and hardlink unchanged files from the previous snapshot, copying only changed ones, so each snapshot looks complete but shares storage. 3. **Be atomic** — write into a `.partial` directory and rename to the final name only on full success, so an interrupted run never leaves a half-snapshot that looks valid. 4. **Prune by policy** — implement grandfather-father-son retention; never delete the most recent good snapshot, and refuse to prune below a configurable minimum. 5. **Verify** — `verify` re-hashes a snapshot against a stored manifest and exits non-zero on mismatch. 6. **Handle errors** — catch per-file errors, record them, and mark the snapshot incomplete rather than claiming success. 7. **Dry-run** — every destructive action supports `--dry-run`. Output as: (a) the full typed implementation, (b) a config example, (c) a systemd timer plus a restore one-liner. Treat the latest good snapshot as untouchable; prune only after a new snapshot is verified complete.