1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

fix: 解决不带密码压缩文件失败的问题 (#5296)

Co-authored-by: ssonglius11 <ssonglius11@163.com>
This commit is contained in:
ssongliu 2024-06-05 14:31:26 +08:00 committed by GitHub
parent 33c4b8bba9
commit 428743d600
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 38 additions and 10 deletions

View File

@ -165,7 +165,11 @@ func handleTar(sourceDir, targetDir, name, exclusionRules string, secret string)
} else { } else {
commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s %s", targetDir+"/"+name, excludeRules, path) commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s %s", targetDir+"/"+name, excludeRules, path)
} }
global.LOG.Debug(strings.ReplaceAll(commands, secret, "******")) if len(secret) != 0 {
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
} else {
global.LOG.Debug(commands)
}
stdout, err := cmd.ExecWithTimeOut(commands, 24*time.Hour) stdout, err := cmd.ExecWithTimeOut(commands, 24*time.Hour)
if err != nil { if err != nil {
if len(stdout) != 0 { if len(stdout) != 0 {
@ -189,7 +193,11 @@ func handleUnTar(sourceFile, targetDir string, secret string) error {
} else { } else {
commands = fmt.Sprintf("tar -zxvf %s %s", sourceFile+" -C ", targetDir+" > /dev/null 2>&1") commands = fmt.Sprintf("tar -zxvf %s %s", sourceFile+" -C ", targetDir+" > /dev/null 2>&1")
} }
global.LOG.Debug(strings.ReplaceAll(commands, secret, "******")) if len(secret) != 0 {
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
} else {
global.LOG.Debug(commands)
}
stdout, err := cmd.ExecWithTimeOut(commands, 24*time.Hour) stdout, err := cmd.ExecWithTimeOut(commands, 24*time.Hour)
if err != nil { if err != nil {
global.LOG.Errorf("do handle untar failed, stdout: %s, err: %v", stdout, err) global.LOG.Errorf("do handle untar failed, stdout: %s, err: %v", stdout, err)

View File

@ -396,7 +396,11 @@ func (u *SnapshotService) handleUnTar(sourceDir, targetDir string, secret string
} else { } else {
commands = fmt.Sprintf("tar -zxvf %s %s", sourceDir+" -C ", targetDir+" > /dev/null 2>&1") commands = fmt.Sprintf("tar -zxvf %s %s", sourceDir+" -C ", targetDir+" > /dev/null 2>&1")
} }
global.LOG.Debug(strings.ReplaceAll(commands, secret, "******")) if len(secret) != 0 {
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
} else {
global.LOG.Debug(commands)
}
stdout, err := cmd.ExecWithTimeOut(commands, 30*time.Minute) stdout, err := cmd.ExecWithTimeOut(commands, 30*time.Minute)
if err != nil { if err != nil {
if len(stdout) != 0 { if len(stdout) != 0 {

View File

@ -261,7 +261,11 @@ func handleSnapTar(sourceDir, targetDir, name, exclusionRules string, secret str
} else { } else {
commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s -C %s .", targetDir+"/"+name, exStr, sourceDir) commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s -C %s .", targetDir+"/"+name, exStr, sourceDir)
} }
global.LOG.Debug(strings.ReplaceAll(commands, secret, "******")) if len(secret) != 0 {
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
} else {
global.LOG.Debug(commands)
}
stdout, err := cmd.ExecWithTimeOut(commands, 30*time.Minute) stdout, err := cmd.ExecWithTimeOut(commands, 30*time.Minute)
if err != nil { if err != nil {
if len(stdout) != 0 { if len(stdout) != 0 {

View File

@ -39,7 +39,7 @@ func (u *SnapshotService) HandleSnapshotRecover(snap model.Snapshot, isRecover b
req.IsNew = true req.IsNew = true
} }
if req.IsNew || snap.InterruptStep == "Decompress" { if req.IsNew || snap.InterruptStep == "Decompress" {
if err := u.handleUnTar(fmt.Sprintf("%s/%s.tar.gz", baseDir, snap.Name), baseDir, req.Secret); err != nil { if err := handleUnTar(fmt.Sprintf("%s/%s.tar.gz", baseDir, snap.Name), baseDir, req.Secret); err != nil {
updateRecoverStatus(snap.ID, isRecover, "Decompress", constant.StatusFailed, fmt.Sprintf("decompress file failed, err: %v", err)) updateRecoverStatus(snap.ID, isRecover, "Decompress", constant.StatusFailed, fmt.Sprintf("decompress file failed, err: %v", err))
return return
} }
@ -55,6 +55,9 @@ func (u *SnapshotService) HandleSnapshotRecover(snap model.Snapshot, isRecover b
req.IsNew = true req.IsNew = true
} }
snapFileDir = fmt.Sprintf("%s/%s", baseDir, snap.Name) snapFileDir = fmt.Sprintf("%s/%s", baseDir, snap.Name)
if _, err := os.Stat(snapFileDir); err != nil {
snapFileDir = baseDir
}
} else { } else {
snapFileDir = fmt.Sprintf("%s/1panel_original/original_%s", global.CONF.System.BaseDir, snap.Name) snapFileDir = fmt.Sprintf("%s/1panel_original/original_%s", global.CONF.System.BaseDir, snap.Name)
if _, err := os.Stat(snapFileDir); err != nil { if _, err := os.Stat(snapFileDir); err != nil {

View File

@ -2,10 +2,11 @@ package files
import ( import (
"fmt" "fmt"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
) )
type TarGzArchiver struct { type TarGzArchiver struct {
@ -24,7 +25,11 @@ func (t TarGzArchiver) Extract(filePath, dstDir string, secret string) error {
} else { } else {
commands = fmt.Sprintf("tar -zxvf %s %s", filePath+" -C ", dstDir+" > /dev/null 2>&1") commands = fmt.Sprintf("tar -zxvf %s %s", filePath+" -C ", dstDir+" > /dev/null 2>&1")
} }
global.LOG.Debug(strings.ReplaceAll(commands, secret, "******")) if len(secret) != 0 {
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
} else {
global.LOG.Debug(commands)
}
if err = cmd.ExecCmd(commands); err != nil { if err = cmd.ExecCmd(commands); err != nil {
return err return err
} }
@ -48,9 +53,13 @@ func (t TarGzArchiver) Compress(sourcePaths []string, dstFile string, secret str
extraCmd := "| openssl enc -aes-256-cbc -salt -k " + secret + " -out" extraCmd := "| openssl enc -aes-256-cbc -salt -k " + secret + " -out"
commands = fmt.Sprintf("tar -zcf %s %s %s", path, extraCmd, dstFile) commands = fmt.Sprintf("tar -zcf %s %s %s", path, extraCmd, dstFile)
} else { } else {
commands = fmt.Sprintf("tar -zcf %s %s", dstFile, path) commands = fmt.Sprintf("tar -zcf %s -C %s %s", dstFile, aheadDir, itemDir)
}
if len(secret) != 0 {
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
} else {
global.LOG.Debug(commands)
} }
global.LOG.Debug(strings.ReplaceAll(commands, secret, "******"))
if err = cmd.ExecCmd(commands); err != nil { if err = cmd.ExecCmd(commands); err != nil {
return err return err
} }