forked from odise/etcd-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (40 loc) · 1.28 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 (
"os"
"time"
"github.com/coreos/go-etcd/etcd"
)
var (
etcdClient *etcd.Client
)
func main() {
args := os.Args
startTime := time.Now()
backupModeAction := args[len(args)-1]
etcdClient = initializeClient(config.EtcdConfigPath)
ExecuteAction(backupModeAction, etcdClient)
config.LogPrintln("Done!", backupModeAction, "executed in", time.Now().Sub(startTime))
}
func initializeClient(configFilePath string) *etcd.Client {
etcdClient, error := etcd.NewClientFromFile(configFilePath)
if error != nil {
config.LogFatal("Error when trying to load the configuration file: `"+configFilePath+"`. Error: ", error)
}
success := etcdClient.SyncCluster()
if !success {
config.LogFatal("cannot sync machines")
}
return etcdClient
}
func ExecuteAction(action string, etcdClient EtcdClient) {
if action == "restore" {
dataSetLoad := LoadDataSet(config.DumpFilePath)
config.LogPrintln("Restoring dataSet in progress...")
RestoreDataSet(*dataSetLoad, config, etcdClient)
} else if action == "dump" {
dataSet := DownloadDataSet(&BackupStrategy{[]string{"/"}, true, true}, etcdClient)
DumpDataSet(dataSet, config.DumpFilePath)
} else {
config.LogFatal("Error no default mode found. Got `" + action + "`. Try `restore` to restore or `dump` to persist data")
}
}