-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathinspect.go
107 lines (92 loc) · 3.06 KB
/
inspect.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package backupstore
import (
"fmt"
"github.com/sirupsen/logrus"
. "github.com/longhorn/backupstore/logging"
"github.com/longhorn/backupstore/types"
)
func InspectVolume(volumeURL string) (*VolumeInfo, error) {
driver, err := GetBackupStoreDriver(volumeURL)
if err != nil {
return nil, err
}
_, volumeName, _, err := DecodeBackupURL(volumeURL)
if err != nil {
return nil, err
}
volume, err := loadVolume(driver, volumeName)
if err != nil {
return nil, err
}
return fillVolumeInfo(volume), nil
}
func InspectBackup(backupURL string) (*BackupInfo, error) {
driver, err := GetBackupStoreDriver(backupURL)
if err != nil {
return nil, err
}
backupName, volumeName, _, err := DecodeBackupURL(backupURL)
if err != nil {
return nil, err
}
volume, err := loadVolume(driver, volumeName)
if err != nil {
return nil, err
}
backup, err := loadBackup(driver, backupName, volumeName)
if err != nil {
log.WithFields(logrus.Fields{
LogFieldReason: LogReasonFallback,
LogFieldEvent: LogEventList,
LogFieldObject: LogObjectBackup,
LogFieldBackup: backupName,
LogFieldVolume: volumeName,
}).Info("Failed to load backup in backupstore")
return nil, err
} else if isBackupInProgress(backup) {
// for now we don't return in progress backups to the ui
return nil, fmt.Errorf("backup %v is still in progress", backup.Name)
}
return fillFullBackupInfo(backup, volume, driver.GetURL()), nil
}
func fillVolumeInfo(volume *Volume) *VolumeInfo {
return &VolumeInfo{
Name: volume.Name,
Size: volume.Size,
Labels: volume.Labels,
Created: volume.CreatedTime,
LastBackupName: volume.LastBackupName,
LastBackupAt: volume.LastBackupAt,
DataStored: int64(volume.BlockCount * DEFAULT_BLOCK_SIZE),
Messages: make(map[types.MessageType]string),
Backups: make(map[string]*BackupInfo),
BackingImageName: volume.BackingImageName,
BackingImageChecksum: volume.BackingImageChecksum,
StorageClassname: volume.StorageClassName,
DataEngine: volume.DataEngine,
}
}
func fillBackupInfo(backup *Backup, destURL string) *BackupInfo {
return &BackupInfo{
Name: backup.Name,
URL: EncodeBackupURL(backup.Name, backup.VolumeName, destURL),
SnapshotName: backup.SnapshotName,
SnapshotCreated: backup.SnapshotCreatedAt,
Created: backup.CreatedTime,
Size: backup.Size,
Labels: backup.Labels,
Parameters: backup.Parameters,
IsIncremental: backup.IsIncremental,
CompressionMethod: backup.CompressionMethod,
NewlyUploadedDataSize: backup.NewlyUploadedDataSize,
ReUploadedDataSize: backup.ReUploadedDataSize,
}
}
func fillFullBackupInfo(backup *Backup, volume *Volume, destURL string) *BackupInfo {
info := fillBackupInfo(backup, destURL)
info.VolumeName = volume.Name
info.VolumeSize = volume.Size
info.VolumeCreated = volume.CreatedTime
info.VolumeBackingImageName = volume.BackingImageName
return info
}