diff --git a/app.go b/app.go index 1f07568..88d4e3c 100644 --- a/app.go +++ b/app.go @@ -169,7 +169,12 @@ func (a *App) Cleanup(now time.Time) error { for _, dest := range a.destinations { dest = dest.Append("/" + src.Box() + "/" + src.Path()) for _, s := range cfg.box[dest.Box()].zfs.filesystems[dest.Path()].snapshots { - if expired, err := s.Expired(now); err != nil { + if !s.Valid() { + if err := s.Delete(); err != nil { + log.WithFields(log.Fields{"app": a.name, "now": now, "box": src.Box(), "snapshot": s.String(), "call": "Delete", "error": err}).Errorf("") + return err + } + } else if expired, err := s.Expired(now); err != nil { log.WithFields(log.Fields{"app": a.name, "now": now, "box": dest.Box(), "snapshot": s.String(), "call": "Expired", "error": err}).Errorf("") return err } else if expired { @@ -202,12 +207,33 @@ func (a *App) SanityCheck() error { log.WithFields(log.Fields{"app": a.name, "box": src.Box(), "path": src.Path(), "error": err}).Errorf("") return err } + + for _, s := range b.zfs.filesystems[src.Path()].snapshots { + if !s.Valid() { + if err := s.Delete(); err != nil { + log.WithFields(log.Fields{"app": a.name, "box": src.Box(), "snapshot": s.String(), "call": "Delete", "error": err}).Errorf("") + return err + } + } + } } onlineDestinations := 0 for _, dest := range a.destinations { - if cfg.box[dest.Box()].online { + b := cfg.box[dest.Box()] + if b.online { onlineDestinations++ + for _, src := range a.sources { + dest2 := dest.Append("/" + src.Box() + "/" + src.Path()) + for _, s := range b.zfs.filesystems[dest2.Path()].snapshots { + if !s.Valid() { + if err := s.Delete(); err != nil { + log.WithFields(log.Fields{"app": a.name, "box": src.Box(), "snapshot": s.String(), "call": "Delete", "error": err}).Errorf("") + return err + } + } + } + } } } if onlineDestinations == 0 {