Saturday, November 23, 2024

applescript – Execute missed launchd job upon subsequent startup

I wish to make periodic backups utilizing rsnapshot on my MacBook. Nonetheless, as it’s a laptop computer, it would solely be powered on at random instances. Thus, scheduled duties could be missed whereas it’s powered off. An answer for this may be anacron which doesn’t appear to be accessible on macOS although. Apparently macOS’ native launchd service isn’t able to scheduling jobs within the method of anacron. Right here it says:

For those who schedule a launchd job by setting the StartCalendarInterval key
and the pc is asleep when the job ought to have run, your job will
run when the pc wakes up. Nonetheless, if the machine is off when
the job ought to have run, the job doesn’t execute till the subsequent
designated time happens. All different launchd jobs are skipped when the
pc is turned off or asleep; they won’t run till the subsequent
designated time happens.

If my month-to-month rsnapshot backup is, for instance, scheduled for the primary day of each month however the laptop computer is powered off that day, that may imply I lack that backup and solely get the subsequent one an entire month later.

Is there any workaround to this? Maybe linking the launchd schedule with some conditional instructions in a bash script?

The one thought I needed to clear up this was to schedule the launchd job for each single day at a selected time and execute a script which:

  1. Checks a timestamp log file if a profitable backup has run this month
  2. If sure –> exit, if no –> run backup
  3. If backup profitable –> add timestamp to that file

Although that appears unnecessarily complicated compared to anacron jobs that you could create on Unix programs.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles