I'd like to access my Time Machine backup files using a little bash script. As I understand it, this requires a two-step process.

First, I have to mount the Time Capsule "Data" partition:

mount_afp afp://user:pass@ ~/Data

Then, I have to mount the .sparsebundle on the Data partition that contains the backup files of my Mac. I'm not sure how to do this.

It also seems rather awkward that I have to do two mounts to access my backup files. Perhaps I can do it in one step?

I'd love to hear the best solution for this.

  • If you use the default setup for your remote Time Machine backup, the sparsebundle is already mounted or you wouldn't be able to backup your files continuously! The volume is (often) just not visible on your desktop! – klanomath Jul 21 '17 at 21:05
  • @klanomath Alright, but can I also access the backup files using the Terminal? – Daan Jul 21 '17 at 21:17
  • What do you wanna do with your bash script? – klanomath Jul 21 '17 at 21:58
  • I want to run tmutil compare to compare different backups. That part of the script works, but I still have to mount the volumes in Finder. I'd like to automate the mount (and unmount) as well. – Daan Jul 21 '17 at 22:13

If you've configured a regular Time Machine backup onto your Time Capsule, mounting (or unmounting) the sparsebundle is not needed. It's already mounted or you wouldn't be able to backup your data regularly.

To mount the remote Time Machine sparsebundle and get the path to it simply enter:

tmutil latestbackup

(or tmutil latestbackup > /dev/null 2>&1 if you don't want any output)

The command triggers the mounting of the sparsebundle and the output is the path to your last backup.

Entering mount will show you the mount points of the Time Capsule and your sparsebundle.

Your result will be something like (example listing):

/dev/disk1s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
//%user%@%IP% on /Volumes/%TimeCapsule% (afpfs, nobrowse)
/dev/disk2s2 on /Volumes/%Time Machine-Backups% (hfs, local, nodev, nosuid, journaled, nobrowse)

The second last line is the Time Capsule share, the last line (disk2s2) the mounted sparsebundle image. The mounted share/sparsebundle aren't visible in the Finder because they are flagged as nobrowse.

To access your backup you can simply enter something like:

cd "/Volumes/%Time Machine Backups%/Backups.backupdb/%LocalHostName%/

(All terms framed by percent signs depend on your environment and you have to replace them by proper names/addresses - get them by diving into the folders with cd and ls -la.)

  • I think Time Capsule is only mounted when it's actually making a backup. At that time, the volumes are even visible in Finder. When it's not making a backup, it doesn't appear in the mount list. – Daan Jul 22 '17 at 11:07
  • OK, modified answer. – klanomath Jul 22 '17 at 12:25
  • Thank you very much, it works! I wonder though, why tmutil compare doesn't trigger the mount as well. Or, alternatively, why there isn't a dedicated mount command (e.g. tmutil mount). In other words, I feel like there must be a more 'official' way to do it... Any thoughts? – Daan Jul 23 '17 at 23:55
  • Checking a lot of possible options/verbs (like init or mount) and googling a lot I haven't found anything better than the latestbackup verb... – klanomath Jul 24 '17 at 0:08
  • I've looked as well, and I think listbackups is the best verb for when you want to do backup comparisons. I now have: mapfile -t backups < <(tmutil listbackups). This will trigger the mount and put all the backup paths into an array. Then, you can easily retrieve paths to compare. – Daan Jul 24 '17 at 12:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .