Weekly Sunday Midnight Cron Schedule | CronBase

cron expression Standard
$ 0 0 * * 0

Every Sunday at midnight

The `0 0 * * 0` cron expression triggers a scheduled task weekly on Sundays at exactly midnight (00:00). This predictable, low-traffic time slot is widely utilized by systems administrators and DevOps teams for executing resource-intensive operations like full database backups, log rotations, SSL certificate renewals, and system cleanup scripts.

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

Next 5 Runs

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

* Tools

Code & Implementations

Bash
#!/usr/bin/env bash
# Weekly maintenance script designed to run via cron: 0 0 * * 0
set -euo pipefail

LOCKFILE="/var/lock/weekly-cleanup.lock"
LOGFILE="/var/log/weekly-cleanup.log"

# Ensure only one instance runs at a time
exec 9>"$LOCKFILE"
if ! flock -n 9; then
    echo "$(date -u) - ERROR: Another instance is already running." >&2
    exit 1
fi

echo "$(date -u) - Starting weekly database maintenance..." >> "$LOGFILE"
# Perform backup; redirect stderr to logfile
if pg_dump -U postgres -h localhost my_db > /backups/db_weekly_$(date +%F).sql 2>> "$LOGFILE"; then
    echo "$(date -u) - Weekly backup completed successfully." >> "$LOGFILE"
else
    echo "$(date -u) - CRITICAL: Weekly backup failed!" >&2
    exit 1
fi
Setup notes

Save the code as weekly-cleanup.sh, run chmod +x weekly-cleanup.sh, and add it to your crontab using crontab -e with the line: 0 0 * * 0 /path/to/weekly-cleanup.sh.

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 0 ? * 0 *)

Systemd Timer

OnCalendarSun *-*-* 00:00:00

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

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

[Install]
WantedBy=timers.target

Last verified:

Frequently Asked Questions

How does DST affect the Sunday midnight execution?

If your system runs on local time zones that observe Daylight Saving Time, the transition usually occurs on Sunday mornings (e.g., at 2:00 AM). While Sunday midnight (00:00) is before most DST transitions, some regions shift at midnight, causing the job to either run twice or skip. It is highly recommended to use UTC to avoid these issues.

How can I prevent multiple instances of this weekly cron from running simultaneously?

For standard Unix systems, wrap your script execution with the `flock` utility to enforce a file lock. In Kubernetes, set the `concurrencyPolicy` to `Forbid` within the CronJob specification. In application-level schedulers, use distributed lock managers like Redis (Redlock) or database-backed locks.

What is the best way to test a cron job scheduled for Sunday midnight?

You should decouple the execution logic from the schedule. Write your logic as a standalone script or command-line task, then manually trigger it in a staging environment. To test the cron configuration itself, temporarily change the expression to run every few minutes (e.g., `*/5 * * * *`) to verify the scheduler hooks work.

How do I handle failures in a weekly cron job without waiting another week?

Implement robust monitoring and alerting using tools like Prometheus Alertmanager or Sentry. If a job fails, the system must trigger an immediate notification to your on-call team. Ensure your architecture allows you to manually trigger the job on-demand to rerun failed operations safely.

Should I run database migrations on this Sunday midnight schedule?

While Sunday midnight has low traffic, using standard cron for database migrations is dangerous. Migrations should be tightly integrated with your deployment pipeline (CI/CD) and executed as pre-deployment or post-deployment steps with rolling updates, rather than decoupled time-based schedulers.

* Explore

Related expressions you might need

Last verified:

Was this helpful?