Skip to content

Time Machine automatically nuking snapshots #1

Open

Description

@vimalloc

It looks like time machine will occasionally nuke snapshots itself. If I had to guess, it is probably doing something along the lines of tmutil thinlocalsnapshots /.

As it stands, the only way I found to create APFS snapshots is via tmutil, so unless whatever is deleting the snapshots we created is run on a cron or something that we can disable, there isn't much to be done about this. Ideally we would have a C API or a different set of tools outside of time machine that let us create APFS snapshots, but until that is a thing we will take what we can get.

This won't cause the program to crash, if it finds that a snapshot was removed out from under it, it will just remove that snapshots metadata from the database and keep happily running. But it does mean that I cannot guarantee the amount of snapshots to keep limits found in the config file will be honored.

Activity

  1. vimalloc commented on Sep 29, 2017

    @vimalloc
    OwnerAuthor

    Doing testing with an actual snapshot schedule, it looks like it doesn't let me keep more then 4 or 5 snapshots at a time, which equates to never having hourly snapshots kept. This is super unfortunate, but unless apply provides a way around this i don't see what could be done.

  2. vimalloc commented on Nov 11, 2017

    @vimalloc
    OwnerAuthor

    It looks like there is a way to create snapshots via a C syscall:

    #include <fcntl.h>
    #include <stdio.h>
    #include <sys/attr.h>
    #include <sys/snapshot.h>
    
    int main() {
    	int dirfd = open("/", O_RDONLY, 0);
    	if (dirfd < 0) {
    		perror("open");
    		return(1);
    	}
    
    	int ret = fs_snapshot_create(dirfd, "snapshot_test", 0);
    	if (ret != 0)
    		perror("fs_snapshot_create");
    	return (ret);
    }

    However, running this, even as root, returns the error fs_snapshot_create: Operation not permitted. Looking at this thread (https://forums.developer.apple.com/thread/89635), it looks like we would need a special entitlement to get that to work, and based on what that sounds like I highly doubt apple would give me one (stupid apple). But, if I have some more time, I will see if it is possible.

  3. leftytennis commented on Jan 26, 2018

    @leftytennis

    Did you find any more info regarding the entitlement required and how to request this?

  4. Jip-Hop commented on Jun 29, 2018

    @Jip-Hop

    I havent tried this myself, but when reading the snapshot documentation of CCC, it seems they have found a way around this. The interface distinguishes between snapshots made by CCC and snapshots made by Time Machine. Also it guarantees the following:

    † CCC applies a more conservative retention policy for the startup disk — weekly snapshots are not retained, and daily snapshots are only retained for 7 days. You can customize those settings if you want a longer retention for snapshots on the startup disk, but be sure to consider the implications this will have on disk usage on your startup disk.

  5. Jip-Hop commented on Jun 29, 2018

    @Jip-Hop

    I think I found the answer here:

    Time Machine should only monkey with its own snapshots. If you create a snapshot via other means, Time Machine should leave it alone.
    As far as creating such a snapshot, that requires a special entitlement as per this thread.
    Share and Enjoy

    Seem like the key is to use man fs_snapshot_create instead of tmutil.

  6. Jip-Hop commented on Jun 29, 2018

    @Jip-Hop

    Whoops. I now see you already posted that article on 11 Nov 2017. I guess CCC was able to get this special entitlement because they're a backup application developer.

  7. leftytennis commented on Jun 29, 2018

    @leftytennis

    Seems really odd to me that this special entitlement is required at all and not just require elevated privileges for the effective uid...

  8. vimalloc commented on Jun 29, 2018

    @vimalloc
    OwnerAuthor

    Seriously, it's super dumb 👎

  9. sclsj commented on Mar 12, 2020

    @sclsj

    You can mount the snapshot somewhere, and Time Machine won't be able to delete it. I've tested mounting multiple snapshots and it did not create any problems.

  10. sclsj commented on Sep 1, 2021

    @sclsj

    Another option: use snaputil. See here: ahl/apfs#2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions