@@ -2,6 +2,7 @@ package backup
2
2
3
3
import (
4
4
"context"
5
+ "encoding/json"
5
6
"path"
6
7
"runtime"
7
8
"sync"
@@ -16,12 +17,45 @@ import (
16
17
"github.com/percona/percona-backup-mongodb/pbm/version"
17
18
)
18
19
19
- func CheckBackupFiles (ctx context.Context , bcp * BackupMeta , stg storage.Storage ) error {
20
- // !!! TODO: Check physical files ?
21
- if bcp .Type != defs .LogicalBackup {
22
- return nil
20
+ func CheckBackupFiles (ctx context.Context , stg storage.Storage , name string ) error {
21
+ bcp , err := ReadMetadata (stg , name + defs .MetadataFileSuffix )
22
+ if err != nil {
23
+ return errors .Wrap (err , "read backup metadata" )
24
+ }
25
+
26
+ return CheckBackupDataFiles (ctx , stg , bcp )
27
+ }
28
+
29
+ func ReadMetadata (stg storage.Storage , filename string ) (* BackupMeta , error ) {
30
+ rdr , err := stg .SourceReader (filename )
31
+ if err != nil {
32
+ return nil , errors .Wrap (err , "open" )
33
+ }
34
+ defer rdr .Close ()
35
+
36
+ var meta * BackupMeta
37
+ err = json .NewDecoder (rdr ).Decode (& meta )
38
+ if err != nil {
39
+ return nil , errors .Wrap (err , "decode" )
23
40
}
24
41
42
+ return meta , nil
43
+ }
44
+
45
+ func CheckBackupDataFiles (ctx context.Context , stg storage.Storage , bcp * BackupMeta ) error {
46
+ switch bcp .Type {
47
+ case defs .LogicalBackup :
48
+ return checkLogicalBackupFiles (ctx , stg , bcp )
49
+ case defs .PhysicalBackup , defs .IncrementalBackup :
50
+ return checkPhysicalBackupFiles (ctx , stg , bcp )
51
+ case defs .ExternalBackup :
52
+ return nil // no files available
53
+ }
54
+
55
+ return errors .Errorf ("unknown backup type %s" , bcp .Type )
56
+ }
57
+
58
+ func checkLogicalBackupFiles (ctx context.Context , stg storage.Storage , bcp * BackupMeta ) error {
25
59
legacy := version .IsLegacyArchive (bcp .PBMVersion )
26
60
eg , _ := errgroup .WithContext (ctx )
27
61
for _ , rs := range bcp .Replsets {
@@ -74,6 +108,10 @@ func CheckBackupFiles(ctx context.Context, bcp *BackupMeta, stg storage.Storage)
74
108
return eg .Wait ()
75
109
}
76
110
111
+ func checkPhysicalBackupFiles (ctx context.Context , stg storage.Storage , bcp * BackupMeta ) error {
112
+ return nil
113
+ }
114
+
77
115
func ReadArchiveNamespaces (stg storage.Storage , metafile string ) ([]* archive.Namespace , error ) {
78
116
r , err := stg .SourceReader (metafile )
79
117
if err != nil {
0 commit comments