mirror of
https://github.com/zrepl/zrepl.git
synced 2024-12-18 13:10:56 +01:00
c743c7b03f
fixes https://github.com/zrepl/zrepl/issues/554 refs https://github.com/zrepl/zrepl/discussions/547#discussioncomment-1936126
43 lines
846 B
Go
43 lines
846 B
Go
package snapper
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/zrepl/zrepl/config"
|
|
"github.com/zrepl/zrepl/zfs"
|
|
)
|
|
|
|
type Type string
|
|
|
|
const (
|
|
TypePeriodic Type = "periodic"
|
|
TypeCron Type = "cron"
|
|
TypeManual Type = "manual"
|
|
)
|
|
|
|
type Snapper interface {
|
|
Run(ctx context.Context, snapshotsTaken chan<- struct{})
|
|
Report() Report
|
|
}
|
|
|
|
type Report struct {
|
|
Type Type
|
|
Periodic *PeriodicReport
|
|
Cron *CronReport
|
|
Manual *struct{}
|
|
}
|
|
|
|
func FromConfig(g *config.Global, fsf zfs.DatasetFilter, in config.SnapshottingEnum) (Snapper, error) {
|
|
switch v := in.Ret.(type) {
|
|
case *config.SnapshottingPeriodic:
|
|
return periodicFromConfig(g, fsf, v)
|
|
case *config.SnapshottingCron:
|
|
return cronFromConfig(fsf, *v)
|
|
case *config.SnapshottingManual:
|
|
return &manual{}, nil
|
|
default:
|
|
return nil, fmt.Errorf("unknown snapshotting type %T", v)
|
|
}
|
|
}
|