Coder Social home page Coder Social logo

Comments (7)

BrianHenryIE avatar BrianHenryIE commented on June 6, 2024 4

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.

from ejectify-macos.

gagarine avatar gagarine commented on June 6, 2024 1

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"

from ejectify-macos.

nielsmouthaan avatar nielsmouthaan commented on June 6, 2024 1

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.

from ejectify-macos.

nielsmouthaan avatar nielsmouthaan commented on June 6, 2024

Thanks for the suggestion 👍.

from ejectify-macos.

vordenken avatar vordenken commented on June 6, 2024

This would be really great!

from ejectify-macos.

marcheimendinger avatar marcheimendinger commented on June 6, 2024

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

from ejectify-macos.

BrianHenryIE avatar BrianHenryIE commented on June 6, 2024

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

from ejectify-macos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.