Convert that nightly cron job to a systemd timer. Why would you?
IntermediateScenarioScheduling, automation and scripting
Answer
Situation read → Timers add logging, dependencies and catch-up runs.
What I'd do →
/etc/systemd/system/db-dump.service:
[Service]
Type=oneshot
User=postgres
ExecStart=/usr/local/bin/db-dump.sh
/etc/systemd/system/db-dump.timer:
[Timer]
OnCalendar=*-*-* 01:30:00
Persistent=true
RandomizedDelaySec=300
[Install]
WantedBy=timers.target
systemctl enable --now db-dump.timer, check with systemctl list-timers.
Why → Output goes to the journal, Persistent=true runs a missed job after downtime, and resource limits and OnFailure= alerts are available.
Interview tip → Validate calendar expressions with systemd-analyze calendar '*-*-* 01:30:00'.
More on Scheduling, automation and scripting
A database dump must run every night at 1:30 AM. How do you schedule it with cron so it is reliable?BeginnerA cron job runs every 5 minutes, but sometimes takes 8 minutes and two copies overlap, corrupting data. How do you prevent that?BeginnerYou have 300 servers running the same cron job at midnight, and they hammer a shared API. How do you fix it?IntermediateA job must run on the last day of every month. Cron has no "last day" field. What do you do?IntermediateYou inherited a server and need to know every scheduled job on it. Where do you look?BeginnerA one-off data fix must run at 9 PM tonight, just once. How do you schedule it?Beginner