forked from wal-g/wal-g
/
backup_sentinel_dto.go
70 lines (59 loc) · 2.3 KB
/
backup_sentinel_dto.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
package internal
import (
"sync"
"time"
)
// BackupSentinelDto describes file structure of json sentinel
type BackupSentinelDto struct {
BackupStartLSN *uint64 `json:"LSN"`
IncrementFromLSN *uint64 `json:"DeltaFromLSN,omitempty"`
IncrementFrom *string `json:"DeltaFrom,omitempty"`
IncrementFullName *string `json:"DeltaFullName,omitempty"`
IncrementCount *int `json:"DeltaCount,omitempty"`
Files BackupFileList `json:"Files"`
TarFileSets map[string][]string `json:"TarFileSets"`
PgVersion int `json:"PgVersion"`
BackupFinishLSN *uint64 `json:"FinishLSN"`
SystemIdentifier *uint64 `json:"SystemIdentifier,omitempty"`
UncompressedSize int64 `json:"UncompressedSize"`
CompressedSize int64 `json:"CompressedSize"`
TablespaceSpec *TablespaceSpec `json:"Spec"`
UserData interface{} `json:"UserData,omitempty"`
}
// Extended metadata should describe backup in more details, but be small enough to be downloaded often
type ExtendedMetadataDto struct {
StartTime time.Time `json:"start_time"`
FinishTime time.Time `json:"finish_time"`
DatetimeFormat string `json:"date_fmt"`
Hostname string `json:"hostname"`
DataDir string `json:"data_dir"`
PgVersion int `json:"pg_version"`
StartLsn uint64 `json:"start_lsn"`
FinishLsn uint64 `json:"finish_lsn"`
IsPermanent bool `json:"is_permanent"`
SystemIdentifier *uint64 `json:"system_identifier"`
UncompressedSize int64 `json:"uncompressed_size"`
CompressedSize int64 `json:"compressed_size"`
UserData interface{} `json:"user_data,omitempty"`
}
func (dto *BackupSentinelDto) setFiles(p *sync.Map) {
dto.Files = make(BackupFileList)
p.Range(func(k, v interface{}) bool {
key := k.(string)
description := v.(BackupFileDescription)
dto.Files[key] = description
return true
})
}
// TODO : unit tests
// TODO : get rid of panic here
// IsIncremental checks that sentinel represents delta backup
func (dto *BackupSentinelDto) IsIncremental() bool {
// If we have increment base, we must have all the rest properties.
if dto.IncrementFrom != nil {
if dto.IncrementFromLSN == nil || dto.IncrementFullName == nil || dto.IncrementCount == nil {
panic("Inconsistent BackupSentinelDto")
}
}
return dto.IncrementFrom != nil
}