Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
sadihakan committed Apr 3, 2021
2 parents b082fbd + 3b0f984 commit 8b81c24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type Config struct {
DB string
BinaryPath string
BackupName string
Host string
Port string
}

func (c *Config) checkAll() error {
Expand Down
17 changes: 12 additions & 5 deletions internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
pgFlagCreateDatabase = "-C"
pgFlagCreate = "--create"
pgFlagFormat = "--format=c"
pgVersion = "--version"
pgVersion = "--version"
mysqlVersion = "--version"

//pgRestore="pg_restore"
Expand All @@ -27,6 +27,9 @@ const (
mysqlFlagExecute = "-e"
//mysqlImport="mysql"
//mysqlDump="mysqldump"

host = "--host="
port = "--port="
)

// CreateCheckBinaryCommand ...
Expand Down Expand Up @@ -77,14 +80,16 @@ func getVersionCommandArg(sourceType config.SourceType) (arg []string) {

// getImportCommandArg ...
func getImportCommandArg(cfg config.Config) (arg []string) {
host := fmt.Sprintf("%s%s", host, cfg.Host)
port := fmt.Sprintf("%s%s", port, cfg.Port)
switch cfg.Source {
case config.PostgreSQL:
dns := fmt.Sprintf(`user=%s password=%s dbname=%s`, cfg.User, cfg.Password, cfg.DB)
arg = []string{dns, pgFlagCreateDatabase, pgFlagCreate, cfg.Path}
arg = []string{dns, host, port, pgFlagCreateDatabase, pgFlagCreate, cfg.Path}
case config.MySQL:
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}
arg = []string{user, password, host, port, cfg.DB, mysqlFlagExecute, "source " + cfg.Path}

}
return arg
Expand All @@ -93,14 +98,16 @@ func getImportCommandArg(cfg config.Config) (arg []string) {
// getExportCommandArg ...
func getExportCommandArg(cfg config.Config) (arg []string) {
filename := fmt.Sprintf("%s", cfg.BackupName)
host := fmt.Sprintf("%s%s", host, cfg.Host)
port := fmt.Sprintf("%s%s", port, cfg.Port)
switch cfg.Source {
case config.PostgreSQL:
dns := fmt.Sprintf(`user=%s password=%s dbname=%s`, cfg.User, cfg.Password, cfg.DB)
arg = []string{dns, pgFlagFileName, filename, pgFlagCreate, pgFlagFormat}
arg = []string{dns, host, port, pgFlagCreate, pgFlagFormat, pgFlagFileName, filename}
case config.MySQL:
user := fmt.Sprintf("%s%s", mysqlFlagUser, cfg.User)
password := fmt.Sprintf("%s\"%s\"", mysqlFlagPassword, cfg.Password)
arg = []string{user,password, cfg.DB}
arg = []string{user, password, host, port, cfg.DB}
}
return arg
}
Expand Down

0 comments on commit 8b81c24

Please sign in to comment.