fix: 解决远程数据库备份失败的问题 (#5221)

Refs #5166
pull/5222/head
ssongliu 2024-05-30 15:25:15 +08:00 committed by GitHub
parent c133f39b5e
commit d5abd7ec3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 12 deletions

View File

@ -874,7 +874,6 @@ func calculateNetwork(network map[string]types.NetworkStats) (float64, float64)
func checkImageExist(client *client.Client, imageItem string) bool {
images, err := client.ImageList(context.Background(), image.ListOptions{})
if err != nil {
fmt.Println(err)
return false
}

View File

@ -4,7 +4,6 @@ import (
"bufio"
"context"
"encoding/json"
"fmt"
"os"
"path"
"strings"
@ -104,7 +103,6 @@ func (u *DockerService) LoadDockerConf() *dto.DaemonJsonConf {
return &data
}
if err := json.Unmarshal(arr, &conf); err != nil {
fmt.Println(err)
return &data
}
if _, ok := daemonMap["iptables"]; !ok {

View File

@ -1,7 +1,6 @@
package service
import (
"fmt"
"os"
"github.com/1Panel-dev/1Panel/backend/app/dto"
@ -128,7 +127,9 @@ func (f *FtpService) Sync() error {
func (f *FtpService) Create(req dto.FtpCreate) (uint, error) {
if _, err := os.Stat(req.Path); err != nil {
if os.IsNotExist(err) {
fmt.Println(os.MkdirAll(req.Path, os.ModePerm))
if err := os.MkdirAll(req.Path, os.ModePerm); err != nil {
return 0, err
}
} else {
return 0, err
}

View File

@ -252,7 +252,7 @@ func (r *Remote) Backup(info BackupInfo) error {
backupCmd := fmt.Sprintf("docker run --rm --net=host -i %s /bin/bash -c '%s -h %s -P %d -u%s -p%s %s --default-character-set=%s %s'",
image, dumpCmd, r.Address, r.Port, r.User, r.Password, sslSkip(info.Version, r.Type), info.Format, info.Name)
global.LOG.Debug(backupCmd)
global.LOG.Debug(strings.ReplaceAll(backupCmd, r.Password, "******"))
cmd := exec.Command("bash", "-c", backupCmd)
var stderr bytes.Buffer
cmd.Stderr = &stderr
@ -281,7 +281,7 @@ func (r *Remote) Recover(info RecoverInfo) error {
recoverCmd := fmt.Sprintf("docker run --rm --net=host -i %s /bin/bash -c '%s -h %s -P %d -u%s -p%s %s --default-character-set=%s %s'",
image, r.Type, r.Address, r.Port, r.User, r.Password, sslSkip(info.Version, r.Type), info.Format, info.Name)
global.LOG.Debug(recoverCmd)
global.LOG.Debug(strings.ReplaceAll(recoverCmd, r.Password, "******"))
cmd := exec.Command("bash", "-c", recoverCmd)
if strings.HasSuffix(info.SourceFile, ".gz") {
@ -419,11 +419,11 @@ func (r *Remote) ExecSQLForHosts(timeout uint) ([]string, error) {
func loadImage(dbType, version string) (string, error) {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
fmt.Println(err)
return "", err
}
images, err := cli.ImageList(context.Background(), image.ListOptions{})
if err != nil {
fmt.Println(err)
return "", err
}
for _, image := range images {
@ -445,10 +445,20 @@ func loadImage(dbType, version string) (string, error) {
}
}
}
if dbType == "mariadb" || version == "8.x" {
return "mysql:8.2.0", nil
return loadVersion(dbType, version), nil
}
func loadVersion(dbType string, version string) string {
if dbType == "mariadb" {
return "mariadb:11.3.2 "
}
return "mysql:" + version, nil
if strings.HasPrefix(version, "5.6") {
return "mysql:5.6.51"
}
if strings.HasPrefix(version, "5.7") {
return "mysql:5.7.44"
}
return "mysql:8.2.0"
}
func sslSkip(version, dbType string) string {