Snapshot cleanup logic – risk of having no snapshots at all, breaking retention policy (physical mode only)
Currently, for physical mode, we clean up old snapshots using this snippet (3.3.0):
zfs list -t snapshot -H -o name -s dblab:datastateat -s creation -r dblab_pool_registry | grep -v clone | head -n -6 | xargs -n1 --no-run-if-empty zfs destroy -R
The problem here is that if new snapshot creation has issues, and there are _pre snapshots without final ones, this snippet deletes them all, eventually leaving DBLab instance without any working snapshots at all.
We need to improve this code so retention policy would also work (N last snapshots are not get deleted, according to the policy define in the config).