Skip to content

Commit

Permalink
Add support for providing multiple dump args (#802)
Browse files Browse the repository at this point in the history
/cherry-pick

Signed-off-by: Anisur Rahman <[email protected]>
  • Loading branch information
anisurrahman75 authored and 1gtm committed Dec 17, 2024
1 parent cc9420a commit eb99fc3
Show file tree
Hide file tree
Showing 596 changed files with 45,294 additions and 282 deletions.
36 changes: 23 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.1
toolchain go1.23.0

require (
github.com/spf13/cobra v1.8.0
github.com/spf13/cobra v1.8.1
go.bytebuilders.dev/license-verifier/kubernetes v0.14.1
gomodules.xyz/flags v0.1.3
gomodules.xyz/go-sh v0.1.0
Expand All @@ -14,15 +14,20 @@ require (
k8s.io/apimachinery v0.30.2
k8s.io/client-go v0.30.2
k8s.io/klog/v2 v2.130.1
kmodules.xyz/client-go v0.30.13
kmodules.xyz/client-go v0.30.17
kmodules.xyz/custom-resources v0.30.0
kmodules.xyz/offshoot-api v0.30.0
stash.appscode.dev/apimachinery v0.35.0
kmodules.xyz/offshoot-api v0.30.1
stash.appscode.dev/apimachinery v0.36.1-0.20241121051155-50822965c5af
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Masterminds/semver/v3 v3.3.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
)

require (
github.com/PuerkitoBio/purell v1.2.1 // indirect
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand All @@ -34,6 +39,7 @@ require (
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
Expand All @@ -47,11 +53,11 @@ require (
github.com/google/go-containerregistry v0.19.1 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand All @@ -64,20 +70,24 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.46.0 // indirect
github.com/prometheus/procfs v0.15.0 // indirect
github.com/rancher/norman v0.0.0-20240708202514-a0127673d1b9 // indirect
github.com/rancher/rancher/pkg/client v0.0.0-20240710123941-93e332156bbe // indirect
github.com/rancher/wrangler/v3 v3.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.bytebuilders.dev/license-proxyserver v0.0.11 // indirect
go.bytebuilders.dev/license-verifier v0.14.1 // indirect
go.bytebuilders.dev/license-verifier v0.14.2 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/time v0.5.0 // indirect
gomodules.xyz/clock v0.0.0-20200817085942-06523dba733f // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
Expand Down
64 changes: 39 additions & 25 deletions go.sum

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions pkg/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func NewCmdBackup() *cobra.Command {
}

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

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

session.setUserArgs(opt.myArgs)
if strings.Contains(opt.myArgs, "--all-databases") {
session.cmd.Args = append(session.cmd.Args, "--ignore-table=mysql.user")
}

session.setMultiDumpArgs(opt.multiDumpArgs)
// add backup command in the pipeline
opt.backupOptions.StdinPipeCommands = append(opt.backupOptions.StdinPipeCommands, *session.cmd)
resticWrapper, err := restic.NewResticWrapperFromShell(opt.setupOptions, session.sh)
Expand Down
60 changes: 54 additions & 6 deletions pkg/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ import (
)

const (
MySqlUser = "username"
MySqlPassword = "password"
MySqlDumpFile = "dumpfile.sql"
MySqlDumpCMD = "mysqldump"
MySqlRestoreCMD = "mysql"
EnvMySqlPassword = "MYSQL_PWD"
MySqlUser = "username"
MySqlPassword = "password"
MySqlDumpFile = "dumpfile.sql"
MySqlDumpCMD = "mysqldump"
BashCMD = "/bin/bash"
MySqlRestoreCMD = "mysql"
EnvMySqlPassword = "MYSQL_PWD"
multiDumpSeparator = "$args="
)

type mysqlOptions struct {
Expand All @@ -57,6 +59,7 @@ type mysqlOptions struct {
appBindingName string
appBindingNamespace string
myArgs string
multiDumpArgs string
waitTimeout int32
outputDir string
storageSecret kmapi.ObjectReference
Expand Down Expand Up @@ -121,6 +124,51 @@ func (session *sessionWrapper) setUserArgs(args string) {
}
}

func (session *sessionWrapper) setMultiDumpArgs(args string) {
if args == "" {
return
}

commonArgs := session.buildCommonArgsString()
dumpArgs := extractMultiDumpArgs(args)
if dumpArgs == nil {
return
}

// First Bash Command
session.cmd.Args = append([]interface{}{session.cmd.Name},
append(session.cmd.Args, dumpArgs[0])...)
session.cmd.Name = BashCMD
for idx := 1; idx < len(dumpArgs); idx++ {
session.cmd.Args = append(session.cmd.Args,
fmt.Sprintf("&& %s %s %s", MySqlDumpCMD, commonArgs, dumpArgs[idx]))
}
}

func (session *sessionWrapper) buildCommonArgsString() string {
var builder strings.Builder
for _, arg := range session.cmd.Args {
builder.WriteString(fmt.Sprintf(" %v", arg))
}
return strings.TrimSpace(builder.String())
}

func extractMultiDumpArgs(input string) []string {
parts := strings.Split(input, multiDumpSeparator)
if len(parts) <= 1 {
return nil
}

result := make([]string, 0, len(parts)-1)
for _, part := range parts[1:] {
if trimmed := strings.TrimSpace(part); trimmed != "" {
result = append(result, trimmed)
}
}

return result
}

func (session *sessionWrapper) setTLSParameters(appBinding *appcatalog.AppBinding, scratchDir string) error {
// if ssl enabled, add ca.crt in the arguments
if appBinding.Spec.ClientConfig.CABundle != nil {
Expand Down
28 changes: 28 additions & 0 deletions vendor/github.com/Masterminds/semver/v3/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/github.com/Masterminds/semver/v3/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions vendor/github.com/Masterminds/semver/v3/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit eb99fc3

Please sign in to comment.