ejectify-macos icon indicating copy to clipboard operation
ejectify-macos copied to clipboard

Manage Time Machine disk

Open marcheimendinger opened this issue 3 years ago • 5 comments

Time Machine disk is often a hard drive and when not backing up, it tends to make Finder lag when opening a new window if the disk was asleep. A useful option to solve this issue would be to auto-unmount the Time Machine disk while not used by the backupd task. And auto-mount it when needed (every hour, maybe this could be customisable in the utility).

marcheimendinger avatar Jan 30 '21 12:01 marcheimendinger

Thanks for the suggestion 👍.

nielsmouthaan avatar Feb 01 '21 19:02 nielsmouthaan

This would be really great!

vordenken avatar Nov 24 '21 07:11 vordenken

I was working on this today and have it working in principle.

I'm reading the output of /usr/bin/log stream --predicate 'subsystem == "com.apple.TimeMachine"' --info using a Process() and Pipe(), using regex to parse the log string, then firing a notification depending on the message content.

2022-05-21 19:28:21.720633-0700 0x10e421   Info        0x186886             75012  0    backupd: (TimeMachine) [com.apple.TimeMachine:General] Completed backup: 2022-05-21-192820
let logParserPattern = #"""
    (?<timestamp>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{6}-\d{4})
    \s+
    (?<thread>0x\w+)
    \s+
    (?<type>\w+)
    \s+
    (?<activity>0x\w+)
    \s+
    (?<pid>\d+)
    \s+
    (?<ttl>\d+)
    \s+
    (?<context>.*?)
    \s
    \[(?<namespace>.*?):(?<namespacecontext>.*?)\]
    \s+
    (?<message>.*)
"""#

I'm still figuring out how to handle "Cleaning Up..." ("thinning") which happens after the Completed backup log message.

2022-05-21 19:28:21.763071-0700 0x10e421   Info        0x186886             75012  0    backupd: (TimeMachine) [com.apple.TimeMachine:BackupThinning] Thinning 2 backups using age-based thinning, expected free space: 674.59 GB actual free space: 674.59 GB trigger 50 GB thin 83.33 GB dates: (
    "2022-05-21-172136",
    "2022-05-21-175757"
)

This doesn't seem to have an explicit "complete" log message but is usually followed by:

2022-05-21 19:35:09.029014-0700 0x10e421   Info        0x186886             75012  0    backupd: (TimeMachine) [com.apple.TimeMachine:General] Mountpoint '/Volumes/8tb' is still valid

but that message is also sometimes logged during cleanup.

So I think I'm going to use tmutil status when I see that to ensure Time Machine is really complete and the disk is really ready to unmount.

Backup session status:
{
    ClientID = "com.apple.backupd";
    Running = 0;
}

If anyone knows a real API I should be using for this (instead of parsing text logs and calling shell commands!) let me know.

I'll take another look at this soon and make a PR.

BrianHenryIE avatar May 22 '22 02:05 BrianHenryIE

Maybe you could have a look at how this tool is doing it: https://github.com/ProsoftEngineering/TimeMachineRemoteStatus

marcheimendinger avatar May 22 '22 14:05 marcheimendinger

tmutil let you know if a backup is running or not using tmutil status or tmutil currentphase.

Using tmutil listbackups list all backup made recently and tmutil latestbackup -t give you the date of the last one.

This allow to check if a backup was made recently and unmnunt the disk if that the case and no backup are running. To start the backup right after the disk is mounted tmutil startbackup.

ejectify could mount the disk every X hours and unmount the disk when the backup is done.

The settings could be like "Time Machine Backup" -> "every 1 hours", "every 6 hours", "every 12 hours", "every day"

gagarine avatar Jul 31 '22 09:07 gagarine

I'm closing this issue as I consider it out-of-scope for Ejectify. I would recommend reaching out to the developer behind TimeMachineEditor and asking if he could add a mechanism to automatically unmount the volume when Time Machine is done making a backup.

nielsmouthaan avatar Oct 19 '22 10:10 nielsmouthaan

I've been working on this more recently: BrianHenryIE/UnmountVolumeAfterTimeMachine

BrianHenryIE avatar Jun 12 '23 02:06 BrianHenryIE