-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.go
64 lines (50 loc) · 1.24 KB
/
backup.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
package backup
import (
"github.com/KalyCoinProject/kalychain/command"
"github.com/spf13/cobra"
"github.com/KalyCoinProject/kalychain/command/helper"
)
func GetCommand() *cobra.Command {
backupCmd := &cobra.Command{
Use: "backup",
Short: "Create blockchain backup file by fetching blockchain data from the running node",
PreRunE: runPreRun,
Run: runCommand,
}
helper.RegisterGRPCAddressFlag(backupCmd)
setFlags(backupCmd)
helper.SetRequiredFlags(backupCmd, params.getRequiredFlags())
return backupCmd
}
func setFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(
¶ms.out,
outFlag,
"",
"the export path for the backup",
)
cmd.Flags().StringVar(
¶ms.fromRaw,
fromFlag,
"0",
"the beginning height of the chain in backup",
)
cmd.Flags().StringVar(
¶ms.toRaw,
toFlag,
"",
"the end height of the chain in backup",
)
}
func runPreRun(_ *cobra.Command, _ []string) error {
return params.validateFlags()
}
func runCommand(cmd *cobra.Command, _ []string) {
outputter := command.InitializeOutputter(cmd)
defer outputter.WriteOutput()
if err := params.createBackup(helper.GetGRPCAddress(cmd)); err != nil {
outputter.SetError(err)
return
}
outputter.SetCommandResult(params.getResult())
}