yboetz / pyznap

ZFS snapshot tool written in python
GNU General Public License v3.0
197 stars 35 forks source link

Child snapshots being taken even though set to snap = no #73

Closed jpbrown-15 closed 3 years ago

jpbrown-15 commented 3 years ago

I'm not sure if this is an issue or not, but as the root on zfs layout has evolved certain datasets are now children of a different parent.

For example: `rpool rpool/ROOT rpool/ROOT/ubuntu_3chf0x rpool/ROOT/ubuntu_3chf0x/tmp

`

Previously I would have had /tmp as a dataset rpool/tmp but it has now moved to be a child of the root dataset (ubuntu_3chf0x in my example).

I then proceeded to create a new pyznap config that included the following:

`[rpool] daily = 17 weekly = 3 monthly = 1 snap = no clean = yes dest = bkuppool/rpool exclude = rpool/ROOT/ubuntu_3chf0x/tmp rpool/ROOT/ubuntu_3chf0x/var/cache rpool/ROOT/ubuntu_3chf0x/var/mail rpool/ROOT/ubuntu_3chf0x/var/spool rpool/ROOT/ubuntu_3chf0x/var/tmp

Activate the datasets to snapshot for [rpool]

[rpool/ROOT/ubuntu_3chf0x] snap = yes

Turn off Snapshot for children (and grandchildren if we actually want the child snapped e.g. want var but don't want var/tmp) that we don't want snapped [rpool/ROOT/ubuntu_3chf0x/srv] snap = no

[rpool/ROOT/ubuntu_3chf0x/tmp] snap = no

[rpool/ROOT/ubuntu_3chf0x/var/cache] snap = no

[rpool/ROOT/ubuntu_3chf0x/var/spool] snap = no

[rpool/ROOT/ubuntu_3chf0x/var/tmp] snap = no`

The idea was to turn off snap at the rpool level and then activate it at the level of the hierarchy where I wanted to begin, however, turn snap off for certain children of that particular level. The example is I wanted to turn on snap for rpool/ROOT/ubuntu_3chf0x and turn it off for rpool/ROOT/ubuntu_3chf0x/tmp.

When I ran this, I got the following messages in my log:

Oct 30 09:35:34 INFO: Starting pyznap... Oct 30 09:35:34 INFO: Taking snapshots... Oct 30 09:35:35 INFO: Taking snapshot rpool/ROOT/ubuntu_3chf0x@pyznap_2020-10-30_09:35:35_daily... Oct 30 09:35:36 INFO: Taking snapshot rpool/ROOT/ubuntu_3chf0x/srv@pyznap_2020-10-30_09:35:36_monthly... Oct 30 09:35:37 INFO: Taking snapshot rpool/ROOT/ubuntu_3chf0x/srv@pyznap_2020-10-30_09:35:37_weekly... Oct 30 09:35:38 INFO: Taking snapshot rpool/ROOT/ubuntu_3chf0x/tmp@pyznap_2020-10-30_09:35:38_monthly... Oct 30 09:35:39 INFO: Taking snapshot rpool/ROOT/ubuntu_3chf0x/tmp@pyznap_2020-10-30_09:35:39_weekly...

So, while pyznap honors the rpool snap = no for rpool and rpool/ROOT, once it is activated at the rpool/ROOT/ubuntu_3chf0x level, it applies to the rest of the child tree.

I can inhibit sending the snapshots to my backup destination with the exclude configuration and I can add configuration to tell the clean process to remove the newly created snapshots for the children I set snap = no so I have a method to cleanup the snapshots. I'm more surprised that the snapshots were actually taken.

Is this by design and I'm doing something illogical or is there a minor issue?

yboetz commented 3 years ago

Hi

This is by design. pyznap always does recursive snapshots, i.e. if you specify snapshots for rpool it will automatically do a recursive snapshot there and thus snapshot all child datasets. The reason is that snapshots are supposed to be atomic, i.e. snapshots of a dataset and its children should be taken at the same instant. One could maybe handle this a bit more elegant, but atm it will just take a snapshot off all children if you specify snap = yes for a dataset.

An easy workaround here is to specify the snapshots numbers for the root dataset, but use snap = no there and then turn it on for all child datasets you want to snapshot, i.e.:

[rpool]
daily = 17
weekly = 3
monthly = 1
snap = no
clean = yes

[rpool/ROOT/ubuntu_3chf0x/srv]
snap = yes

[rpool/ROOT/ubuntu_3chf0x/tmp]
snap = yes

[rpool/ROOT/ubuntu_3chf0x/var/cache]
snap = yes

[rpool/ROOT/ubuntu_3chf0x/var/spool]
snap = yes

[rpool/ROOT/ubuntu_3chf0x/var/tmp]
snap = yes

There is no way to turn on snapshots on one level, turn it off on an intermediate level and then turn it on again on a deeper level though. For that you would have to use what you said, just deleting the snapshots again by specifying all snapshot numbers to 0.