Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Automatically unmount volume when Time Machine is done making a backup #19

Closed
marcheimendinger opened this issue Jan 30, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@marcheimendinger
Copy link

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).

@nielsmouthaan nielsmouthaan added the enhancement New feature or request label Feb 1, 2021
@nielsmouthaan
Copy link
Owner

Thanks for the suggestion 👍.

@vordenken
Copy link

This would be really great!

@BrianHenryIE
Copy link

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.

@marcheimendinger
Copy link
Author

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

@gagarine
Copy link

gagarine commented Jul 31, 2022

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"

@nielsmouthaan
Copy link
Owner

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 nielsmouthaan changed the title Manage Time Machine disk Automatically unmount volume when Time Machine is done making a backup Oct 19, 2022
@BrianHenryIE
Copy link

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants