From 7935aaff96e5f41c4a5f238712cf51df7bcafc90 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Thu, 14 Apr 2022 09:14:16 -0700 Subject: [PATCH] Add port specification to mysqldump --- tasks.go | 5 +++++ tasks_test.go | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tasks.go b/tasks.go index 2227367..7d01515 100644 --- a/tasks.go +++ b/tasks.go @@ -69,6 +69,7 @@ func (t *JobTaskScript) SetName(name string) { // JobTaskMySQL is a sqlite backup task that performs required pre and post tasks. type JobTaskMySQL struct { + Port int `hcl:"port,optional"` Name string `hcl:"name,label"` Hostname string `hcl:"hostname,optional"` Database string `hcl:"database,optional"` @@ -113,6 +114,10 @@ func (t JobTaskMySQL) GetPreTask() ExecutableTask { command = append(command, "--host", t.Hostname) } + if t.Port != 0 { + command = append(command, "--port", fmt.Sprintf("%d", t.Port)) + } + if t.Username != "" { command = append(command, "--user", t.Username) } diff --git a/tasks_test.go b/tasks_test.go index 313c640..b021df2 100644 --- a/tasks_test.go +++ b/tasks_test.go @@ -15,6 +15,7 @@ func NewBufferedLogger(prefix string) (*bytes.Buffer, *log.Logger) { return &outputBuffer, logger } + func TestJobTaskScript(t *testing.T) { t.Parallel() @@ -149,6 +150,7 @@ func TestJobTaskSql(t *testing.T) { task: main.JobTaskMySQL{ Name: "simple", Hostname: "host", + Port: 3306, Username: "user", Password: "pass", Database: "db", @@ -156,10 +158,11 @@ func TestJobTaskSql(t *testing.T) { DumpToPath: "./simple.sql", }, validationErr: nil, - preBackup: "mysqldump --result-file ./simple.sql --host host --user user --password pass db table1 table2", - postBackup: "", - preRestore: "", - postRestore: "mysql --host host --user user --password pass < ./simple.sql", + preBackup: "mysqldump --result-file ./simple.sql --host host --port 3306" + + " --user user --password pass db table1 table2", + postBackup: "", + preRestore: "", + postRestore: "mysql --host host --user user --password pass < ./simple.sql", }, // Sqlite {