@@ -31,6 +31,7 @@ import (
31
31
"io/ioutil"
32
32
"os"
33
33
"path/filepath"
34
+ "regexp"
34
35
"sort"
35
36
"strings"
36
37
"sync"
@@ -54,18 +55,35 @@ var (
54
55
manifestmutex sync.Mutex
55
56
)
56
57
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
+
57
74
// ProcessSmartOptions will compute the snapshots to use
58
75
// nolint:funlen,gocyclo // Difficult to break this up
59
76
func ProcessSmartOptions (ctx context.Context , jobInfo * files.JobInfo ) error {
60
77
snapshots , err := zfs .GetSnapshotsAndBookmarks (context .Background (), jobInfo .VolumeName )
61
78
if err != nil {
62
79
return err
63
80
}
81
+ filter := newSnapshotFilter (jobInfo .SnapshotPrefix , jobInfo .SnapshotRegexp )
64
82
// Base Snapshots cannot be a bookmark
65
83
for i := range snapshots {
66
84
log .AppLogger .Debugf ("Considering snapshot %s" , snapshots [i ].Name )
67
85
if ! snapshots [i ].Bookmark {
68
- if jobInfo . SnapshotPrefix == "" || strings . HasPrefix ( snapshots [i ]. Name , jobInfo . SnapshotPrefix ) {
86
+ if includeSnapshot ( & snapshots [i ], filter ) {
69
87
log .AppLogger .Debugf ("Matched snapshot: %s" , snapshots [i ].Name )
70
88
jobInfo .BaseSnapshot = snapshots [i ]
71
89
break
@@ -163,6 +181,11 @@ func ProcessSmartOptions(ctx context.Context, jobInfo *files.JobInfo) error {
163
181
return nil
164
182
}
165
183
184
+ func includeSnapshot (snapshot * files.SnapshotInfo , filter * snapshotFilter ) bool {
185
+ return (filter .prefix == "" || strings .HasPrefix (snapshot .Name , filter .prefix )) &&
186
+ (filter .regexpMatch == nil || filter .regexpMatch .MatchString (snapshot .Name ))
187
+ }
188
+
166
189
// Will list all backups found in the target destination
167
190
func getBackupsForTarget (ctx context.Context , volume , target string , jobInfo * files.JobInfo ) ([]* files.JobInfo , error ) {
168
191
// Prepare the backend client
0 commit comments