Run Weekly Maintenance Tasks on Sunday | CronBase

cron expression Standard
$ 0 8 * * 0

Every Sunday morning at eight AM.

The `0 8 * * 0` cron expression schedules a task to execute every Sunday at exactly 8:00 AM. This weekly cadence is ideal for running low-traffic database backups, generating weekly performance reports, executing system updates, and conducting routine maintenance tasks without impacting standard weekday business operations.

Minute
0
Hour
8
Day of Month
*
Month
*
Day of Week
0

Next 5 Runs

  • in 1d 22h
  • in 8d 22h
  • in 15d 22h
  • in 22d 22h
  • in 29d 22h

* Tools

Code & Implementations

nodejs
// Node.js weekly cron implementation using 'node-cron'
// Run: npm install node-cron
const cron = require('node-cron');
const schedule = '0 8 * * 0'; // Sunday at 8:00 AM
console.log(`Initializing weekly cron worker on schedule: ${schedule}`);
cron.schedule(schedule, async () => {
    const timestamp = new Date().toISOString();
    console.log(`[${timestamp}] Weekly execution started.`);
    try {
        // Simulate production task (e.g., database cleanup or cache eviction)
        await performWeeklyCleanup();
        console.log(`[${timestamp}] Weekly execution completed successfully.`);
    } catch (error) {
        console.error(`[${timestamp}] Critical error during weekly execution:`, error);
        // In production, integrate with PagerDuty, Sentry, or Slack webhooks here
    }
}, {
    scheduled: true,
    timezone: "UTC" // Enforcing UTC prevents Daylight Saving Time shift issues
});
async function performWeeklyCleanup() {
    return Promise.resolve();
}
Setup notes

Install the required 'node-cron' package, save the file as 'scheduler.js', and run it using 'node scheduler.js' inside a process manager like PM2.

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

Systemd Timer

OnCalendarSun *-*-* 08:00:00

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

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

[Install]
WantedBy=timers.target

Frequently Asked Questions

How does Daylight Saving Time affect this Sunday 8 AM schedule?

Since the schedule runs at 8:00 AM, it is safely past the typical 2:00 AM DST shift. However, if your system clock shifts, the interval from the previous run may be 167 or 169 hours instead of 168. Ensure your cron daemon or scheduler is timezone-aware (using UTC is highly recommended) to avoid unexpected execution timing.

Is Sunday represented by 0 or 7 in standard cron systems?

In standard POSIX cron, 0 represents Sunday. However, many modern implementations (such as Vixie cron, BSD cron, and systemd) accept both 0 and 7 to represent Sunday. Using 0 is the most universally portable configuration across older legacy Unix environments.

What happens if the server is powered down at Sunday 8:00 AM?

Standard cron does not catch up on missed executions. If your server is offline at 8:00 AM on Sunday, the job will not run until the following Sunday. To mitigate this risk, use a utility like anacron for system tasks, or implement an external monitoring tool that alerts you when an expected weekly heartbeat is missed.

How should I handle long-running tasks scheduled at this time?

Since this job runs once a week, it has a large execution window before the next scheduled run. However, to prevent resource exhaustion or overlapping processes, wrap your script in a file lock utility like flock in Linux, or set a strict timeout within your application code.

Can I run this job on both Saturday and Sunday at 8:00 AM?

Yes, you can modify the day-of-week field to include both days. The expression '0 8 * * 0,6' or '0 8 * * 6-0' (depending on the parser) will trigger the execution at 8:00 AM on both Saturday (6) and Sunday (0), allowing you to run weekend-specific workflows.

* Explore

Related expressions you might need

Was this helpful?

Last verified: