Add more mysql options
All checks were successful
continuous-integration/drone/push Build is passing

Default to --all-databases if none specified and add --no-tablespaces option
This commit is contained in:
IamTheFij 2022-04-15 10:25:29 -07:00
parent ced262d52c
commit 12b1cfbb06
2 changed files with 26 additions and 18 deletions

View File

@ -76,6 +76,7 @@ type JobTaskMySQL struct {
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"`
}
@ -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...)

View File

@ -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",
@ -154,12 +154,13 @@ func TestJobTaskSql(t *testing.T) {
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",