# Phase 4: Retention & Cleanup **Status:** ⬜ Not Started **Parent plan:** [PLAN.md](./PLAN.md) **Domain:** backend ## Objective Implement automatic retention enforcement — prune old backups after each backup operation and on server startup. ## Tasks - [ ] Task 1: Add `Prune()` method to backup engine - Delete backups exceeding retention count (keep N most recent) - Return count of pruned backups - [ ] Task 2: Call Prune after every CreateBackup (both manual and auto) - [ ] Task 3: Call Prune on server startup - [ ] Task 4: Clean up orphaned files (files in backup dir not in metadata) - [ ] Task 5: Log pruning results ## Files to Modify/Create - `internal/backup/engine.go` — add Prune method - `cmd/server/main.go` — call prune on startup ## Acceptance Criteria - Backups exceeding retention count are automatically deleted - Both file and metadata are removed during pruning - Orphaned files (no metadata) are cleaned up - Pruning runs after each backup and on startup - Pruning results logged ## Handoff to Next Phase