Schedule Daily Maintenance Tasks at 2:00 AM | CronBase

cron expression Standard
$ 0 2 * * *

Every day at two o'clock in the morning.

This cron expression executes a scheduled task every single day at exactly two o'clock in the morning. It is widely used by system administrators and software engineers to run resource-intensive operations, such as database backups, system updates, and log rotations, during off-peak hours to minimize performance impact on active users.

Minute
0
Hour
2
Day of Month
*
Month
*
Day of Week
*
How it works

Next 5 Runs

  • in 5h 23m
  • in 1d 5h
  • in 2d 5h
  • in 3d 5h
  • in 4d 5h

* Tools

Code & Implementations

Bash
#!/usr/bin/env bash
# Daily backup script executed at 2:00 AM
set -euo pipefail
BACKUP_DIR="/var/backups/db"
LOG_FILE="/var/log/backup.log"
mkdir -p "$BACKUP_DIR"
echo "[$(date -u)] Starting daily backup..." >> "$LOG_FILE"
if pg_dump -U postgres prod_db > "$BACKUP_DIR/db_$(date +%F).sql"; then
    echo "[$(date -u)] Backup completed successfully." >> "$LOG_FILE"
else
    echo "[$(date -u)] Error: Backup failed!" >&2
    exit 1
fi
Setup notes

Add this script to your crontab by running crontab -e and appending: 0 2 * * * /usr/local/bin/backup.sh >> /var/log/cron_backup.log 2>&1.

Last verified:

Partner UptimeRobot

Keep this cron job monitored 24/7

UptimeRobot alerts you the moment a scheduled job stops responding. Free plan monitors up to 50 endpoints — no credit card required.

Platform Equivalents

AWS EventBridge

Standard cron expressions often need conversion for AWS EventBridge schedules.

EventBridge Rule
cron(0 2 * * ? *)

Systemd Timer

OnCalendar*-*-* 02:00:00

my-task.timer
[Unit]
Description=Timer for cron expression: 0 2 * * *

[Timer]
OnCalendar=*-*-* 02:00:00
Persistent=true

[Install]
WantedBy=timers.target

Last verified:

Frequently Asked Questions

How does Daylight Saving Time affect a cron job scheduled at 2:00 AM?

In local time zones, spring-forward transitions skip the 2:00 AM hour, causing the job to be missed. In autumn fall-back transitions, the 2:00 AM hour occurs twice, which might trigger the job twice. To prevent this, configure your servers and schedulers to use Coordinated Universal Time (UTC).

What is the best way to handle overlapping runs if the 2:00 AM job takes over 24 hours?

Use a locking mechanism like flock in Bash, a distributed lock manager like Redis (Redlock) in multi-node environments, or configure 'concurrencyPolicy: Forbid' in Kubernetes CronJobs to prevent a new instance from starting before the previous one completes.

How can I stagger multiple jobs that are all scheduled for 2:00 AM?

Avoid scheduling everything at exactly 2:00 AM to prevent resource spikes. You can stagger schedules (e.g., 2:00, 2:15, 2:30), add a randomized sleep delay (jitter) at the beginning of your scripts, or use a message-queue-driven system to process jobs sequentially.

Can I run this schedule on a specific day of the week or month instead of daily?

Yes. To run only on Sundays at 2:00 AM, use '0 2 * * 0'. To run only on the first day of every month at 2:00 AM, use '0 2 1 * *'. Modifying the fourth and fifth fields allows you to easily restrict the daily execution to specific dates.

How do I capture and monitor failures for a cron job running at 2:00 AM?

Redirect standard output and standard error to a log file or external log aggregator. Integrate alert triggers using tools like Prometheus, Sentry, or health check ping services (e.g., healthchecks.io) that alert you if the job fails to report completion within a specified window.

* Explore

Related expressions you might need

Last verified:

Was this helpful?