Macro to report weekly number and size of space occupying APFS snapshots (CCC & TM) per email

Hello,

my iMac was slowing down and I noticed rapidly decreasing primary SSD disk space; 30 GB out 1 TB free.

I ran daisy disk which showed more than 450 GB in unidentified purgeable space which daisy disk was strangely unable to purge.

I finally discovered that it was all due to a fluke 435 GB APFS snapshot which I deleted and all is fine.

I therefore decided to write a macro to report weekly by email to myself on the number and size of APFS snapshots in my Mac (the source being mainly Time Machine and CCC).

I basically have 2 problems:

1- the terminal command
tmutil listlocalsnapshots /
lists the snapshot names correctly, but I would like to also list the snapshot path and size in addition to the names. Size is essential. Path not so important.

2- I was wondering how to copy the result (listing of snapshots name, size, if simple path) to a variable which I would put in the body of the email to myself.

thank you for your time and help

Hey @ronald,

The Execute a Shell Script action can save to a variable.

Read the tmutil man page.

man tmutil

In the Terminal. Better yet:

man tmutil | col -bx

In a BBEdit Shell Worksheet.

See if there are any options for listing the path of the snapshot. There should be, but I can't test this – as I'm still on Sierra.

There may also be an option to display the size.

If not then you can feed the path to the du Unix utility to get the size of the item.

du -d 0 ~/Downloads

Using the Downloads folder to simulate the snapshot path.

-Chris

1 Like

My apologies. I forgot to thank you for the info.

Hey Ronald,

Did you find a solution to list the snapshots and their sizes?

The tmutil listlocalsnapshots doesn’t work for me (probably because currently I have no TM running; I only have the snapshots done by CCC).

What works for me is…

diskutil apfs listSnaps <volume>

But this doesn’t give me the sizes of the snapshots (nor the path). The only way I found to get the sizes is via the CCC GUI. (Besides du probably; but for that I would need the path.)

And some facts make me believe that currently it is impossible to get the list and the sizes via a simple command, because:

  • Also in the CCC GUI it takes a considerable amount of time to display the sizes (currently I have 15 CCC snapshots). Seems like CCC is doing additional queries to get the sizes, which might not be accessible via the shell.
  • Also with diskutil apfs listSnaps in the Terminal it takes some time to only build the list of snapshots – without any sizes, or paths.

Did you find a way?

Hello Tom,

For the reason above, I think that it's important to keep a close eye on APFS snapshots.

1- for me, listing snapshots without any reference to size is useless. My only concern with snapshots is how much disk space they use. In addition, the idea that once should not be concerned with purgeable space because the OS deletes it automatically is nonsense. I was running out of space to such an extent that I got a 'no space availalble' message when I wanted to update my iphone connected to my mac. It worked perfeclty after I deleted a few APFS snapshots.

2- CCC: your email is a coincidence because just yesterday, I found that CCC GUI is the most convenient way to display the size of APFS snapshots. Otherwise, using scripts, I asked everywhere including reddit, and it just seems too complicated and same for finding the path and displaying the files in pathfinder.
There is a problem : right click on the APFS in CCC and click on browse in Finder. In my case pathfinder opens (even if it is not the default file browser) but in no specific folder. What happens if you click on Browse in Finder ?

3- I wanted to discuss deleting snapshots, but before doing I wanted to ask you: what would be the consequences of deleting Time Machine snapshots ?

thank you

image

image

I continued the discussion here:


Besten Dank

The snapshot is opened in the Finder (and I do have a trial of PathFinder installed currently).

If something opens with the “wrong” program, it may help to reset the Launch Services database.


I don’t have TimeMachine snapshots, but speaking of APFS snapshots in general, if you delete a snapshot…

  • you will probably gain the disk space of that snapshot, as for example indicated by CCC. However, this may depend on how the indicated space is calculated. (Not sure about that; a deleted file can be “part” of multiple snapshots.)
  • you will lose the ability to restore to the point of time of the deleted snapshot.

thank you very much for the info and link.

I did some more reading and don't think that erasing snapshots on the mac is a big deal. It's just an added precaution.

From apple's site:

our Time Machine backup disk might not always be available, so Time Machine also stores some of its backups on your Mac. These backups are called local snapshots.

thank you again Tom

Note that snapshots are an APFS feature, and are not only created by Time Machine (though currently tmutil seems to be the main interface to create them).

For example, I don’t have Time Machine running but I create snapshots with CCC, which will be retained for a certain time according to a certain policy (e.g. one per day for the last 30 days). Also the system seems to automatically create a snapshot before an OS update. You can also create snapshots manually via Terminal.

Obviously snapshots don’t qualify as backup (since they reside on the same disk) but they are useful for example when you have accidentally deleted some files and don’t have a backup of them. So, I wouldn’t erase them, unless you need the space. (Of course, a remaining disk space of only 20GB or so would be a good reason :wink: )

1 Like

A very interesting reply. Helps me better understand snapshots.
Strange that there is no GUI interface to manage snapshots
Thank you.