-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
86 lines (74 loc) · 1.99 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
package main
import (
"flag"
"log"
"os"
"path"
"github.com/allthatjazzleo/auto-snapshot/internal"
)
func main() {
// Define flags
chainHomeDir := flag.String("chain-home", "", "The chain home directory")
keepLocal := flag.Bool("keep-local", false, "Keep the local compressed file")
uploaderType := flag.String("uploader", "s3", "Uploader type (s3/gcs/none) - set none to disable upload")
nodeType := flag.String("node-type", "", "Node type (archive/default)")
// Parse flags
flag.Parse()
// Validate flags
if *chainHomeDir == "" {
log.Println("chain-home flag is required")
flag.Usage()
os.Exit(1)
}
dataDir := path.Join(*chainHomeDir, "data")
// Call checkVersion
height, backendType, err := internal.CheckVersionAndDB(dataDir)
if err != nil {
log.Printf("Error: %v\n", err)
os.Exit(1)
}
// Print the result
log.Printf("Height: %d\n", height)
// get chain_id
chainID, err := internal.GetChainID(*chainHomeDir)
if err != nil {
log.Printf("Error: %v\n", err)
os.Exit(1)
}
log.Printf("Chain ID: %s\n", chainID)
var uploader internal.Uploader
switch *uploaderType {
case "s3":
config, err := internal.LoadConfig()
if err != nil {
log.Printf("Error loading AWS config: %v\n", err)
os.Exit(1)
}
s3Bucket := os.Getenv("AWS_S3_BUCKET")
if s3Bucket == "" {
log.Printf("AWS_S3_BUCKET environment variable not set")
os.Exit(1)
}
uploader, err = internal.NewS3Uploader(s3Bucket, config)
if err != nil {
log.Printf("Error creating S3 uploader: %v\n", err)
os.Exit(1)
}
case "gcs":
gcsBucket := os.Getenv("GCS_BUCKET")
if gcsBucket == "" {
log.Printf("GCS_BUCKET environment variable not set")
os.Exit(1)
}
uploader, err = internal.NewGCSUploader(gcsBucket)
if err != nil {
log.Printf("Error creating GCS uploader: %v\n", err)
os.Exit(1)
}
}
err = internal.Compress(*chainHomeDir, chainID, backendType, height, uploader, *keepLocal, *nodeType)
if err != nil {
log.Printf("Error during compression: %v\n", err)
os.Exit(1)
}
}