Skip to content

Commit

Permalink
mysql password fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Onur CEVIK committed Mar 31, 2021
1 parent d13fc15 commit 579e766
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
12 changes: 6 additions & 6 deletions example/dummy_dump_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (

func main() {
dd , err:= dummydump.New(&config.Config{
Source: "postgres",
Source: "mysql",
Import: false,
Export: true,
User: "hakankosanoglu",
Password: "",
User: "testuser",
Password: "123456",
Path: "",
DB: "testt",
BinaryPath: "/usr/local/opt/postgresql@12/bin/pg_dump",
BackupName: "hakan",
DB: "deneme",
BinaryPath: "/usr/bin/mysqldump",
BackupName: "deneme",
})

if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func getImportCommandArg(cfg config.Config) (arg []string) {
dns := fmt.Sprintf(`user=%s password=%s dbname=%s`, cfg.User, cfg.Password, cfg.DB)
arg = []string{dns, pgFlagCreateDatabase, pgFlagCreate, cfg.Path}
case config.MySQL:
arg = []string{mysqlFlagUser, cfg.User, mysqlFlagPassword, cfg.Password, cfg.DB, mysqlFlagExecute, "source " + cfg.Path}
user := fmt.Sprintf("%s=%s", mysqlFlagUser, cfg.User)
password := fmt.Sprintf("%s=%s", mysqlFlagPassword, cfg.Password)
arg = []string{user, password, cfg.DB, mysqlFlagExecute, "source " + cfg.Path}

}
return arg
Expand All @@ -73,7 +75,9 @@ func getExportCommandArg(cfg config.Config) (arg []string) {
dns := fmt.Sprintf(`user=%s password=%s dbname=%s`, cfg.User, cfg.Password, cfg.DB)
arg = []string{dns, pgFlagFileName, filename, pgFlagCreate, pgFlagFormat}
case config.MySQL:
arg = []string{mysqlFlagUser, cfg.User, mysqlFlagPassword, cfg.Password, cfg.DB}
user := fmt.Sprintf("%s%s", mysqlFlagUser, cfg.User)
password := fmt.Sprintf("%s%s", mysqlFlagPassword, cfg.Password)
arg = []string{user,password, cfg.DB}
}
return arg
}
Expand Down
10 changes: 6 additions & 4 deletions internal/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package internal

import (
"bytes"
"errors"
"fmt"
"github.com/sadihakan/dummy-dump/config"
"io/ioutil"
Expand Down Expand Up @@ -36,16 +37,17 @@ func (m MySQL) Check() error {
func (m MySQL) Export(dump config.Config) error {
filename := fmt.Sprintf("%d.backup", time.Now().UTC().UnixNano())
cmd := CreateExportCommand(dump)
var outb bytes.Buffer
cmd.Stderr = os.Stderr
fmt.Println(cmd)
var outb, errBuf bytes.Buffer
cmd.Stderr = &errBuf
cmd.Stdin = os.Stdin
cmd.Stdout = &outb
err := cmd.Run()
if err != nil {
return err
return errors.New(errBuf.String())
}

err = ioutil.WriteFile(filename,outb.Bytes(),0644)
err = ioutil.WriteFile(filename, outb.Bytes(), 0644)
return err
}

Expand Down

0 comments on commit 579e766

Please sign in to comment.