forked from greenplum-db/gpbackup-s3-plugin-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpbackup_s3_plugin.go
97 lines (89 loc) · 2.03 KB
/
gpbackup_s3_plugin.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
91
92
93
94
95
96
97
// +build gpbackup_s3_plugin
package main
import (
"fmt"
"log"
"os"
"github.com/greenplum-db/gpbackup-s3-plugin/s3plugin"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
cli.VersionFlag = cli.BoolFlag{
Name: "version",
Usage: "print version of gpbackup_s3_plugin",
}
app.Version = s3plugin.Version
app.Usage = ""
app.UsageText = "Not supported as a standalone utility. This plugin must be used in conjuction with gpbackup and gprestore."
app.Commands = []cli.Command{
{
Name: "setup_plugin_for_backup",
Action: s3plugin.SetupPluginForBackup,
Before: buildBeforeFunc(3, 4),
},
{
Name: "setup_plugin_for_restore",
Action: s3plugin.SetupPluginForRestore,
Before: buildBeforeFunc(3, 4),
},
{
Name: "cleanup_plugin_for_backup",
Action: s3plugin.CleanupPlugin,
Before: buildBeforeFunc(3, 4),
},
{
Name: "cleanup_plugin_for_restore",
Action: s3plugin.CleanupPlugin,
Before: buildBeforeFunc(3, 4),
},
{
Name: "backup_file",
Action: s3plugin.BackupFile,
Before: buildBeforeFunc(2),
},
{
Name: "restore_file",
Action: s3plugin.RestoreFile,
Before: buildBeforeFunc(2),
},
{
Name: "backup_data",
Action: s3plugin.BackupData,
Before: buildBeforeFunc(2),
},
{
Name: "restore_data",
Action: s3plugin.RestoreData,
Before: buildBeforeFunc(2),
},
{
Name: "plugin_api_version",
Action: s3plugin.GetAPIVersion,
Before: buildBeforeFunc(0),
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func buildBeforeFunc(expectedNArgs ...int) (beforeFunc cli.BeforeFunc) {
beforeFunc = func(context *cli.Context) error {
actualNArg := context.NArg()
argMatched := false
for _, expectedNArg := range expectedNArgs {
if actualNArg == expectedNArg {
argMatched = true
break
}
}
if !argMatched {
return fmt.Errorf("Invalid number of arguments to plugin command. "+
"Expected %v arguments. Got %d arguments", expectedNArgs, actualNArg)
} else {
return nil
}
}
return beforeFunc
}