This repository has been archived by the owner on May 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
gpbackup_s3_plugin.go
137 lines (130 loc) · 2.98 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package main
import (
"fmt"
"os"
"github.com/greenplum-db/gp-common-go-libs/gplog"
"github.com/greenplum-db/gpbackup-s3-plugin/s3plugin"
"github.com/urfave/cli"
)
func main() {
gplog.InitializeLogging("gpbackup_s3_plugin", "")
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 conjunction 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: "backup_directory",
Action: s3plugin.BackupDirectory,
Before: buildBeforeFunc(2, 3),
Hidden: true,
},
{
Name: "backup_directory_parallel",
Action: s3plugin.BackupDirectoryParallel,
Before: buildBeforeFunc(2, 3),
Hidden: true,
},
{
Name: "restore_file",
Action: s3plugin.RestoreFile,
Before: buildBeforeFunc(2),
},
{
Name: "restore_directory",
Action: s3plugin.RestoreDirectory,
Before: buildBeforeFunc(2, 3),
Hidden: true,
},
{
Name: "restore_directory_parallel",
Action: s3plugin.RestoreDirectoryParallel,
Before: buildBeforeFunc(2, 3),
Hidden: true,
},
{
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),
},
{
Name: "delete_backup",
Action: s3plugin.DeleteBackup,
Before: buildBeforeFunc(2),
},
{
Name: "delete_directory",
Action: s3plugin.DeleteDirectory,
Before: buildBeforeFunc(2),
},
{
Name: "list_directory",
Action: s3plugin.ListDirectory,
Before: buildBeforeFunc(1, 2),
},
}
err := app.Run(os.Args)
if err != nil {
gplog.Error(err.Error())
os.Exit(1)
}
}
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("ERROR: Invalid number of arguments to plugin command. "+
"Expected %v arguments. Got %d arguments", expectedNArgs, actualNArg)
} else {
return nil
}
}
return beforeFunc
}