-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
88 lines (72 loc) · 1.8 KB
/
main.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
package main
import (
"context"
"flag"
"fmt"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
"os"
"path/filepath"
)
var bucket = flag.String("bucket", "", "s3 bucket with exported qldb data")
var completedManifestKey = flag.String("completedManifestKey", "", "key of the qldb completed manifest")
var region = flag.String("region", os.Getenv("AWS_REGION"), "AWS region")
func checkRequiredFlags() {
if *bucket == "" {
fmt.Fprintln(os.Stderr, "-bucket is required")
flag.Usage()
os.Exit(1)
}
if *region == "" {
fmt.Fprintln(os.Stderr, "-region is required")
flag.Usage()
os.Exit(1)
}
if *completedManifestKey == "" {
fmt.Fprintln(os.Stderr, "-completedManifestKey is required")
flag.Usage()
os.Exit(1)
}
}
func main() {
flag.Parse()
checkRequiredFlags()
ctx := context.Background()
cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
panic(err)
}
client := s3.NewFromConfig(cfg, func(o *s3.Options) {
o.Region = *region
})
cwd, err := os.Getwd()
if err != nil {
panic(err)
}
dir := filepath.Join(cwd, "vehicle-registration")
dlr := NewS3Downloader(dir, *bucket, client)
completedManifestLocalPath, err := dlr.Download(ctx, *completedManifestKey)
if err != nil {
panic(err)
}
dataKeys, err := ExtractKeysFromCompletedManifest(completedManifestLocalPath)
if err != nil {
panic(err)
}
localDataKeys := make([]string, len(dataKeys))
for idx, key := range dataKeys {
lk, err := dlr.Download(ctx, key)
if err != nil {
panic(err)
}
localDataKeys[idx] = lk
}
outFile := filepath.Join(cwd, "vehicle-registration-replay.sql")
mr := NewQldbToDoltReplayWriter(localDataKeys, outFile)
err = mr.WriteReplay(ctx)
if err != nil {
panic(err)
} else {
fmt.Println("QLDB journal replay Dolt SQL file written to", outFile)
}
}