From 12b1cfbb0668303e5a1c9476d6e3f3f70cc419da Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Fri, 15 Apr 2022 10:25:29 -0700 Subject: [PATCH] Add more mysql options Default to --all-databases if none specified and add --no-tablespaces option --- tasks.go | 23 +++++++++++++++-------- tasks_test.go | 21 +++++++++++---------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/tasks.go b/tasks.go index 7d01515..a7c1d4a 100644 --- a/tasks.go +++ b/tasks.go @@ -69,14 +69,15 @@ 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"` - Username string `hcl:"username,optional"` - Password string `hcl:"password,optional"` - Tables []string `hcl:"tables,optional"` - DumpToPath string `hcl:"dump_to"` + Port int `hcl:"port,optional"` + Name string `hcl:"name,label"` + Hostname string `hcl:"hostname,optional"` + Database string `hcl:"database,optional"` + Username string `hcl:"username,optional"` + Password string `hcl:"password,optional"` + Tables []string `hcl:"tables,optional"` + NoTablespaces bool `hcl:"no_tablespaces,optional"` + DumpToPath string `hcl:"dump_to"` } func (t JobTaskMySQL) Paths() []string { @@ -126,8 +127,14 @@ func (t JobTaskMySQL) GetPreTask() ExecutableTask { command = append(command, "--password", t.Password) } + if t.NoTablespaces { + command = append(command, "--no-tablespaces") + } + if t.Database != "" { command = append(command, t.Database) + } else { + command = append(command, "--all-databases") } command = append(command, t.Tables...) diff --git a/tasks_test.go b/tasks_test.go index b021df2..46f36ef 100644 --- a/tasks_test.go +++ b/tasks_test.go @@ -126,7 +126,7 @@ func TestJobTaskSql(t *testing.T) { DumpToPath: "./simple.sql", }, validationErr: nil, - preBackup: "mysqldump --result-file ./simple.sql", + preBackup: "mysqldump --result-file ./simple.sql --all-databases", postBackup: "", preRestore: "", postRestore: "mysql < ./simple.sql", @@ -148,18 +148,19 @@ func TestJobTaskSql(t *testing.T) { { name: "mysql all options", task: main.JobTaskMySQL{ - Name: "simple", - Hostname: "host", - Port: 3306, - Username: "user", - Password: "pass", - Database: "db", - Tables: []string{"table1", "table2"}, - DumpToPath: "./simple.sql", + Name: "simple", + Hostname: "host", + Port: 3306, + Username: "user", + Password: "pass", + Database: "db", + NoTablespaces: true, + Tables: []string{"table1", "table2"}, + DumpToPath: "./simple.sql", }, validationErr: nil, preBackup: "mysqldump --result-file ./simple.sql --host host --port 3306" + - " --user user --password pass db table1 table2", + " --user user --password pass --no-tablespaces db table1 table2", postBackup: "", preRestore: "", postRestore: "mysql --host host --user user --password pass < ./simple.sql",