Run Weekly Maintenance at 2 AM Sunday | CronBase

cron expression Standard
$ 0 2 * * 0

Every Sunday morning at two o'clock.

This cron expression schedules a task to run every Sunday at exactly 2:00 AM. It is widely utilized by system administrators for executing heavy weekly maintenance chores, such as database optimization, full system backups, log archiving, and software updates, during a period when user traffic and system load are typically at their lowest.

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

Next 5 Runs

  • in 5h 34m
  • in 7d 5h
  • in 14d 5h
  • in 21d 5h
  • in 28d 5h

* Tools

Code & Implementations

Bash
#!/bin/bash
# System backup script scheduled weekly on Sundays at 2:00 AM via crontab
set -euo pipefail

BACKUP_DIR="/var/backups/weekly"
LOG_FILE="/var/log/weekly_backup.log"

echo "[$(date -u)] Starting weekly system backup..." >> "$LOG_FILE"

# Ensure backup directory exists
mkdir -p "$BACKUP_DIR"

# Perform backup with error handling
if tar -czf "$BACKUP_DIR/backup-$(date +%F).tar.gz" /var/www /etc 2>> "$LOG_FILE"; then
    echo "[$(date -u)] Backup completed successfully." >> "$LOG_FILE"
else
    echo "[$(date -u)] ERROR: Backup failed!" >> "$LOG_FILE" >&2
    exit 1
fi
Setup notes

Add this script to your system and configure it in the user or system-wide crontab using crontab -e with the standard expression.

Last verified:

Partner BetterStack

Monitor this schedule in production

Get alerted the moment this cron job fails, is late, or doesn't run. BetterStack tracks execution, duration, and output — no infrastructure required.

Platform Equivalents

AWS EventBridge

Standard cron expressions often need conversion for AWS EventBridge schedules.

EventBridge Rule
cron(0 2 ? * 0 *)

Systemd Timer

OnCalendarSun *-*-* 02:00:00

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

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

[Install]
WantedBy=timers.target

Last verified:

Frequently Asked Questions

How does Daylight Saving Time affect a job scheduled for 2:00 AM on Sunday?

In regions observing Daylight Saving Time, the local clock jumps directly from 1:59 AM to 3:00 AM in the spring, which will cause your job to be skipped. In the autumn, the hour repeats, potentially triggering the job twice. To prevent this, always set your system timezone and cron daemon to UTC.

What is the best way to handle long-running tasks that exceed one week?

For tasks that might run longer than seven days, implement locking mechanisms (such as flock in Bash, redis-lock, or Kubernetes concurrencyPolicy: Forbid). This prevents a new instance of the job from starting while the previous week's run is still actively executing.

Can I use '7' instead of '0' for Sunday in this cron expression?

Yes, in standard and POSIX-compliant cron implementations, both 0 and 7 represent Sunday. However, to ensure maximum portability across different systems, platforms, and third-party libraries, using 0 is the widely accepted industry standard.

How can I test or dry-run this Sunday morning schedule immediately?

You can temporarily adjust the cron schedule to run every few minutes for testing, or execute the underlying script/command directly in your terminal. For testing the scheduler logic itself without waiting, use tools like `cron-parser` in Node.js or Python's mock library to simulate time-shifts.

How do I prevent CPU spikes if multiple weekly jobs are scheduled at 2:00 AM?

To avoid resource contention and CPU spikes, stagger your jobs by offsetting the minutes field (e.g., 0 2, 15 2, 30 2) or introduce a randomized sleep delay at the beginning of your script execution (e.g., `sleep $((RANDOM % 300))`).

* Explore

Related expressions you might need

Last verified:

Was this helpful?