Remove old backups based on retention policies defined in your configuration.
backitup cleanup [OPTIONS]| Option | Short | Description |
|---|---|---|
--config <path> |
-c |
Path to config file (default: ./backitup.config.yaml) |
--schedule <name> |
-s |
Only cleanup specific schedule |
--dry-run |
Preview deletions without removing files | |
--force |
Skip confirmation prompt | |
--verbose |
-v |
Enable verbose logging |
--help |
-h |
Show help message |
Each schedule defines its retention policy:
schedules:
hourly:
cron: "0 * * * *"
retention:
maxCount: 24 # Keep at most 24 backups
maxDays: 2 # Delete backups older than 2 daysA backup is deleted if it exceeds either limit:
- More than
maxCountbackups exist for the schedule - Backup is older than
maxDays
Cleanup includes multiple safety checks before deleting any file:
- Database verification - File must be tracked in BackItUp database
- Name pattern validation - Archive name must match BackItUp naming pattern
- Path validation - Local files must be within configured backup directory
- S3 validation - S3 keys must match configured bucket and prefix
- Checksum verification - File checksum must match database (if enabled)
Any file failing validation is skipped and reported.
# Cleanup all schedules (with confirmation)
backitup cleanup
# Preview what would be deleted
backitup cleanup --dry-run# Only cleanup hourly backups
backitup cleanup -s hourly
# Only cleanup daily backups
backitup cleanup -s daily# Skip confirmation (for cron jobs)
backitup cleanup --force
# Preview without prompts
backitup cleanup --dry-run --force◆ backitup cleanup
│
│ Found 3 backup(s) to delete:
│ • backitup_app_hourly_2024-01-13_100000_abc123.tar.gz (age limit)
│ • backitup_app_hourly_2024-01-13_110000_def456.tar.gz (age limit)
│ • backitup_app_hourly_2024-01-13_120000_ghi789.tar.gz (count limit)
│
◆ Delete 3 backup(s)?
│ ○ Yes ● No
◆ backitup cleanup
│
◇ Cleanup complete
│
│ Deletions:
│ [OK] backitup_app_hourly_2024-01-13_100000_abc123.tar.gz (age limit)
│ [OK] backitup_app_hourly_2024-01-13_110000_def456.tar.gz (age limit)
│ [OK] backitup_app_hourly_2024-01-13_120000_ghi789.tar.gz (count limit)
│
│ ┌─────────────────────────────────┐
│ │ Checked: 25 │
│ │ Deleted: 3 │
│ │ Skipped: 0 │
│ └─────────────────────────────────┘
│
◇ Cleanup complete!
│ Deletions:
│ [OK] backitup_app_hourly_2024-01-13_100000_abc123.tar.gz (age limit)
│ [FAILED] backitup_app_hourly_2024-01-13_110000_def456.tar.gz (age limit)
│ Checksum mismatch - file may have been modified
│
⚠ Some backups were skipped due to validation errors
When running backitup start, cleanup runs automatically after each scheduled backup. Manual cleanup is only needed for:
- Running cleanup outside the scheduler
- Cleaning up after manual backups
- Recovering from errors
Always use --dry-run first when cleaning up manually:
# See what would be deleted
backitup cleanup --dry-run
# Then actually delete
backitup cleanup- backup - Create backups
- start - Automatic cleanup with scheduler
- verify - Check backup integrity before cleanup
- Configuration Reference - Retention settings