Skip to content

Commit

Permalink
fix(database-pg): Fixed the issue of PostgreSQL not being able to bac…
Browse files Browse the repository at this point in the history
…k up. (1Panel-dev#7324)
  • Loading branch information
ssongliu authored Dec 11, 2024
1 parent cbad4dd commit aaf1d86
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions backend/utils/postgresql/client/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"os"
"os/exec"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -134,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 -e PGPASSWORD='%s' /bin/bash -c '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)
Expand Down Expand Up @@ -177,7 +178,7 @@ func (r *Remote) Recover(info RecoverInfo) error {
}()
}
recoverCommand := exec.Command("bash", "-c",
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",
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()
Expand Down Expand Up @@ -296,7 +297,11 @@ func loadImageTag() (string, error) {
return itemTag, nil
}

itemTag = "postgres:16.1-alpine"
sort.Strings(versions)
if len(versions) != 0 {
itemTag = versions[len(versions)-1]
}

ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
defer cancel()
if _, err := client.ImagePull(ctx, itemTag, image.PullOptions{}); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,7 @@ const message = {
gotoInstalled: 'Go to install',
search: 'Search',
limitHelper: 'The application has already been installed.',
deleteHelper: `"{0}" has been associated with the following resource(s) and can't be deleted`,
deleteHelper: `"{0}" has been associated with the following resource(s). Please check and try again!`,
checkTitle: 'Hint',
website: 'website',
database: 'database',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lang/modules/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ const message = {
gotoInstalled: '去安裝',
search: '搜',
limitHelper: '該應用已安裝不支持重復安裝',
deleteHelper: '{0}已經關聯以下資源無法刪除',
deleteHelper: '{0}已經關聯以下資源請檢查後重試',
checkTitle: '提',
website: '網',
database: '數據庫',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ const message = {
gotoInstalled: '去安装',
search: '搜',
limitHelper: '该应用已安装不支持重复安装',
deleteHelper: '{0}已经关联以下资源无法删除',
deleteHelper: '{0}已经关联以下资源请检查后重试',
checkTitle: '提',
website: '网',
database: '数据库',
Expand Down

0 comments on commit aaf1d86

Please sign in to comment.