mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 21:05:10 +00:00
Move snapshot filter function to restic package
This commit is contained in:
parent
77037e33c9
commit
052a6a0acc
@ -58,15 +58,7 @@ func FindFilteredSnapshots(ctx context.Context, repo *repository.Repository, hos
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for id := range repo.List(ctx, restic.SnapshotFile) {
|
for _, sn := range restic.FindFilteredSnapshots(ctx, repo, host, tags, paths) {
|
||||||
sn, err := restic.LoadSnapshot(ctx, repo, id)
|
|
||||||
if err != nil {
|
|
||||||
Warnf("Ignoring %q, could not load snapshot: %v\n", id, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if (host != "" && host != sn.Hostname) || !sn.HasTags(tags) || !sn.HasPaths(paths) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
|
@ -2,6 +2,8 @@ package restic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
"restic/errors"
|
"restic/errors"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -48,3 +50,23 @@ func FindSnapshot(repo Repository, s string) (ID, error) {
|
|||||||
|
|
||||||
return ParseID(name)
|
return ParseID(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindFilteredSnapshots yields Snapshots filtered from the list of all
|
||||||
|
// snapshots.
|
||||||
|
func FindFilteredSnapshots(ctx context.Context, repo Repository, host string, tags []string, paths []string) Snapshots {
|
||||||
|
results := make(Snapshots, 0, 20)
|
||||||
|
|
||||||
|
for id := range repo.List(ctx, SnapshotFile) {
|
||||||
|
sn, err := LoadSnapshot(ctx, repo, id)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "could not load snapshot %v: %v\n", id.Str(), err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (host != "" && host != sn.Hostname) || !sn.HasTags(tags) || !sn.HasPaths(paths) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
results = append(results, sn)
|
||||||
|
}
|
||||||
|
return results
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user