How macOS runs background activities: 2 Time Machine backups

Having shown and explained how a sample third-party activity is run in the background using Centralized Task Scheduling (CTS) and Duet Activity Scheduler (DAS), this article shows you how this is achieved for the most overt of all the macOS scheduled background tasks: Time Machine backups.

I have not yet analysed the exchanges which happen when Time Machine backups are first set up following startup, so this account details what happens when they are already up and running.

If you have turned off Time Machine backups and scheduled yours using a third-party utility, then they will be launched using the ‘old’ launchd mechanism and not the new system using DAS and CTS.

If your Time Machine is running normal hourly backups without any third-party interference, the making of those backups through the backupd-auto service will be one of the seventy-odd activities in the list kept by DAS. At fairly frequent intervals, it will have been rescored to see whether it should be run, according to the DAS heuristics. While its CurrentScore remains below the ThresholdScore, DAS will give it a DecisionToRun of 0, and it should not be run.

At approximately an hour (as long as seventy minutes or more) after the last backup started, one of these rescoring sessions will return a CurrentScore well above the ThresholdScore, and DAS will record a DecisionToRun of 1. Thus DAS will have decided that it should be run by CTS.

CTS then records that “DAS told us to run”. It may subsequently evaluate activities itself before making the state change in backupd-auto from 1 to 2. It next initiates XPC activity with the service, and runs backupd-auto. This in turn launches backupd itself, which does the heavy lifting for the backup proper.

Once the backup has completed, CTS changes the state of the backupd-auto service from 2 to 5, completes XPC activity, and completes DAS activity too. It then reschedules, submitting it as a DAS activity to be run in its future time window. That rescheduling is finally updated in DAS.

I have sketched this sequence out using Scapple again, in the following diagram:


and here as a PDF: GCD2

If you compare that diagram with my previous one showing my third-party activity using NSBackgroundActivityScheduler, you will notice that they are essential identical in all details. However, backupd-auto seems to have some additional options, such as “Dark-Wake Eligible”, which are not available to third-parties using NSBackgroundActivityScheduler. I suspect that Apple gives itself more extensive controls over options for background tasks.

This demonstrates that macOS and third-party background activities use the same mechanisms and systems within macOS.

Is Time Machine unusual?

On most of the occasions when I have seen DAS rescoring log entries, they have referred to between 70-80 activities in the macOS list, in Sierra. Many of those are seen to run quite regularly and fairly frequently. Those include:

  • metadata services from mds
  • iCloud through CloudKit services
  • Calendar synchronisation
  • Address Book synchronisation
  • suggestions services in parsecd and suggestd
  • Xcode services from DVTDownloadable Manager
  • security in the subsystem
  • help services
  • Safari SafeBrowsing updater.

I’m sure that more observation of DAS and CTS will reveal more of the seventy-odd activities which are poised in its to-do list.

It is, of course, perfectly possible from the interactions that I have shown in this and the previous article that I might have misinterpreted the relative roles of CTS and DAS. To examine that, in the next article I look at what happens when things go wrong.