@@ -508,7 +508,7 @@ func (m *Manager) CleanupSnapshots(retentionLimit int) ([]string, error) {
508
508
busySnapshots := m .getBusySnapshotList (clonesOutput )
509
509
510
510
cleanupCmd := fmt .Sprintf (
511
- "zfs list -t snapshot -H -o name -s %s -s creation -r %s | grep -v clone | head -n -%d %s" +
511
+ "zfs list -t snapshot -H -o name -s %s -s creation -r %s | grep -v clone | grep _pre$ | head -n -%d %s" +
512
512
"| xargs -n1 --no-run-if-empty zfs destroy -R " ,
513
513
dataStateAtLabel , m .config .Pool .Name , retentionLimit , excludeBusySnapshots (busySnapshots ))
514
514
@@ -527,10 +527,10 @@ func (m *Manager) CleanupSnapshots(retentionLimit int) ([]string, error) {
527
527
}
528
528
529
529
func (m * Manager ) getBusySnapshotList (clonesOutput string ) []string {
530
- systemClones , userClones := make (map [string ]string ), make ( map [ string ] struct {} )
531
- branchingSnapshots := []string {}
530
+ systemClones := make (map [string ]string )
531
+ branchingSnapshotDatasets := []string {}
532
532
533
- userClonePrefix := m .config .Pool .Name + "/"
533
+ systemDatasetPrefix := fmt . Sprintf ( "%s/%s/%s/clone_pre_" , m .config .Pool .Name , branching . BranchDir , branching . DefaultBranch )
534
534
535
535
for _ , line := range strings .Split (clonesOutput , "\n " ) {
536
536
cloneLine := strings .FieldsFunc (line , unicode .IsSpace )
@@ -539,39 +539,32 @@ func (m *Manager) getBusySnapshotList(clonesOutput string) []string {
539
539
continue
540
540
}
541
541
542
- // Keep the user-defined snapshot and the snapshot it is based on.
543
- if strings .HasPrefix (cloneLine [0 ], userClonePrefix + "branch" ) {
544
- branchingSnapshots = append (branchingSnapshots , cloneLine [0 ], cloneLine [1 ])
545
-
542
+ // Make dataset-snapshot map for system snapshots.
543
+ if strings .HasPrefix (cloneLine [0 ], systemDatasetPrefix ) {
544
+ systemClones [cloneLine [0 ]] = cloneLine [1 ]
546
545
continue
547
546
}
548
547
549
- //nolint:lll
550
- if cloneName , _ := strings .CutPrefix (cloneLine [0 ], userClonePrefix ); strings .HasPrefix (cloneLine [0 ], userClonePrefix ) && ! strings .Contains (cloneName , m .config .PreSnapshotSuffix ) {
551
- origin := cloneLine [1 ]
552
-
553
- if idx := strings .Index (origin , "@" ); idx != - 1 {
554
- origin = origin [:idx ]
548
+ // Keep snapshots related to the user-defined datasets.
549
+ if strings .HasPrefix (cloneLine [1 ], systemDatasetPrefix ) {
550
+ systemDataset , _ , found := strings .Cut (cloneLine [1 ], "@" )
551
+ if found {
552
+ branchingSnapshotDatasets = append (branchingSnapshotDatasets , systemDataset )
555
553
}
556
554
557
- userClones [origin ] = struct {}{}
558
-
559
555
continue
560
556
}
561
-
562
- systemClones [cloneLine [0 ]] = cloneLine [1 ]
563
557
}
564
558
565
- busySnapshots := make ([]string , 0 , len (userClones ))
559
+ busySnapshots := make ([]string , 0 , len (branchingSnapshotDatasets ))
566
560
567
- for userClone := range userClones {
568
- if systemClones [userClone ] != "" {
569
- busySnapshots = append (busySnapshots , systemClones [userClone ])
561
+ for _ , busyDataset := range branchingSnapshotDatasets {
562
+ busySnapshot , ok := systemClones [busyDataset ]
563
+ if ok {
564
+ busySnapshots = append (busySnapshots , busySnapshot )
570
565
}
571
566
}
572
567
573
- busySnapshots = append (busySnapshots , branchingSnapshots ... )
574
-
575
568
return busySnapshots
576
569
}
577
570
0 commit comments