forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.go
69 lines (57 loc) · 2.09 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
package influxdb
import (
"context"
"io"
"time"
)
const (
BackupFilenamePattern = "20060102T150405Z"
)
// BackupService represents the data backup functions of InfluxDB.
type BackupService interface {
// BackupKVStore creates a live backup copy of the metadata database.
BackupKVStore(ctx context.Context, w io.Writer) error
// BackupShard downloads a backup file for a single shard.
BackupShard(ctx context.Context, w io.Writer, shardID uint64, since time.Time) error
}
// RestoreService represents the data restore functions of InfluxDB.
type RestoreService interface {
// RestoreKVStore restores & replaces metadata database.
RestoreKVStore(ctx context.Context, r io.Reader) error
// RestoreKVStore restores the metadata database.
RestoreBucket(ctx context.Context, id ID, rpiData []byte) (shardIDMap map[uint64]uint64, err error)
// RestoreShard uploads a backup file for a single shard.
RestoreShard(ctx context.Context, shardID uint64, r io.Reader) error
}
// Manifest lists the KV and shard file information contained in the backup.
type Manifest struct {
KV ManifestKVEntry `json:"kv"`
Files []ManifestEntry `json:"files"`
// These fields are only set if filtering options are set on the CLI.
OrganizationID string `json:"organizationID,omitempty"`
BucketID string `json:"bucketID,omitempty"`
}
// ManifestEntry contains the data information for a backed up shard.
type ManifestEntry struct {
OrganizationID string `json:"organizationID"`
OrganizationName string `json:"organizationName"`
BucketID string `json:"bucketID"`
BucketName string `json:"bucketName"`
ShardID uint64 `json:"shardID"`
FileName string `json:"fileName"`
Size int64 `json:"size"`
LastModified time.Time `json:"lastModified"`
}
// ManifestKVEntry contains the KV store information for a backup.
type ManifestKVEntry struct {
FileName string `json:"fileName"`
Size int64 `json:"size"`
}
// Size returns the size of the manifest.
func (m *Manifest) Size() int64 {
n := m.KV.Size
for _, f := range m.Files {
n += f.Size
}
return n
}