Run Weekend Midnight Maintenance Tasks | CronBase

cron expression Standard
$ 0 0 * * 6,0

Every Saturday and Sunday at midnight.

This cron expression schedules a task to run at exactly midnight (00:00) every Saturday and Sunday. It is commonly used by system administrators and DevOps engineers to perform weekly maintenance, database optimization, and system backups during low-traffic weekend windows to avoid impacting production users.

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

Next 5 Runs

  • in 3h 33m
  • in 6d 3h
  • in 7d 3h
  • in 13d 3h
  • in 14d 3h

* Tools

Code & Implementations

Bash
#!/usr/bin/env bash
# Cron execution: 0 0 * * 6,0 (Midnight on Saturday and Sunday)
set -euo pipefail
LOCKFILE="/var/lock/weekend_maintenance.lock"
exec 9>"$LOCKFILE"
if ! flock -n 9; then
    echo "Error: Another instance of the weekend maintenance job is already running." >&2
    exit 1
fi
echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] Starting weekend maintenance..."
if ! tar -czf /backup/db_weekend_$(date +%F).tar.gz /var/lib/mysql; then
    echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] Backup failed!" >&2
    exit 1
fi
echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] Weekend maintenance completed successfully."
Setup notes

Save this script to /usr/local/bin/weekend-maint.sh, make it executable with chmod +x, and configure it under the root crontab using 'crontab -e'.

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

Systemd Timer

OnCalendarSat,Sun *-*-* 00:00:00

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

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

[Install]
WantedBy=timers.target

Last verified:

Frequently Asked Questions

Does standard cron treat 0 and 7 both as Sunday?

Yes, in most standard cron implementations (such as Vixie cron, commonly found in Linux), both 0 and 7 represent Sunday. However, to guarantee maximum portability across different systems and cloud platforms, using 0 is widely preferred.

What happens if Saturday's run takes longer than 24 hours to complete?

If Saturday's run exceeds 24 hours, Sunday's run will trigger while the previous execution is still active. To prevent race conditions and system overload, you should implement lock files, use `flock` in Bash, or set `concurrencyPolicy: Forbid` in Kubernetes.

How do daylight saving time (DST) transitions affect this midnight schedule?

If your system timezone is configured to a local timezone that observes DST, your job might run twice or be skipped entirely when clocks shift. To avoid this unpredictable behavior, it is highly recommended to configure your system or application schedulers to run strictly in UTC.

Can I target only Saturday instead of both weekend days?

Yes, if you want to run the job exclusively on Saturday, you can modify the day-of-week field to only include 6. The resulting cron expression would be `0 0 * * 6`.

Why is this schedule preferred over daily midnight maintenance?

Running tasks on weekends minimizes the risk of impacting active users, as standard business application traffic is typically at its lowest. This provides a safer window for executing heavy locking operations, schema migrations, or massive data aggregations that could degrade system performance during weekdays.

* Explore

Related expressions you might need

Last verified:

Was this helpful?