Add more mysql options
All checks were successful
continuous-integration/drone/push Build is passing
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:
parent
ced262d52c
commit
12b1cfbb06
23
tasks.go
23
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.
|
// JobTaskMySQL is a sqlite backup task that performs required pre and post tasks.
|
||||||
type JobTaskMySQL struct {
|
type JobTaskMySQL struct {
|
||||||
Port int `hcl:"port,optional"`
|
Port int `hcl:"port,optional"`
|
||||||
Name string `hcl:"name,label"`
|
Name string `hcl:"name,label"`
|
||||||
Hostname string `hcl:"hostname,optional"`
|
Hostname string `hcl:"hostname,optional"`
|
||||||
Database string `hcl:"database,optional"`
|
Database string `hcl:"database,optional"`
|
||||||
Username string `hcl:"username,optional"`
|
Username string `hcl:"username,optional"`
|
||||||
Password string `hcl:"password,optional"`
|
Password string `hcl:"password,optional"`
|
||||||
Tables []string `hcl:"tables,optional"`
|
Tables []string `hcl:"tables,optional"`
|
||||||
DumpToPath string `hcl:"dump_to"`
|
NoTablespaces bool `hcl:"no_tablespaces,optional"`
|
||||||
|
DumpToPath string `hcl:"dump_to"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t JobTaskMySQL) Paths() []string {
|
func (t JobTaskMySQL) Paths() []string {
|
||||||
@ -126,8 +127,14 @@ func (t JobTaskMySQL) GetPreTask() ExecutableTask {
|
|||||||
command = append(command, "--password", t.Password)
|
command = append(command, "--password", t.Password)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if t.NoTablespaces {
|
||||||
|
command = append(command, "--no-tablespaces")
|
||||||
|
}
|
||||||
|
|
||||||
if t.Database != "" {
|
if t.Database != "" {
|
||||||
command = append(command, t.Database)
|
command = append(command, t.Database)
|
||||||
|
} else {
|
||||||
|
command = append(command, "--all-databases")
|
||||||
}
|
}
|
||||||
|
|
||||||
command = append(command, t.Tables...)
|
command = append(command, t.Tables...)
|
||||||
|
@ -126,7 +126,7 @@ func TestJobTaskSql(t *testing.T) {
|
|||||||
DumpToPath: "./simple.sql",
|
DumpToPath: "./simple.sql",
|
||||||
},
|
},
|
||||||
validationErr: nil,
|
validationErr: nil,
|
||||||
preBackup: "mysqldump --result-file ./simple.sql",
|
preBackup: "mysqldump --result-file ./simple.sql --all-databases",
|
||||||
postBackup: "",
|
postBackup: "",
|
||||||
preRestore: "",
|
preRestore: "",
|
||||||
postRestore: "mysql < ./simple.sql",
|
postRestore: "mysql < ./simple.sql",
|
||||||
@ -148,18 +148,19 @@ func TestJobTaskSql(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "mysql all options",
|
name: "mysql all options",
|
||||||
task: main.JobTaskMySQL{
|
task: main.JobTaskMySQL{
|
||||||
Name: "simple",
|
Name: "simple",
|
||||||
Hostname: "host",
|
Hostname: "host",
|
||||||
Port: 3306,
|
Port: 3306,
|
||||||
Username: "user",
|
Username: "user",
|
||||||
Password: "pass",
|
Password: "pass",
|
||||||
Database: "db",
|
Database: "db",
|
||||||
Tables: []string{"table1", "table2"},
|
NoTablespaces: true,
|
||||||
DumpToPath: "./simple.sql",
|
Tables: []string{"table1", "table2"},
|
||||||
|
DumpToPath: "./simple.sql",
|
||||||
},
|
},
|
||||||
validationErr: nil,
|
validationErr: nil,
|
||||||
preBackup: "mysqldump --result-file ./simple.sql --host host --port 3306" +
|
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: "",
|
postBackup: "",
|
||||||
preRestore: "",
|
preRestore: "",
|
||||||
postRestore: "mysql --host host --user user --password pass < ./simple.sql",
|
postRestore: "mysql --host host --user user --password pass < ./simple.sql",
|
||||||
|
Loading…
Reference in New Issue
Block a user