My Learning Journey
  • My Learning Journey
  • Timeline
    • 2024
      • August
        • August 08, 2024
        • August 09, 2024
        • August 10, 2024
        • August 11, 2024
        • August 12, 2024
        • August 19, 2024
      • November
        • November 26, 2024
      • December
        • December 13, 2024
        • December 21, 2024
Powered by GitBook
On this page
  • Things That I Discovered
  • 1. Prevent cronjobs from overlapping
  1. Timeline
  2. 2024
  3. December

December 13, 2024

PreviousDecemberNextDecember 21, 2024

Last updated 4 months ago

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:

    flock /var/lock/rclone-sync.lock -w 30 rclone sync <SOURCE> <DESTINATION>
  • 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 .

  • Reference(s):

Website
CleverUptime
Mattias Geniar Blog
Bashscript.net