mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/1Panel-dev/1Panel.git
synced 2026-09-20 08:03:55 +08:00
feat: merge code from dev (#7439)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/agent/buserr"
|
||||
@@ -31,8 +32,9 @@ func NewPostgresqlClient(conn client.DBInfo) (PostgresqlClient, error) {
|
||||
connArgs := []string{"exec", conn.Address, "psql", "-t", "-U", conn.Username, "-c"}
|
||||
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)
|
||||
escapedUsername := url.QueryEscape(conn.Username)
|
||||
escapedPassword := url.QueryEscape(conn.Password)
|
||||
connArgs := fmt.Sprintf("postgres://%s:%s@%s:%d/?sslmode=disable", escapedUsername, escapedPassword, conn.Address, conn.Port)
|
||||
db, err := sql.Open("pgx", connArgs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -135,7 +135,7 @@ func (r *Remote) Backup(info BackupInfo) error {
|
||||
}
|
||||
fileNameItem := info.TargetDir + "/" + strings.TrimSuffix(info.FileName, ".gz")
|
||||
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 /bin/bash -c 'PGPASSWORD=\"%s\" 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))
|
||||
_ = backupCommand.Run()
|
||||
b := make([]byte, 5)
|
||||
@@ -178,7 +178,7 @@ func (r *Remote) Recover(info RecoverInfo) error {
|
||||
}()
|
||||
}
|
||||
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 /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",
|
||||
imageTag, r.Password, r.Address, r.Port, r.User, info.Name, info.Username, fileName))
|
||||
pipe, _ := recoverCommand.StdoutPipe()
|
||||
stderrPipe, _ := recoverCommand.StderrPipe()
|
||||
|
||||
Reference in New Issue
Block a user