Clean Backups Command Options
Theclean-backups command deletes old backups while keeping the most recent ones. This helps manage disk space and maintain a clean backup directory.
Command Usage
Options
Specify the number of recent backups to keep. Older backups beyond this count will be deleted.Default: 10 backupsExample:
Skip confirmation prompt and proceed with the cleanup operation automatically. Useful for automated cleanup scripts.Aliases:
-yExample:How Clean Backups Works
The clean-backups command performs the following operations:- Lists all backups in the
.env-twin/directory - Sorts backups by timestamp (newest first)
- Identifies backups to keep based on the
--keepcount - Shows which backups will be deleted
- Prompts for confirmation (unless
--yesis used) - Deletes old backup directories
- Reports cleanup summary
Backup Retention Strategy
- Backups are sorted by timestamp, with the most recent first
- The
--keepcount determines how many of the most recent backups to retain - All backups older than the retention count are deleted
- If you have fewer backups than the
--keepcount, no backups are deleted
Usage Examples
Basic Cleanup (Keep 10 Most Recent)
Keep Only 5 Most Recent Backups
Keep 20 Backups
Cleanup Without Confirmation
Combined Options
Output Example
Best Practices
Recommended Retention Counts
- Development environments: 5-10 backups
- Production environments: 20-50 backups
- CI/CD pipelines: 3-5 backups
Automated Cleanup
For automated cleanup in CI/CD or cron jobs:Regular Maintenance
Set up a cron job or scheduled task for regular cleanup:Safety Features
- No backups deleted by default: If you have fewer backups than the
--keepcount, no action is taken - Confirmation prompt: By default, you’ll see which backups will be deleted and must confirm
- Detailed listing: Shows timestamp and files for each backup before deletion
- Summary report: Displays how many backups were deleted and kept