I don’t know about timemachine but I have some anecdotal experience with Dropbox and ransomware. Essentially one person’s computer was infected which encrypted all the files for everyone in Dropbox. Because Dropbox had versioning on the files I was able to restore all the files back to the point before they were encrypted after removing and wiping the infected machines.
So if timemachine has versioning then maybe then you probably have some options, I’m not sure I’d call this being “safe” from ransomware.
So if timemachine has versioning then maybe then you probably have some options, I’m not sure I’d call this being “safe” from ransomware.