Add port specification to mysqldump
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
IamTheFij 2022-04-14 09:14:16 -07:00
parent 2b8b450861
commit 7935aaff96
2 changed files with 12 additions and 4 deletions

View File

@ -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)
}

View File

@ -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,7 +158,8 @@ 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",
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",