December 13, 2024
Things That I Discovered
1. Prevent cronjobs from overlapping
I recently started running Systemd timer for a recurring task; rclone sync, and wanted bare minimum time to re-run it, but here comes a caveat, if the execution doesn't finish in time, a new task might be started, resulting in overlap, and if the task is handling data, say database for an example. That can lead to data loss/corruption. We can use
flock
command to overcome this.Example:
Here,
flock
command would check for a lock file at/var/lock/rclone-sync.lock
and wait for 30 seconds before it exits with an error if a lock file is found.Read more at my TIL Website.
Reference(s):
Last updated