Warn if a Time Machine backup is still in progress before shutting down or sleeping a Mac

Before I shut down or sleep my Mac, I want to be warned if a Time Machine backup is still in progress.

Is there such a thing? Or at least something that makes it very obvious that a backup is in progress, so that I avoid shutting down the machine before it is finished?

Right now the only visible sign that a backup is in progress is the little spinning circle up in the "task-bar", it's very easy to miss.

enter image description here

I searched but could not find a solution for this.


Solution 1:

You've asked what you want, but not why you want it. I am guessing that this is a preconception that you think it needs to complete in order to be successful. Time Machine isn't just a standard "backup job" that will create individual backups that depend on the success of each backup, it's more a permanent process.

Effectively each time you change a file, whether by addition or alteration of the contents or metadata, it gets added to the list of files that need to be backed up. The list grows and grows all the time, and it's built into the actions of the filesystem that whenever it makes a change, it also adds the file to the list. Every hour (or whatever you have set if you are using a non-standard config), Time Machine will start at the beginning of this list of changes, and start to plough through them and copy the changes to the backup disk. At the end of the process, when there are no more files to include in the backup, it stops.

But there is no need to wait for it to stop. If you have say 100 files in the queue, and it only processes 45.5 of them when you shut the machine down, the completed files are removed from the list only after Time Machine confirms they were completely backed up -- any partly-completed files will not be flagged as complete. Then, next time you boot up, wait another hour, the process will start again. You will have the 55 files that were not transferred last time at the front of the queue, followed by any other changes that have been made in the first place.

So, in summary, unlike a traditional backup which requires completion to ensure validity, the Time Machine backup is an ongoing process that can be interrupted at any time, and you do not have to wait for it to finish before shutting down. Indeed, if you are doing something disk intensive, feel free to temporarily turn Time Machine off or interrupt a backup that is in progress while you do stuff, then when you turn it back on it will just pick up where it left off.

Solution 2:

Time Machine is effectively a backup program. The program is a daemon called "backupd" that runs via an automated system job controlled by launchd.

When time machine is active there is an active "backupd" process running. Once the Time Machine process finishes, backupd needs a few minutes to close down and quit.

As for shutdown/logout, it's easy to write a script/program to check for the running process and throw up a warning.

Pre-sleep this is a little more difficult because there really isn't a simple sleep intercept like "Logout items"

For further information on the backupd task: Adjusting the Time Machine Backup Interval