mirror of https://github.com/1Panel-dev/1Panel
Fix: Postgres fails to connect when using special characters (#7262)
* Update client.go * Update remote.go * Update client.gopull/7266/head
parent
5b92b75090
commit
5be325405d
|
@ -32,7 +32,11 @@ func NewPostgresqlClient(conn client.DBInfo) (PostgresqlClient, error) {
|
||||||
return client.NewLocal(connArgs, conn.Address, conn.Username, conn.Password, conn.Database), nil
|
return client.NewLocal(connArgs, conn.Address, conn.Username, conn.Password, conn.Database), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
connArgs := fmt.Sprintf("postgres://%s:%s@%s:%d/?sslmode=disable", conn.Username, conn.Password, conn.Address, conn.Port)
|
// Escape username and password to handle special characters
|
||||||
|
escapedUsername := url.QueryEscape(username)
|
||||||
|
escapedPassword := url.QueryEscape(password)
|
||||||
|
|
||||||
|
connArgs := fmt.Sprintf("postgres://%s:%s@%s:%d/?sslmode=disable", escapedUsername, escapedPassword, conn.Address, conn.Port)
|
||||||
db, err := sql.Open("pgx", connArgs)
|
db, err := sql.Open("pgx", connArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -134,7 +134,7 @@ func (r *Remote) Backup(info BackupInfo) error {
|
||||||
}
|
}
|
||||||
fileNameItem := info.TargetDir + "/" + strings.TrimSuffix(info.FileName, ".gz")
|
fileNameItem := info.TargetDir + "/" + strings.TrimSuffix(info.FileName, ".gz")
|
||||||
backupCommand := exec.Command("bash", "-c",
|
backupCommand := exec.Command("bash", "-c",
|
||||||
fmt.Sprintf("docker run --rm --net=host -i %s /bin/bash -c 'PGPASSWORD=%s pg_dump -h %s -p %d --no-owner -Fc -U %s %s' > %s",
|
fmt.Sprintf("docker run --rm --net=host -i %s -e PGPASSWORD='%s' /bin/bash -c 'pg_dump -h %s -p %d --no-owner -Fc -U %s %s' > %s",
|
||||||
imageTag, r.Password, r.Address, r.Port, r.User, info.Name, fileNameItem))
|
imageTag, r.Password, r.Address, r.Port, r.User, info.Name, fileNameItem))
|
||||||
_ = backupCommand.Run()
|
_ = backupCommand.Run()
|
||||||
b := make([]byte, 5)
|
b := make([]byte, 5)
|
||||||
|
@ -177,7 +177,7 @@ func (r *Remote) Recover(info RecoverInfo) error {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
recoverCommand := exec.Command("bash", "-c",
|
recoverCommand := exec.Command("bash", "-c",
|
||||||
fmt.Sprintf("docker run --rm --net=host -i %s /bin/bash -c 'PGPASSWORD=%s pg_restore -h %s -p %d --verbose --clean --no-privileges --no-owner -Fc -U %s -d %s --role=%s' < %s",
|
fmt.Sprintf("docker run --rm --net=host -i %s -e PGPASSWORD='%s' /bin/bash -c 'pg_restore -h %s -p %d --verbose --clean --no-privileges --no-owner -Fc -U %s -d %s --role=%s' < %s",
|
||||||
imageTag, r.Password, r.Address, r.Port, r.User, info.Name, info.Username, fileName))
|
imageTag, r.Password, r.Address, r.Port, r.User, info.Name, info.Username, fileName))
|
||||||
pipe, _ := recoverCommand.StdoutPipe()
|
pipe, _ := recoverCommand.StdoutPipe()
|
||||||
stderrPipe, _ := recoverCommand.StderrPipe()
|
stderrPipe, _ := recoverCommand.StderrPipe()
|
||||||
|
|
Loading…
Reference in New Issue