I would like to make periodic backups using rsnapshot on my MacBook. However, as it is a laptop, it will only be powered on at random times. Thus, scheduled tasks might be missed while it is powered off. A solution for this would be anacron which does not seem to be available on macOS though. Apparently macOS’ native launchd service is not capable of scheduling jobs in the manner of anacron. Here it says:
If you schedule a launchd job by setting the StartCalendarInterval key and the computer is asleep when the job should have run, your job will run when the computer wakes up. However, if the machine is off when the job should have run, the job does not execute until the next designated time occurs.
All other launchd jobs are skipped when the computer is turned off or asleep; they will not run until the next designated time occurs.
If my monthly rsnapshot backup is, for example, scheduled for the first day of every month but the laptop is powered off that day, that would mean I would not get the next monthly backup until one month later the earliest.
Is there any workaround to this? Perhaps linking the launchd schedule with some conditional commands in a bash script?
I think this functionality, or lack thereof, seems like a major shortcoming of launchd.
I thought about creating a launchd job that runs daily for a specific month which executes a script that then checks if a certain rsnapshot backup folder has been created (monthly.0, monthly.1, …) and only runs the rsnapshot backup if it does not exist. The problem is that after the first year these folders will all exist and just rotate through. So it would require some kind of timestamp as well. Such as “does folder exist” –> yes –> “is creation date < current date” –> yes –> run rsnapshot backup.
I am not sure how that could be implemented. And ideally there should be a much simpler solution anyway as with anacron for Unix systems.