-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (46 loc) · 1.48 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
package main
import (
"context"
"flag"
"log"
"time"
"github.com/ichbinfrog/cloudsqlmigrate/migrate"
)
func main() {
srcProject := flag.String("src-project", "", "GCP project where the source CloudSQL Instance is provisioned")
srcInstance := flag.String("src-instance", "", "Name of the source CloudSQL Instance")
dstProject := flag.String("dst-project", "", "GCP project where the target CloudSQL Instance is provisioned")
dstInstance := flag.String("dst-instance", "", "Name of the target CloudSQL Instance")
flag.Parse()
if *srcProject == "" {
log.Fatalf("missing argument: src-project is required")
}
if *srcInstance == "" {
log.Fatalf("missing argument: src-instance is required")
}
if *dstProject == "" {
log.Fatalf("missing argument: dst-project is required")
}
if *dstInstance == "" {
log.Fatalf("missing argument: dst-instance is required")
}
ctx := context.Background()
start := time.Now()
log.Printf("starting the migration of %s:%s to %s:%s at %s", *srcProject, *srcInstance, *dstProject, *dstInstance, start.String())
op, err := migrate.NewOp(ctx, *srcProject, *srcInstance, *dstProject, *dstInstance)
if err != nil {
log.Fatal(err)
}
if errs := op.Run(ctx,
[]migrate.Preflight{
migrate.PreflightVersion{},
migrate.PreflightStatus{},
},
[]migrate.PostFlight{
&migrate.PostFlightSQLAdmin{},
},
); len(errs) > 0 {
log.Fatalf("checks failed: %v", errs)
}
log.Printf("operation completed successfully in %s", time.Since(start).String())
}