Skip to content

Commit 3bda048

Browse files
Implement default snapshot retention limit of 5 snapshots
Co-authored-by: SomethingGeneric <[email protected]>
1 parent c8776c4 commit 3bda048

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ vmid = 200
198198
- Use `max_snapshots` to set a maximum number of automated snapshots per VM
199199
- When set, miniupdate will keep only the N newest snapshots and delete older ones
200200
- Useful for VMs on capacity-limited storage backends (e.g., small SSDs)
201-
- Takes precedence over the global `snapshot_retention_days` setting
202-
- If not set, the global time-based retention policy applies
201+
- Takes precedence over the default snapshot limit
202+
- **If not set, miniupdate defaults to keeping the 5 newest snapshots** to prevent unbounded growth
203+
- Time-based retention (`snapshot_retention_days`) provides additional cleanup after the count limit
203204

204205
### inventory.yml (Ansible Format)
205206

@@ -363,7 +364,8 @@ The `update` command provides a complete automated update workflow with Proxmox
363364
- `ping_timeout`: How long to wait for host availability (default: 2 minutes)
364365
- `snapshot_name_prefix`: Prefix for automated snapshots
365366
- `cleanup_snapshots`: Remove old snapshots after successful updates
366-
- `snapshot_retention_days`: Keep snapshots for N days
367+
- `snapshot_retention_days`: Time-based cleanup for snapshots older than N days
368+
- **Default snapshot limit**: Keeps 5 newest snapshots per VM (override with `max_snapshots` in vm_mapping.toml)
367369

368370
## Email Reports
369371

config.toml.example

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ ping_timeout = 120
3636
ping_interval = 5
3737
snapshot_name_prefix = "pre-update"
3838
cleanup_snapshots = true
39-
snapshot_retention_days = 7
40-
opt_out_hosts = []
39+
snapshot_retention_days = 7 # Time-based retention (applies after default snapshot count limit)
40+
opt_out_hosts = [] # Hosts to skip automated updates (check-only)
41+
# Note: By default, miniupdate keeps the 5 newest snapshots per VM to prevent unbounded growth
42+
# Override this per-VM using max_snapshots in vm_mapping.toml

miniupdate/update_automator.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -524,18 +524,26 @@ def _cleanup_old_snapshots(self, vm_mapping: VMMapping):
524524
logger.info(f"Per-host snapshot quota: keeping {vm_mapping.max_snapshots} newest snapshots "
525525
f"for VM {vm_mapping.vmid}, deleting {len(snapshots_to_delete)} older ones")
526526
else:
527-
# Fall back to time-based retention policy
528-
retention_days = self.update_config.get('snapshot_retention_days', 7)
529-
cutoff_time = datetime.now() - timedelta(days=retention_days)
530-
531-
snapshots_to_delete = [
532-
snap for snap in automated_snapshots
533-
if snap['time'] < cutoff_time
534-
]
527+
# Use default snapshot count limit to prevent unbounded growth
528+
default_max_snapshots = 5
529+
if len(automated_snapshots) > default_max_snapshots:
530+
snapshots_to_delete = automated_snapshots[default_max_snapshots:]
531+
logger.info(f"Default snapshot quota: keeping {default_max_snapshots} newest snapshots "
532+
f"for VM {vm_mapping.vmid}, deleting {len(snapshots_to_delete)} older ones")
535533

536-
if snapshots_to_delete:
537-
logger.info(f"Time-based retention: deleting {len(snapshots_to_delete)} snapshots "
538-
f"older than {retention_days} days for VM {vm_mapping.vmid}")
534+
# Also apply time-based retention if configured (for additional cleanup)
535+
if not snapshots_to_delete:
536+
retention_days = self.update_config.get('snapshot_retention_days', 7)
537+
cutoff_time = datetime.now() - timedelta(days=retention_days)
538+
539+
snapshots_to_delete = [
540+
snap for snap in automated_snapshots
541+
if snap['time'] < cutoff_time
542+
]
543+
544+
if snapshots_to_delete:
545+
logger.info(f"Time-based retention: deleting {len(snapshots_to_delete)} snapshots "
546+
f"older than {retention_days} days for VM {vm_mapping.vmid}")
539547

540548
# Delete the snapshots
541549
for snap in snapshots_to_delete:

0 commit comments

Comments
 (0)