Wednesday, November 13, 2024

command line – How can I mount a TimeMachine Backup snapshot in the Terminal via mount_apfs?

Part 1 – the role of /Volumes/.timemachine

There is a misconception about what is in /Volumes/.timemachine/<GUID>/. It contains mount points which may or may not have mounted TM snapshots. Some of these mount points relate to TM snapshots which still exists, but most refer to snapshots which have been thinned and so no longer exist.

If I choose a mount point for a snapshot which no longer exists then, like you, I get nothing:

ls -l /Volumes/.timemachine/84A3891E-14F5-4FEE-A1A0-F3F501863D11/2024-04-12-015857.backup
total 0

But I can use Finder to see which snapshots still exist in my TM backup. Choose one of them and ls gives:

ls -l /Volumes/.timemachine/84A3891E-14F5-4FEE-A1A0-F3F501863D11/2024-04-11-124649.backup
total 64
drwxr-xr-x@ 5 root  wheel    160 11 Apr 12:44 2024-04-11-124649.backup
-rw-r--r--@ 1 root  wheel  32077 11 Apr 11:46 backup_manifest.plist

(I have deliberately used ls -l and not ls -1 as you did)

Go one level deeper to see the - Data folder:

ls -l /Volumes/.timemachine/84A3891E-14F5-4FEE-A1A0-F3F501863D11/2024-04-11-124649.backup/2024-04-11-124649.backup
total 0
drwxrwxr-x@ 22 root  admin  704 11 Apr 12:46 BethSSD - Data

I am somewhat surprised that macOS does not remove the mount points referring to thinned (no longer existing) snapshots.

Part 2 – mounting TM snapshots using mount_apfs

In my example below, my TM volume is called TM-Duff.

First list the snapshots TM snapshots with:

diskutil apfs listSnapshots /Volumes/TM-Duff

This lists all the snapshots. Here is just one of them:

+-- C67959A1-ACAD-47D9-9FAB-17A9B4988BD8
|   Name:        com.apple.TimeMachine.2024-03-31-192542.backup
|   XID:         2229
|   Purgeable:   Yes

Now it can be mounted using:

mount_apfs -o ro -s com.apple.TimeMachine.2024-03-31-192542.backup /Volumes/TM-Duff ~/Temp/mp

where ~/Temp/mp is an empty directory to use as a mount point. See man mount_apfs for a rather poor description of the command.

Now use ls -l ~/Temp/mp to see the content of the backup. A few folders down the tree:

ls -l ~/Temp/mp/2024-03-31-192542.backup/Data
total 3840
drwxrwxr-x@ 171 root  admin  5472 23 Mar 20:18 Applications
-rw-r--r--@   1 root  wheel     0 24 Mar 20:11 Icon?
drwxr-xr-x@  67 root  wheel  2144  9 Mar 20:12 Library
drwxr-xr-x@   3 root  wheel    96  7 Nov 14:48 MobileSoftwareUpdate
drwxr-xr-x@   3 root  wheel    96 29 Feb 15:05 System
drwxr-xr-x@   6 root  admin   192  9 Mar 20:12 Users
drwxr-xr-x@   2 root  wheel    64 24 Mar 20:04 Volumes
drwxrwxr-t@   2 root  admin    64 11 Jul  2023 cores
drwxr-xr-x@   2 root  wheel    64 11 Jul  2023 mnt
drwxr-xr-x@   3 root  wheel    96 12 Nov 15:26 opt
drwxr-xr-x@   6 root  wheel   192  9 Mar 20:12 private
drwxr-xr-x@   2 root  wheel    64 11 Jul  2023 sw
drwxr-xr-x@   5 root  wheel   160 29 Feb 15:05 usr

(just the same as Finder shows.)

Related Articles

Latest Articles