4

I'm used to backup my user's home using rsync. However, I now have data (eg, running database) that shouldn't be backed up while being changed, and I'd like to keep the applications changing them running during the backup.

I know file system snapshot views exist to deal with this problem: Linux has the LVM approach and Apple has Time Machine. However, apparently only the former allows one to mount a snapshot as a virtual file system, so that it's possible to use tools like rsync, tar, or, for what matters, cp, against a view of the files frozen at a given time.

I cannot find any such feature for macOS, tmutil/Time Machine don't look to be the same thing, they must be leveraging the snapshot functionality of their APFS file system, but I can't find any way to see a snapshot as a set of files. Is that possible for APFS?

Note that I'm not interested at all in using Time Machine for my backups: I'm an advanced user and TM is too stupid to suit me fine (it doesn't work over SSH, it doesn't allow me to select a folder on a destination device, it doesn't seem to support multiple backup profiles, each with a different set of sources/destinations and different schedules), nor I'm so interested in spending money on things like SuperDuper!, just to do what that my scripts have done very well for years.

1 Answer 1

7

Yes, it is definitely possible to view an APFS snapshot as a "set of files" - i.e. a file system. This is done simply by mounting the snapshot - exactly like you would do with LVM on Linux.

The syntax is:

  mount_apfs -s <snapshot name> <mounted base volume> <mount folder>

So for example create a snapshot with:

  tmutil snapshot /

It will say that the new snapshot is named for example: 2019-01-01-180510.

Then later you can create a folder "MyBackup" and mount the snapshot like this:

  mount_apfs -s com.apple.TimeMachine.2019-01-01-180510 / MyBackup

If you then browse MyBackup you'll see the files like they were at the time the snapshot was taken.

Note: You don't have to use snapshots created by TimeMachine. Any APFS snapshots will be mountable with the same command.

2
  • Thanks a lot @jksoegaard, just tried it and works perfectly! I see there are tmutil alternatives (eg, arstechnica.com/gadgets/2017/02/…), but that's a minor issue for me.
    – zakmck
    Commented Jan 1, 2019 at 17:16
  • 2
    Note that the alternative (fs_snapshot) isn't available to ordinary users. Only certain developers can actually take advantage of it.
    – jksoegaard
    Commented Jan 1, 2019 at 17:18

You must log in to answer this question.

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