Skip to content

Commit 07d774a

Browse files
1gtmanisurrahman75
andauthored
[cherry-pick] Add support for providing multiple dump args (#802) (#806)
* Add support for providing multiple dump args (#802) /cherry-pick Signed-off-by: Anisur Rahman <anisur@appscode.com> * fix build Signed-off-by: Anisur Rahman <anisur@appscode.com> --------- Signed-off-by: Anisur Rahman <anisur@appscode.com> Co-authored-by: Md. Anisur Rahman <54911684+anisurrahman75@users.noreply.github.com> Co-authored-by: Anisur Rahman <anisur@appscode.com>
1 parent cc9420a commit 07d774a

File tree

596 files changed

+45294
-283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

596 files changed

+45294
-283
lines changed

go.mod

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.22.1
55
toolchain go1.23.0
66

77
require (
8-
github.com/spf13/cobra v1.8.0
8+
github.com/spf13/cobra v1.8.1
99
go.bytebuilders.dev/license-verifier/kubernetes v0.14.1
1010
gomodules.xyz/flags v0.1.3
1111
gomodules.xyz/go-sh v0.1.0
@@ -14,15 +14,20 @@ require (
1414
k8s.io/apimachinery v0.30.2
1515
k8s.io/client-go v0.30.2
1616
k8s.io/klog/v2 v2.130.1
17-
kmodules.xyz/client-go v0.30.13
17+
kmodules.xyz/client-go v0.30.17
1818
kmodules.xyz/custom-resources v0.30.0
19-
kmodules.xyz/offshoot-api v0.30.0
20-
stash.appscode.dev/apimachinery v0.35.0
19+
kmodules.xyz/offshoot-api v0.30.1
20+
stash.appscode.dev/apimachinery v0.36.1-0.20241121051155-50822965c5af
2121
)
2222

2323
require (
2424
filippo.io/edwards25519 v1.1.0 // indirect
25-
github.com/Masterminds/semver/v3 v3.2.1 // indirect
25+
github.com/Masterminds/semver/v3 v3.3.0 // indirect
26+
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
27+
github.com/zeebo/xxh3 v1.0.2 // indirect
28+
)
29+
30+
require (
2631
github.com/PuerkitoBio/purell v1.2.1 // indirect
2732
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 // indirect
2833
github.com/beorn7/perks v1.0.1 // indirect
@@ -34,6 +39,7 @@ require (
3439
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
3540
github.com/fatih/structs v1.1.0 // indirect
3641
github.com/fsnotify/fsnotify v1.7.0 // indirect
42+
github.com/ghodss/yaml v1.0.0 // indirect
3743
github.com/go-logr/logr v1.4.2 // indirect
3844
github.com/go-openapi/jsonpointer v0.21.0 // indirect
3945
github.com/go-openapi/jsonreference v0.21.0 // indirect
@@ -47,11 +53,11 @@ require (
4753
github.com/google/go-containerregistry v0.19.1 // indirect
4854
github.com/google/gofuzz v1.2.0 // indirect
4955
github.com/google/uuid v1.6.0 // indirect
56+
github.com/gorilla/websocket v1.5.1 // indirect
5057
github.com/imdario/mergo v0.3.16 // indirect
5158
github.com/inconshreveable/mousetrap v1.1.0 // indirect
5259
github.com/josharian/intern v1.0.0 // indirect
5360
github.com/json-iterator/go v1.1.12 // indirect
54-
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
5561
github.com/mailru/easyjson v0.7.7 // indirect
5662
github.com/mitchellh/mapstructure v1.5.0 // indirect
5763
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
@@ -64,20 +70,24 @@ require (
6470
github.com/prometheus/client_model v0.6.1 // indirect
6571
github.com/prometheus/common v0.46.0 // indirect
6672
github.com/prometheus/procfs v0.15.0 // indirect
73+
github.com/rancher/norman v0.0.0-20240708202514-a0127673d1b9 // indirect
74+
github.com/rancher/rancher/pkg/client v0.0.0-20240710123941-93e332156bbe // indirect
75+
github.com/rancher/wrangler/v3 v3.0.0 // indirect
6776
github.com/rogpeppe/go-internal v1.12.0 // indirect
6877
github.com/sergi/go-diff v1.2.0 // indirect
78+
github.com/sirupsen/logrus v1.9.3 // indirect
6979
github.com/spf13/pflag v1.0.5 // indirect
7080
github.com/yudai/gojsondiff v1.0.0 // indirect
7181
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
72-
github.com/zeebo/xxh3 v1.0.2 // indirect
7382
go.bytebuilders.dev/license-proxyserver v0.0.11 // indirect
74-
go.bytebuilders.dev/license-verifier v0.14.1 // indirect
83+
go.bytebuilders.dev/license-verifier v0.14.2 // indirect
84+
go.uber.org/zap v1.27.0 // indirect
7585
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
76-
golang.org/x/net v0.27.0 // indirect
77-
golang.org/x/oauth2 v0.21.0 // indirect
78-
golang.org/x/sys v0.22.0 // indirect
79-
golang.org/x/term v0.22.0 // indirect
80-
golang.org/x/text v0.16.0 // indirect
86+
golang.org/x/net v0.29.0 // indirect
87+
golang.org/x/oauth2 v0.22.0 // indirect
88+
golang.org/x/sys v0.25.0 // indirect
89+
golang.org/x/term v0.24.0 // indirect
90+
golang.org/x/text v0.18.0 // indirect
8191
golang.org/x/time v0.5.0 // indirect
8292
gomodules.xyz/clock v0.0.0-20200817085942-06523dba733f // indirect
8393
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect

go.sum

Lines changed: 39 additions & 25 deletions
Large diffs are not rendered by default.

pkg/backup.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package pkg
1919
import (
2020
"context"
2121
"path/filepath"
22-
"strings"
2322

2423
api_v1beta1 "stash.appscode.dev/apimachinery/apis/stash/v1beta1"
2524
stash "stash.appscode.dev/apimachinery/client/clientset/versioned"
@@ -116,6 +115,7 @@ func NewCmdBackup() *cobra.Command {
116115
}
117116

118117
cmd.Flags().StringVar(&opt.myArgs, "mysql-args", opt.myArgs, "Additional arguments")
118+
cmd.Flags().StringVar(&opt.multiDumpArgs, "multi-dump-args", opt.multiDumpArgs, "Arguments for the multiple dump commands")
119119
cmd.Flags().Int32Var(&opt.waitTimeout, "wait-timeout", opt.waitTimeout, "Time limit to wait for the database to be ready")
120120

121121
cmd.Flags().StringVar(&masterURL, "master", masterURL, "The address of the Kubernetes API server (overrides any value in kubeconfig)")
@@ -222,10 +222,7 @@ func (opt *mysqlOptions) backupMySQL(targetRef api_v1beta1.TargetRef) (*restic.B
222222
}
223223

224224
session.setUserArgs(opt.myArgs)
225-
if strings.Contains(opt.myArgs, "--all-databases") {
226-
session.cmd.Args = append(session.cmd.Args, "--ignore-table=mysql.user")
227-
}
228-
225+
session.setMultiDumpArgs(opt.multiDumpArgs)
229226
// add backup command in the pipeline
230227
opt.backupOptions.StdinPipeCommands = append(opt.backupOptions.StdinPipeCommands, *session.cmd)
231228
resticWrapper, err := restic.NewResticWrapperFromShell(opt.setupOptions, session.sh)

pkg/utils.go

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ import (
3939
)
4040

4141
const (
42-
MySqlUser = "username"
43-
MySqlPassword = "password"
44-
MySqlDumpFile = "dumpfile.sql"
45-
MySqlDumpCMD = "mysqldump"
46-
MySqlRestoreCMD = "mysql"
47-
EnvMySqlPassword = "MYSQL_PWD"
42+
MySqlUser = "username"
43+
MySqlPassword = "password"
44+
MySqlDumpFile = "dumpfile.sql"
45+
MySqlDumpCMD = "mysqldump"
46+
BashCMD = "/bin/bash"
47+
MySqlRestoreCMD = "mysql"
48+
EnvMySqlPassword = "MYSQL_PWD"
49+
multiDumpSeparator = "$args="
4850
)
4951

5052
type mysqlOptions struct {
@@ -57,6 +59,7 @@ type mysqlOptions struct {
5759
appBindingName string
5860
appBindingNamespace string
5961
myArgs string
62+
multiDumpArgs string
6063
waitTimeout int32
6164
outputDir string
6265
storageSecret kmapi.ObjectReference
@@ -121,6 +124,51 @@ func (session *sessionWrapper) setUserArgs(args string) {
121124
}
122125
}
123126

127+
func (session *sessionWrapper) setMultiDumpArgs(args string) {
128+
if args == "" {
129+
return
130+
}
131+
132+
commonArgs := session.buildCommonArgsString()
133+
dumpArgs := extractMultiDumpArgs(args)
134+
if dumpArgs == nil {
135+
return
136+
}
137+
138+
// First Bash Command
139+
session.cmd.Args = append([]interface{}{session.cmd.Name},
140+
append(session.cmd.Args, dumpArgs[0])...)
141+
session.cmd.Name = BashCMD
142+
for idx := 1; idx < len(dumpArgs); idx++ {
143+
session.cmd.Args = append(session.cmd.Args,
144+
fmt.Sprintf("&& %s %s %s", MySqlDumpCMD, commonArgs, dumpArgs[idx]))
145+
}
146+
}
147+
148+
func (session *sessionWrapper) buildCommonArgsString() string {
149+
var builder strings.Builder
150+
for _, arg := range session.cmd.Args {
151+
builder.WriteString(fmt.Sprintf(" %v", arg))
152+
}
153+
return strings.TrimSpace(builder.String())
154+
}
155+
156+
func extractMultiDumpArgs(input string) []string {
157+
parts := strings.Split(input, multiDumpSeparator)
158+
if len(parts) <= 1 {
159+
return nil
160+
}
161+
162+
result := make([]string, 0, len(parts)-1)
163+
for _, part := range parts[1:] {
164+
if trimmed := strings.TrimSpace(part); trimmed != "" {
165+
result = append(result, trimmed)
166+
}
167+
}
168+
169+
return result
170+
}
171+
124172
func (session *sessionWrapper) setTLSParameters(appBinding *appcatalog.AppBinding, scratchDir string) error {
125173
// if ssl enabled, add ca.crt in the arguments
126174
if appBinding.Spec.ClientConfig.CABundle != nil {

vendor/github.com/Masterminds/semver/v3/CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Masterminds/semver/v3/Makefile

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Masterminds/semver/v3/README.md

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)