2018-10-11 15:22:52 +02:00
|
|
|
package snapper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2019-03-22 19:41:12 +01:00
|
|
|
|
2018-10-11 15:22:52 +02:00
|
|
|
"github.com/zrepl/zrepl/config"
|
2020-06-27 23:53:33 +02:00
|
|
|
"github.com/zrepl/zrepl/zfs"
|
2018-10-11 15:22:52 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// FIXME: properly abstract snapshotting:
|
|
|
|
// - split up things that trigger snapshotting from the mechanism
|
|
|
|
// - timer-based trigger (periodic)
|
|
|
|
// - call from control socket (manual)
|
|
|
|
// - mixed modes?
|
|
|
|
// - support a `zrepl snapshot JOBNAME` subcommand for config.SnapshottingManual
|
|
|
|
type PeriodicOrManual struct {
|
|
|
|
s *Snapper
|
|
|
|
}
|
|
|
|
|
2021-03-23 18:01:12 +01:00
|
|
|
func (s *PeriodicOrManual) Run(ctx context.Context, wakeUpCommon chan<- struct{}) {
|
2018-10-11 15:22:52 +02:00
|
|
|
if s.s != nil {
|
2021-03-23 18:01:12 +01:00
|
|
|
s.s.Run(ctx, wakeUpCommon)
|
2018-10-11 15:22:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 00:13:55 +02:00
|
|
|
// Returns nil if manual
|
|
|
|
func (s *PeriodicOrManual) Report() *Report {
|
|
|
|
if s.s != nil {
|
|
|
|
return s.s.Report()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-27 23:53:33 +02:00
|
|
|
func FromConfig(g *config.Global, fsf zfs.DatasetFilter, in config.SnapshottingEnum) (*PeriodicOrManual, error) {
|
2018-10-11 15:22:52 +02:00
|
|
|
switch v := in.Ret.(type) {
|
|
|
|
case *config.SnapshottingPeriodic:
|
|
|
|
snapper, err := PeriodicFromConfig(g, fsf, v)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &PeriodicOrManual{snapper}, nil
|
|
|
|
case *config.SnapshottingManual:
|
|
|
|
return &PeriodicOrManual{}, nil
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unknown snapshotting type %T", v)
|
|
|
|
}
|
|
|
|
}
|