WIP daemon:

Implement
* pruning on source side
* local job
* test subcommand for doing a dry-run of a prune policy

* use a non-blocking callback from autosnap to trigger the depending
jobs -> avoids races, looks saner in the debug log
This commit is contained in:
Christian Schwarz
2017-09-16 21:12:26 +02:00
parent b168274048
commit 6a05e101cf
7 changed files with 333 additions and 47 deletions
+14 -6
View File
@@ -17,7 +17,14 @@ type Pruner struct {
PrunePolicy PrunePolicy
}
func (p *Pruner) Run(ctx context.Context) {
type PruneResult struct {
Filesystem *zfs.DatasetPath
All []zfs.FilesystemVersion
Keep []zfs.FilesystemVersion
Remove []zfs.FilesystemVersion
}
func (p *Pruner) Run(ctx context.Context) (r []PruneResult, err error) {
log := ctx.Value(contextKeyLog).(Logger)
@@ -25,19 +32,18 @@ func (p *Pruner) Run(ctx context.Context) {
log.Printf("doing dry run")
}
// ZFSListSnapsFiltered --> todo can extend fsfilter or need new? Have already something per fs
// Dedicated snapshot object? Adaptor object to FilesystemVersion?
filesystems, err := zfs.ZFSListMapping(p.DatasetFilter)
if err != nil {
log.Printf("error applying filesystem filter: %s", err)
return
return nil, err
}
if len(filesystems) <= 0 {
log.Printf("no filesystems matching filter")
return
return nil, err
}
r = make([]PruneResult, 0, len(filesystems))
for _, fs := range filesystems {
fsversions, err := zfs.ZFSListFilesystemVersions(fs, &PrefixSnapshotFilter{p.SnapshotPrefix})
@@ -73,6 +79,8 @@ func (p *Pruner) Run(ctx context.Context) {
dbgj, err = json.Marshal(remove)
l.Printf("DEBUG: REMOVE=%s", dbgj)
r = append(r, PruneResult{fs, fsversions, keep, remove})
describe := func(v zfs.FilesystemVersion) string {
timeSince := v.Creation.Sub(p.Now)
const day time.Duration = 24 * time.Hour