Sanoid snapshot help

Hi. I’m using sanoid to manage automatic ZFS snapshots. It mostly works, but I’m seeing some weird behavior with snapshots. Here’s my layout:

# zfs list
NAME        USED  AVAIL  REFER  MOUNTPOINT
pool       53.0G  1.67T    96K  none
pool/home   178M  1.67T   165M  none
pool/nix   39.6G  1.67T  10.2G  none
pool/root   390M  1.67T  4.48M  none
pool/var   12.6G  1.67T  9.35G  none

and an abbreviated version of my sanoid nix config:

      services.sanoid = {
        enable = true;
        datasets."pool/root" = {
          useTemplate = [
            "daily"
            "weekly"
            "monthly"
          ];
        };
        datasets."pool/nix" = {
          useTemplate = [
            "weekly"
          ];
        };
        templates."hourly" = {
          hourly = 24;
          autosnap = true;
          autoprune = true;
        };
        templates."daily" = {
          daily = 7;
          autosnap = true;
          autoprune = true;
        };
        templates."weekly" = {
          weekly = 4;
          autosnap = true;
          autoprune = true;
        };


So, root is snapshotted daily, weekly, and monthly, but nix is only snapshotted weekly. The templates all have autosnao and autoprune enabled, and I have an hourly template for other datasets like home..

The problem is hourly snapshots are being created for root, and both daily and hourly snapshots are taken for nix. They’re also not being pruned properly - for root, where daily is defined, there are 7 snapshots as expected… but for nix, I have 67 daily snapshots, when there should be 0.

Any ideas what’s going on here? I’m new to sanoid so certainly could be missing something, but not seeing any obvious misconfiguration.

Would appreciate any guidance. Thanks.

I figured it out. Turns out there’s a “default” template, and by invoking the use of templates it also enables those default values. Where I overrode it those explicitly defined values are used, but for something like daily on nix, which I don’t have explicitly defined, the default template value for daily is still used.

Fixed by overriding the template and setting all to 0, so only my explicit values are used. Update for the example above.

      services.sanoid = {
        enable = true;
        datasets."pool/root" = {
      		useTemplate = [
      			"daily"
      			"weekly"
    	  		"monthly"
    		  ];
        };
        datasets."pool/nix" = {
      		useTemplate = [
      			"weekly"
      		];
        };
        # Override default template to 0; only create requested snapshots
        templates."default" = {
            frequently = 0;
            hourly = 0;
            daily = 0;
            weekly = 0;
            monthly = 0;
            yearly = 0;
            autosnap = true;
            autoprune = true;
        };
        templates."hourly" = {
          hourly = 24;
        };
        templates."daily" = {
          daily = 7;
        };
        templates."weekly" = {
          weekly = 4;
        };

This seems to be working as intended now.

1 Like