diff --git a/pkg/backup.go b/pkg/backup.go index 926a909ab..151c57457 100644 --- a/pkg/backup.go +++ b/pkg/backup.go @@ -18,6 +18,7 @@ package pkg import ( "context" + "fmt" "path/filepath" "strings" @@ -212,6 +213,10 @@ func (opt *mysqlOptions) backupMySQL(targetRef api_v1beta1.TargetRef) (*restic.B "-h", appBinding.Spec.ClientConfig.Service.Name, }, } + // if port is specified, append port in the arguments + if appBinding.Spec.ClientConfig.Service.Port != 0 { + opt.backupOptions.StdinPipeCommand.Args = append(opt.backupOptions.StdinPipeCommand.Args, fmt.Sprintf("--port=%d", appBinding.Spec.ClientConfig.Service.Port)) + } for _, arg := range strings.Fields(opt.myArgs) { opt.backupOptions.StdinPipeCommand.Args = append(opt.backupOptions.StdinPipeCommand.Args, arg) } diff --git a/pkg/restore.go b/pkg/restore.go index 45f1f0c93..19e544607 100644 --- a/pkg/restore.go +++ b/pkg/restore.go @@ -18,6 +18,7 @@ package pkg import ( "context" + "fmt" "path/filepath" "strings" @@ -181,6 +182,10 @@ func (opt *mysqlOptions) restoreMySQL(targetRef api_v1beta1.TargetRef) (*restic. "-h", appBinding.Spec.ClientConfig.Service.Name, }, } + // if port is specified, append port in the arguments + if appBinding.Spec.ClientConfig.Service.Port != 0 { + opt.dumpOptions.StdoutPipeCommand.Args = append(opt.dumpOptions.StdoutPipeCommand.Args, fmt.Sprintf("--port=%d", appBinding.Spec.ClientConfig.Service.Port)) + } for _, arg := range strings.Fields(opt.myArgs) { opt.dumpOptions.StdoutPipeCommand.Args = append(opt.dumpOptions.StdoutPipeCommand.Args, arg) } diff --git a/pkg/utils.go b/pkg/utils.go index 25c7da586..cb9c35bcb 100644 --- a/pkg/utils.go +++ b/pkg/utils.go @@ -66,5 +66,8 @@ func waitForDBReady(appBinding *v1alpha1.AppBinding, secret *core.Secret, waitTi "--user=root", fmt.Sprintf("--wait=%d", waitTimeout), } + if appBinding.Spec.ClientConfig.Service.Port != 0 { + args = append(args, fmt.Sprintf("--port=%d", appBinding.Spec.ClientConfig.Service.Port)) + } return shell.Command("mysqladmin", args...).Run() }