Skip to content
CloudOps
Newsletter
All prompts
AI for Bash & Python Automation Difficulty: Advanced ClaudeCursor

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.
Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 1,603 DevOps AI prompts
  • One practical workflow email per week