@@ -31,6 +31,7 @@ import (
3131 "io/ioutil"
3232 "os"
3333 "path/filepath"
34+ "regexp"
3435 "sort"
3536 "strings"
3637 "sync"
@@ -54,18 +55,35 @@ var (
5455 manifestmutex sync.Mutex
5556)
5657
58+ type snapshotFilter struct {
59+ prefix string
60+ regexpMatch * regexp.Regexp
61+ }
62+
63+ func newSnapshotFilter (prefix string , match string ) * snapshotFilter {
64+ filter := & snapshotFilter {
65+ prefix : prefix ,
66+ }
67+ if match != "" {
68+ filter .regexpMatch = regexp .MustCompile (match )
69+ }
70+ log .AppLogger .Debugf ("Filtering snapshots with prefix = %s, regex matcher = %v" , filter .prefix , filter .regexpMatch )
71+ return filter
72+ }
73+
5774// ProcessSmartOptions will compute the snapshots to use
5875// nolint:funlen,gocyclo // Difficult to break this up
5976func ProcessSmartOptions (ctx context.Context , jobInfo * files.JobInfo ) error {
6077 snapshots , err := zfs .GetSnapshotsAndBookmarks (context .Background (), zfs .GetLocalVolumeName (jobInfo ))
6178 if err != nil {
6279 return err
6380 }
81+ filter := newSnapshotFilter (jobInfo .SnapshotPrefix , jobInfo .SnapshotRegexp )
6482 // Base Snapshots cannot be a bookmark
6583 for i := range snapshots {
6684 log .AppLogger .Debugf ("Considering snapshot %s" , snapshots [i ].Name )
6785 if ! snapshots [i ].Bookmark {
68- if jobInfo . SnapshotPrefix == "" || strings . HasPrefix ( snapshots [i ]. Name , jobInfo . SnapshotPrefix ) {
86+ if includeSnapshot ( & snapshots [i ], filter ) {
6987 log .AppLogger .Debugf ("Matched snapshot: %s" , snapshots [i ].Name )
7088 jobInfo .BaseSnapshot = snapshots [i ]
7189 break
@@ -164,6 +182,11 @@ func ProcessSmartOptions(ctx context.Context, jobInfo *files.JobInfo) error {
164182 return nil
165183}
166184
185+ func includeSnapshot (snapshot * files.SnapshotInfo , filter * snapshotFilter ) bool {
186+ return (filter .prefix == "" || strings .HasPrefix (snapshot .Name , filter .prefix )) &&
187+ (filter .regexpMatch == nil || filter .regexpMatch .MatchString (snapshot .Name ))
188+ }
189+
167190// Will list all backups found in the target destination
168191func getBackupsForTarget (ctx context.Context , volume , target string , jobInfo * files.JobInfo ) ([]* files.JobInfo , error ) {
169192 // Prepare the backend client
0 commit comments