Cute Locks; Public Domain; openclipart.org
Cute Locks; Public Domain; openclipart.org

I fixed it!

So, I’ve been having the issue of Time Machine backups silently failing. I tried all the troubleshooting steps. After nothing working, I wiped the backup drive and tried to start fresh. Somehow, things got worse. Rather than failing, backups would now go on in an endless loop, backing up terabytes of data (my MacBook only has 1 TB, and my backup drive 2 TB), so, it went beyond what was even there, and then would start over. You could see the backup drive being filled in terms of capacity, but nothing was actually shown in Finder.

I did check the logs in the past, [see how] but today I gave it another shot, maybe I’d see something this time!

I noticed a bunch of Failed to acquire device lock assertion for [some path here] Error Domain=NSPOSIXErrorDomain Code=22 "Invalid argument

So, I tried to filter the logs for these specific errors like this:

log show --info --style compact --predicate '(subsystem == "com.apple.TimeMachine") && (eventMessage like[cd] "Failed * acquire device lock assertion*")' --last 24h

And this is the list of paths with this issue:

2022-05-12 23:06:56.815 E  backupd[666:178829] [com.apple.TimeMachine:FileProtection] Failed to acquire device lock assertion for /Volumes/com.apple.TimeMachine.localsnapshots/Backups.backupdb/M1/2022-05-12-230214/Data/Users/nat/Library/Containers/D8CDEAD6-2CEC-4073-9B34-4A5D048BC02A/Data/StoreKit error: Error Domain=NSPOSIXErrorDomain Code=22 "Invalid argument"
2022-05-12 23:06:56.819 E  backupd[666:178829] [com.apple.TimeMachine:FileProtection] Failed to acquire device lock assertion for /Volumes/com.apple.TimeMachine.localsnapshots/Backups.backupdb/M1/2022-05-12-230214/Data/Users/nat/Library/Containers/D8CDEAD6-2CEC-4073-9B34-4A5D048BC02A/Data/Library error: Error Domain=NSPOSIXErrorDomain Code=22 "Invalid argument"
2022-05-12 23:06:56.823 E  backupd[666:178829] [com.apple.TimeMachine:FileProtection] Failed to acquire device lock assertion for /Volumes/com.apple.TimeMachine.localsnapshots/Backups.backupdb/M1/2022-05-12-230214/Data/Users/nat/Library/Containers/D8CDEAD6-2CEC-4073-9B34-4A5D048BC02A/Data/Documents error: Error Domain=NSPOSIXErrorDomain Code=22 "Invalid argument"
2022-05-12 23:06:56.826 E  backupd[666:178829] [com.apple.TimeMachine:FileProtection] Failed to acquire device lock assertion for /Volumes/com.apple.TimeMachine.localsnapshots/Backups.backupdb/M1/2022-05-12-230214/Data/Users/nat/Library/Containers/D8CDEAD6-2CEC-4073-9B34-4A5D048BC02A/Data/tmp error: Error Domain=NSPOSIXErrorDomain Code=22 "Invalid argument"
2022-05-13 02:04:25.073 E  backupd[666:184543] [com.apple.TimeMachine:FileProtection] Failed to acquire device lock assertion for /Volumes/com.apple.TimeMachine.localsnapshots/Backups.backupdb/M1/2022-05-13-020356/Data/Users/nat/Library/Containers/26F08CF4-D20B-4001-AE38-B4BB3FF8D016/Data/Documents/smartTask_list.plist error: Error Domain=NSPOSIXErrorDomain Code=22 "Invalid argument"
2022-05-13 02:04:25.076 E  backupd[666:184543] [com.apple.TimeMachine:FileProtection] Failed to acquire device lock assertion for /Volumes/com.apple.TimeMachine.localsnapshots/Backups.backupdb/M1/2022-05-13-020356/Data/Users/nat/Library/Containers/26F08CF4-D20B-4001-AE38-B4BB3FF8D016/Data/Documents/alexa_config.plist error: Error Domain=NSPOSIXErrorDomain Code=22 "Invalid argument"
2022-05-13 02:04:25.086 E  backupd[666:184543] [com.apple.TimeMachine:FileProtection] Failed to acquire device lock assertion for /Volumes/com.apple.TimeMachine.localsnapshots/Backups.backupdb/M1/2022-05-13-020356/Data/Users/nat/Library/Containers/26F08CF4-D20B-4001-AE38-B4BB3FF8D016/Data/tmp/DefaultSceneGroup.plist error: Error Domain=NSPOSIXErrorDomain Code=22 "Invalid argument"

So, I looked at one like this:

find /Users/nat/Library/Containers/26F08CF4-D20B-4001-AE38-B4BB3FF8D016

And it was just cache files and stuff that seemed like it could be safely deleted. One of the things was related to the TRADFI (IKEA Home Smart) iOS app. Nothing dramatic.

In fact, ~/Library/Containers is what holds data for sandboxed apps, like for example iOS or iPad apps running on Mac. Again, nothing I’d miss.

Two ways to solve this (but the second should be done either way)

The first way is to delete those files (the way I went)

So, I did run this command to delete those directories entirely:

rm -rf /Users/nat/Library/Containers/26F08CF4-D20B-4001-AE38-B4BB3FF8D016
rm -rf /Users/nat/Library/Containers/D8CDEAD6-2CEC-4073-9B34-4A5D048BC02A

Now, of course, these files would still be in the local Time Machine snapshots (Macs nowadays make regular file system snapshots and then copy those over to the backup drive).

So, I wiped all local snapshots. This is safe because snapshots are not backups, they’re just a “point in time freezes” of the file system. This allows you to go back in time without a backup, but of course, if the internal storage fails, this won’t help. So, I deleted them all with:

for d in $(tmutil listlocalsnapshotdates | grep "-"); do sudo tmutil deletelocalsnapshots $d; done

To make sure they’re gone, run: tmutil listlocalsnapshots /

Finally, wipe the backup drive AGAIN and start fresh. Now that the problematic files are gone, this should work.

The second way is to exclude those files (also recommended if you deleted them anyway and don’t need a backup)

But what if the files causing issues are files you actually need? Well, that’s quite easy:

sudo tmutil addexclusion -p /Users/nat/Library/Containers/26F08CF4-D20B-4001-AE38-B4BB3FF8D016
sudo tmutil addexclusion -p /Users/nat/Library/Containers/D8CDEAD6-2CEC-4073-9B34-4A5D048BC02A

This is probably the safest bet as it will keep the files, but you exclude them from Time Machine. This is especially useful if the files happen to come back and would cause the same issues (e.g. on next app start).

This should be a no-brainer, but you, of course, have to adapt all these paths to your scenario… Don’t just randomly copy and paste things without understanding what you’re doing. Your username is most likely not nat, and you most likely don’t have these two specific apps installed.

I should probably also add at this point that this is an issue that should be resolved by Apple. An end-user shouldn’t have to go through this (most can’t).

The backup finished just fine, the only downside is that I had to set up the IKEA app again, but that was expected (deleted the app data, after all).

Update

After running the successful backup, I started the IKEA Home Smart app again, to see if the error would come back. The app created a new container, but this time with a different path. The issue returned, I noticed because the Time Machine backup had no real progress bar and was just counting up the amount transferred. So, I stopped the backup, and ran the following:

sudo tmutil addexclusion -p /Users/nat/Library/Containers/CED0F836-5EAB-4E64-81BD-423147E2DC2E

This excluded the new IKEA app container, I started the backup again, and it worked, completely without deleting anything. Now the app data should remain at this path and excluded.

Again, adjust your paths and don’t just copy and paste this stuff. Hope this helps.