Cron Schedules for Cleanup Jobs
Cleanup jobs prevent disk exhaustion, database bloat, and stale cache buildup that silently degrade performance. These expressions schedule log rotation, temp directory purges, session table pruning, and CDN cache invalidation at off-peak hours. The cron parser shows the next run times so you can ensure cleanups happen often enough to stay ahead of accumulation rates. Always test cleanup scripts on a small subset before scheduling them to run fully unattended.
Example
0 3 * * * 0 4 * * 0 0 1 1 * * 30 2 * * * 0 5 * * 6 */30 * * * * 0 0 * * * 0 6 1 1 *
FAQ
- How often should I rotate application logs?
- Daily rotation (0 3 * * *) works well for most applications. High-traffic services that generate gigabytes per day may need hourly rotation to keep individual log files manageable.
- When should I purge expired sessions from the database?
- Run session cleanup during off-peak hours, typically nightly at 2–4 AM. Ensure the cleanup query uses an index on the expiry column to avoid full table scans.
- Can I schedule an annual data archive?
- Yes. Use 0 6 1 1 * to run once per year on January 1st at 6 AM. Test this job manually before relying on it — an annual schedule is hard to validate automatically.
Related Examples
Cron Expressions for Database Backups
Backup scheduling is one of the most critical uses of cron in production systems...
Common Cron Schedule ExamplesCron expressions can be intimidating at first, but most production systems rely ...
Cron Schedules for Health ChecksUptime and health check jobs must run frequently enough to catch outages quickly...