-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
90 lines (74 loc) · 1.47 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
89
90
package main
import (
"fmt"
"os"
)
func main() {
pgb, err := NewPgBackups()
if err != nil {
panic(err)
}
action := os.Args[1]
switch action {
case "worker":
runScheduler(pgb)
break
case "run":
pgb.BackupAll()
break
case "list":
listBackups(pgb)
break
case "url":
backupUrl(pgb)
break
}
os.Exit(0)
}
func runScheduler(pgb *PgBackups) {
s := NewScheduler(pgb, os.Getenv("SCHEDULE"))
err := s.Run()
if err != nil {
panic(err)
}
}
func listBackups(pgb *PgBackups) {
if len(os.Args) < 3 {
panic("App name must be given (pgbackups [list] [appname])")
}
appName := os.Args[2]
if appName == "" {
panic("App name must be given (pgbackups list [appname])")
}
app, err := pgb.FlynnClient.GetApp(appName)
if err != nil {
panic(err)
}
backups, err := pgb.Repo.GetBackups(app.ID)
if err != nil {
panic(err)
}
fmt.Printf("App: %s ID: %s\n", app.Name, app.ID)
fmt.Println(" [ID] - [Started] - [Completed] - [Bytes]")
for _, b := range backups {
fmt.Printf(" %s - %s - %s - %d\n", b.BackupID, b.StartedAt, b.CompletedAt, b.Bytes)
}
}
func backupUrl(pgb *PgBackups) {
if len(os.Args) < 3 {
panic("Backup id must be given (pgbackups [url] [backup id])")
}
id := os.Args[2]
if id == "" {
panic("Backup id must be given (pgbackups [url] [backup id])")
}
b, err := pgb.Repo.GetBackup(id)
if err != nil || b == nil {
panic(err)
}
url, err := pgb.Store.DownloadUrl(b.AppID, b.BackupID)
if err != nil {
panic(err)
}
fmt.Println(url)
}