-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (42 loc) · 1.38 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
package main
import (
"log"
"github.com/mschuchard/vault-raft-backup/storage"
"github.com/mschuchard/vault-raft-backup/util"
"github.com/mschuchard/vault-raft-backup/vault"
)
func main() {
// invoke cli parsing
hclConfigPath := util.Cli()
// construct vault raft backup config
backupConfig, err := util.NewBackupConfig(*hclConfigPath)
if err != nil {
log.Print("vault raft backup configuration failed validation")
log.Fatal(err)
}
// construct vault client config
vaultConfig, err := vault.NewVaultConfig(backupConfig.VaultConfig)
if err != nil {
log.Print("Vault configuration failed validation")
log.Fatal(err)
}
// initialize and configure vault client
vaultClient, err := vault.NewVaultClient(vaultConfig)
if err != nil {
log.Print("Vault client initialization and configuration failed")
log.Fatal(err)
}
// vault raft snapshot
snapshotFile, err := vault.VaultRaftSnapshot(vaultClient, vaultConfig.SnapshotPath())
if err != nil {
log.Print("Vault Raft snapshot failed")
log.Fatal(err)
}
// transfer snapshot to cloud storage
err = storage.StorageTransfer(backupConfig.CloudConfig, snapshotFile.Name(), backupConfig.SnapshotCleanup)
if err != nil && err.Error() != "snapshot not found" && err.Error() != "snapshot not removed" {
// not an error from failed removal so error is actually fatal
log.Print("cloud storage upload failed")
log.Fatal(err)
}
}