Cron Expression: Every Day at 2:00 AM (0 2 * * *)
Need to generate a cron expression?
Use CronOS to generate any cron expression you wish with natural language. Simply describe what you need, and we'll create the perfect cron expression for you. It's completely free!
Cron Expression: Every Day at 2:00 AM (0 2 * * *)
The cron expression 0 2 * * * executes a task every day at 2:00 AM, making it ideal for early morning maintenance, backups, and data processing tasks during low-traffic hours.
Expression Breakdown
0 2 * * *
│ │ │ │ │
│ │ │ │ └─── Day of week: * (every day)
│ │ │ └───── Month: * (every month)
│ │ └─────── Day of month: * (every day)
│ └───────── Hour: 2 (at hour 2, 2:00 AM)
└─────────── Minute: 0 (at minute 0)
Field Values
| Field | Value | Meaning |
|---|---|---|
| Minute | 0 | At minute 0 |
| Hour | 2 | At hour 2 (2:00 AM) |
| Day of Month | * | Every day (1-31) |
| Month | * | Every month (1-12) |
| Day of Week | * | Every day of week (0-7) |
Execution Time
This expression runs once per day at:
- 02:00 (2:00 AM)
Common Use Cases
1. Early Morning Backups
0 2 * * * /usr/local/bin/early-backup.sh
Create backups during early morning low-traffic hours.
2. Database Maintenance
0 2 * * * /usr/local/bin/db-maintenance.sh
Run database optimization, vacuum, or index maintenance.
3. Log Processing
0 2 * * * /usr/bin/python3 /scripts/process-logs.py
Process and analyze log files from the previous day.
4. Cache Refresh
0 2 * * * /usr/bin/python3 /scripts/refresh-cache.py
Refresh cached data, computed statistics, or pre-warm cache.
Example Implementations
Early Morning Backup Script
#!/bin/bash
# /usr/local/bin/early-backup.sh
BACKUP_DIR="/var/backups/early"
SOURCE_DIR="/var/data"
TIMESTAMP=$(date +%Y%m%d)
LOG_FILE="/var/log/backups.log"
mkdir -p $BACKUP_DIR
tar -czf "$BACKUP_DIR/backup_$TIMESTAMP.tar.gz" \
-C $(dirname $SOURCE_DIR) \
$(basename $SOURCE_DIR) >> $LOG_FILE 2>&1
find $BACKUP_DIR -name "*.tar.gz" -mtime +30 -delete
echo "$(date): Early morning backup completed" >> $LOG_FILE
Database Maintenance Script
#!/bin/bash
# /usr/local/bin/db-maintenance.sh
DB_NAME="app_db"
DB_USER="dbuser"
LOG_FILE="/var/log/db-maintenance.log"
# PostgreSQL maintenance
psql -U $DB_USER -d $DB_NAME -c "VACUUM ANALYZE;" >> $LOG_FILE 2>&1
# MySQL maintenance (alternative)
# mysql -u $DB_USER -p$DB_PASS $DB_NAME -e "OPTIMIZE TABLE important_table;" >> $LOG_FILE 2>&1
echo "$(date): Database maintenance completed" >> $LOG_FILE
Best Practices
- System Load: 2 AM is typically a low-traffic period
- Error Handling: Implement comprehensive error handling and logging
- Locking: Use file locks to prevent concurrent execution
- Monitoring: Set up alerts for failed jobs
- Resource Management: Monitor CPU, memory, and I/O usage
When to Use
✅ Good for:
- Early morning backups
- Database maintenance
- Log processing
- Cache refresh
- Heavy data processing
❌ Avoid for:
- Real-time critical operations
- Tasks requiring immediate execution
Related Patterns
| Pattern | Expression | Description |
|---|---|---|
| Daily at 1 AM | 0 1 * * * | One hour earlier |
| Daily at 2 AM | 0 2 * * * | Early morning |
| Daily at 6 AM | 0 6 * * * | Pre-dawn |
Conclusion
The 0 2 * * * expression is perfect for early morning maintenance tasks. It's commonly used for backups, database maintenance, and data processing during low-traffic hours when system resources are more available.
Need to generate a cron expression?
Use CronOS to generate any cron expression you wish with natural language. Simply describe what you need, and we'll create the perfect cron expression for you. It's completely free!