2018-09-04 23:46:02 +02:00
|
|
|
package snapper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2019-03-22 19:41:12 +01:00
|
|
|
|
|
|
|
"github.com/zrepl/zrepl/config"
|
|
|
|
"github.com/zrepl/zrepl/zfs"
|
|
|
|
)
|
2018-09-04 23:46:02 +02:00
|
|
|
|
2022-04-12 01:26:41 +02:00
|
|
|
type Type string
|
2018-09-04 23:46:02 +02:00
|
|
|
|
|
|
|
const (
|
2022-04-12 01:26:41 +02:00
|
|
|
TypePeriodic Type = "periodic"
|
|
|
|
TypeCron Type = "cron"
|
|
|
|
TypeManual Type = "manual"
|
2018-09-04 23:46:02 +02:00
|
|
|
)
|
|
|
|
|
2022-04-12 01:26:41 +02:00
|
|
|
type Snapper interface {
|
|
|
|
Run(ctx context.Context, snapshotsTaken chan<- struct{})
|
|
|
|
Report() Report
|
2018-09-04 23:46:02 +02:00
|
|
|
}
|
|
|
|
|
2022-04-12 01:26:41 +02:00
|
|
|
type Report struct {
|
|
|
|
Type Type
|
|
|
|
Periodic *PeriodicReport
|
|
|
|
Cron *CronReport
|
|
|
|
Manual *struct{}
|
2018-09-04 23:46:02 +02:00
|
|
|
}
|
|
|
|
|
2022-04-12 01:26:41 +02:00
|
|
|
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
|
2018-09-04 23:46:02 +02:00
|
|
|
default:
|
2022-04-12 01:26:41 +02:00
|
|
|
return nil, fmt.Errorf("unknown snapshotting type %T", v)
|
2018-09-04 23:46:02 +02:00
|
|
|
}
|
|
|
|
}
|