forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.go
91 lines (75 loc) · 2.34 KB
/
backup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package services
import (
"context"
"io"
"io/fs"
"regexp"
"sync"
"time"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
"www.velocidex.com/golang/velociraptor/file_store/api"
"www.velocidex.com/golang/vfilter"
)
// For writing.
type BackupContainerWriter interface {
Create(name string, mtime time.Time) (io.WriteCloser, error)
WriteResultSet(
ctx context.Context,
config_obj *config_proto.Config,
dest string, in <-chan vfilter.Row) (total_rows int, err error)
}
// For reading.
type BackupContainerReader interface {
Open(name string) (fs.File, error)
}
// Callers may register a backup provider to be included in the backup
type BackupProvider interface {
// The name of this provider
ProviderName() string
// The name of the result saved in the container
Name() []string
// Providers may write result sets into the backup. This will be
// called by the backup service to obtain a channel over which we
// can write the backup file (named in Name() above).
BackupResults(
ctx context.Context,
wg *sync.WaitGroup,
container BackupContainerWriter) (<-chan vfilter.Row, error)
// This is the opposite of backup - it allows a provider to
// recover from an existing backup. Typcially providers need to
// clear their data and read new data from this channel. The
// provider may return stats about its operation.
Restore(ctx context.Context,
container BackupContainerReader,
in <-chan vfilter.Row) (BackupStat, error)
}
// Alows each provider to report the stats of the most recent
// operation.
type BackupStat struct {
// Name of provider
Name string
Error error
Message string
// Which org owns this backup service.
OrgId string
}
type BackupRestoreOptions struct {
// By default the prefix in the zip is calculated based on the
// current org id. This allows this to be overriden.
Prefix string
// Only restore matching providers
ProviderRegex *regexp.Regexp
}
type BackupService interface {
Register(provider BackupProvider)
RestoreBackup(export_path api.FSPathSpec,
opts BackupRestoreOptions) ([]BackupStat, error)
CreateBackup(export_path api.FSPathSpec) ([]BackupStat, error)
}
func GetBackupService(config_obj *config_proto.Config) (BackupService, error) {
org_manager, err := GetOrgManager()
if err != nil {
return nil, err
}
return org_manager.Services(config_obj.OrgId).BackupService()
}