azlin prune¶
Prune inactive VMs based on age and idle time.
Synopsis¶
Description¶
Identifies and optionally deletes VMs that are: - Older than --age-days (default: 1) - Idle for longer than --idle-days (default: 1) - Stopped/deallocated (unless --include-running) - Without named sessions (unless --include-named)
Options¶
| Option | Description | Default |
|---|---|---|
--resource-group, --rg TEXT | Resource group | current |
--config PATH | Config file path | - |
--age-days INTEGER | Age threshold in days | 1 |
--idle-days INTEGER | Idle threshold in days | 1 |
--dry-run | Preview without deleting | false |
--force | Skip confirmation | false |
--include-running | Include running VMs | false |
--include-named | Include named sessions | false |
-h, --help | Show help | - |
Examples¶
Preview what would be deleted¶
Delete VMs idle 1+ days (default)¶
Custom thresholds¶
Force delete without confirmation¶
Include running VMs¶
Output Example¶
VM Pruning Analysis
Scanning VMs...
Found 8 VMs
Candidates for deletion:
vm-test-123 Age: 5 days Idle: 3 days Status: Stopped
vm-temp-456 Age: 10 days Idle: 8 days Status: Stopped
vm-old-789 Age: 15 days Idle: 15 days Status: Stopped
Protected VMs:
vm-prod-1 Named session: "production"
vm-dev-main Active (last used 2 hours ago)
Total to delete: 3 VMs
Estimated savings: $45/month
Continue? [y/N]: y
Deleting VMs...
✓ Deleted vm-test-123
✓ Deleted vm-temp-456
✓ Deleted vm-old-789
Prune complete! 3 VMs deleted.
Protection Rules¶
VMs are protected if: - They have named sessions (unless --include-named) - They are running (unless --include-running) - They were used within idle threshold - They are tagged with critical=true or production=true
Use Cases¶
Regular cleanup¶
Pre-billing cleanup¶
# Last day of month
azlin prune --age-days 3 --idle-days 1 --dry-run
azlin prune --age-days 3 --idle-days 1
Development environment¶
Production (conservative)¶
Troubleshooting¶
No VMs deleted¶
Reasons: - All VMs are actively used - All VMs have named sessions - Thresholds too strict
Solution: Adjust thresholds or list VMs manually:
Important VM deleted¶
If a VM was accidentally deleted: 1. Restore from snapshot if available:
- Or recreate and sync:
Best Practices¶
-
Always dry-run first
-
Use named sessions for important VMs
-
Tag critical VMs
-
Regular automated cleanup
Related Commands¶
- azlin autopilot - Automated optimization
- azlin kill - Delete specific VM
- azlin killall - Delete all VMs
- azlin status - View VM activity