-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
63 lines (52 loc) · 1.26 KB
/
Copy pathmain.go
File metadata and controls
63 lines (52 loc) · 1.26 KB
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
package main
import (
"log"
"os"
"github.com/jczornik/glacier_backup/config"
"github.com/jczornik/glacier_backup/persistent"
"github.com/jczornik/glacier_backup/tools"
"github.com/jczornik/glacier_backup/workflow"
)
const (
ecRequiredTool = iota
ecConfigPath
ecReadingConf
ecCreatingBackup
ecUploadingBackup
ecCreatingWorkflow
)
func main() {
if err := tools.CheckRequiredTools(); err != nil {
log.Printf("Required tool does not exist. Err: %s\n", err)
os.Exit(ecRequiredTool)
}
if len(os.Args) < 2 {
log.Println("Please specify path to configuration")
os.Exit(ecConfigPath)
}
configPath := os.Args[1]
cfg, err := config.NewConfig(configPath)
if err != nil {
log.Printf("Cannot read configuration. Err: %s\n", err)
os.Exit(ecReadingConf)
}
db := persistent.NewDBClient(cfg.Db)
if err := persistent.CheckAndUpdateSchema(db); err != nil {
log.Println(err)
}
var workflows = make([]workflow.Workflow, len(cfg.Backups))
for i, cbackup := range cfg.Backups {
workflows[i], err = workflow.NewEncryptedBackup(cbackup, cfg.AWS, db)
if err != nil {
log.Println(err)
os.Exit(ecCreatingWorkflow)
}
}
for _, w := range workflows {
if err := w.Exec(); err != nil {
log.Fatal(err)
} else {
log.Println("Workflow OK!")
}
}
}