mirror of https://github.com/1Panel-dev/1Panel
fix(database-pg): Fixed the issue of PostgreSQL not being able to back up. (#7324)
parent
cbad4dd172
commit
aaf1d86a55
|
@ -8,6 +8,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -134,7 +135,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 -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))
|
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 +178,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 -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))
|
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()
|
||||||
|
@ -296,7 +297,11 @@ func loadImageTag() (string, error) {
|
||||||
return itemTag, nil
|
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)
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
if _, err := client.ImagePull(ctx, itemTag, image.PullOptions{}); err != nil {
|
if _, err := client.ImagePull(ctx, itemTag, image.PullOptions{}); err != nil {
|
||||||
|
|
|
@ -1834,7 +1834,7 @@ const message = {
|
||||||
gotoInstalled: 'Go to install',
|
gotoInstalled: 'Go to install',
|
||||||
search: 'Search',
|
search: 'Search',
|
||||||
limitHelper: 'The application has already been installed.',
|
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',
|
checkTitle: 'Hint',
|
||||||
website: 'website',
|
website: 'website',
|
||||||
database: 'database',
|
database: 'database',
|
||||||
|
|
|
@ -1716,7 +1716,7 @@ const message = {
|
||||||
gotoInstalled: '去安裝',
|
gotoInstalled: '去安裝',
|
||||||
search: '搜索',
|
search: '搜索',
|
||||||
limitHelper: '該應用已安裝,不支持重復安裝',
|
limitHelper: '該應用已安裝,不支持重復安裝',
|
||||||
deleteHelper: '{0}已經關聯以下資源,無法刪除',
|
deleteHelper: '{0}已經關聯以下資源,請檢查後重試!',
|
||||||
checkTitle: '提示',
|
checkTitle: '提示',
|
||||||
website: '網站',
|
website: '網站',
|
||||||
database: '數據庫',
|
database: '數據庫',
|
||||||
|
|
|
@ -1715,7 +1715,7 @@ const message = {
|
||||||
gotoInstalled: '去安装',
|
gotoInstalled: '去安装',
|
||||||
search: '搜索',
|
search: '搜索',
|
||||||
limitHelper: '该应用已安装,不支持重复安装',
|
limitHelper: '该应用已安装,不支持重复安装',
|
||||||
deleteHelper: '{0}已经关联以下资源,无法删除',
|
deleteHelper: '{0}已经关联以下资源,请检查后重试!',
|
||||||
checkTitle: '提示',
|
checkTitle: '提示',
|
||||||
website: '网站',
|
website: '网站',
|
||||||
database: '数据库',
|
database: '数据库',
|
||||||
|
|
Loading…
Reference in New Issue