forked from wal-g/wal-g
/
binary_backup_fetch_handler.go
45 lines (36 loc) · 1.08 KB
/
binary_backup_fetch_handler.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
package mongo
import (
"context"
"github.com/T0n0T/wal-g/internal"
"github.com/T0n0T/wal-g/internal/databases/mongo/binary"
"github.com/T0n0T/wal-g/utility"
)
func HandleBinaryFetchPush(ctx context.Context, mongodConfigPath, minimalConfigPath, backupName, restoreMongodVersion,
rsName, rsMembers string,
) error {
config, err := binary.CreateMongodConfig(mongodConfigPath)
if err != nil {
return err
}
localStorage := binary.CreateLocalStorage(config.GetDBPath())
uploader, err := internal.ConfigureUploader()
if err != nil {
return err
}
uploader.ChangeDirectory(utility.BaseBackupPath + "/")
if minimalConfigPath == "" {
minimalConfigPath, err = config.SaveConfigToTempFile("storage", "systemLog")
if err != nil {
return err
}
}
restoreService, err := binary.CreateRestoreService(ctx, localStorage, uploader, minimalConfigPath)
if err != nil {
return err
}
rsConfig := binary.RsConfig{RsName: rsName, RsMembers: rsMembers}
if err = rsConfig.Validate(); err != nil {
return err
}
return restoreService.DoRestore(backupName, restoreMongodVersion, rsConfig)
}