From f57db2931758e9c94b4e393d4d61a5aafcaeec4f Mon Sep 17 00:00:00 2001 From: ssongliu Date: Tue, 7 Mar 2023 15:51:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=87=E4=BB=BD=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/backup_app.go | 4 ++-- backend/app/service/backup_database.go | 12 ++---------- backend/app/service/backup_website.go | 5 +++-- backend/app/service/snapshot.go | 4 ++-- frontend/src/components/backup/index.vue | 6 +++++- frontend/src/components/upload/index.vue | 9 +-------- frontend/src/lang/modules/en.ts | 5 ++--- frontend/src/lang/modules/zh.ts | 4 ++-- frontend/src/views/app-store/installed/index.vue | 2 ++ 9 files changed, 21 insertions(+), 30 deletions(-) diff --git a/backend/app/service/backup_app.go b/backend/app/service/backup_app.go index 11195d4e7..751350f36 100644 --- a/backend/app/service/backup_app.go +++ b/backend/app/service/backup_app.go @@ -98,7 +98,7 @@ func handleAppBackup(install *model.AppInstall, backupDir, fileName string) erro } appPath := fmt.Sprintf("%s/%s/%s", constant.AppInstallDir, install.App.Key, install.Name) - if err := fileOp.Compress([]string{appPath}, tmpDir, "app.tar.gz", files.TarGz); err != nil { + if err := handleTar(appPath, tmpDir, "app.tar.gz", ""); err != nil { return err } @@ -117,7 +117,7 @@ func handleAppBackup(install *model.AppInstall, backupDir, fileName string) erro } } - if err := fileOp.Compress([]string{tmpDir}, backupDir, fileName, files.TarGz); err != nil { + if err := handleTar(tmpDir, backupDir, fileName, ""); err != nil { return err } return nil diff --git a/backend/app/service/backup_database.go b/backend/app/service/backup_database.go index 189e856e7..7462645ff 100644 --- a/backend/app/service/backup_database.go +++ b/backend/app/service/backup_database.go @@ -72,8 +72,7 @@ func (u *BackupService) MysqlRecoverByUpload(req dto.CommonRecover) error { } file := req.File fileName := path.Base(req.File) - if !strings.HasSuffix(fileName, ".sql") && !strings.HasSuffix(fileName, ".gz") { - fileOp := files.NewFileOp() + if strings.HasSuffix(fileName, ".tar.gz") { fileNameItem := time.Now().Format("20060102150405") dstDir := fmt.Sprintf("%s/%s", path.Dir(req.File), fileNameItem) if _, err := os.Stat(dstDir); err != nil && os.IsNotExist(err) { @@ -81,14 +80,7 @@ func (u *BackupService) MysqlRecoverByUpload(req dto.CommonRecover) error { return fmt.Errorf("mkdir %s failed, err: %v", dstDir, err) } } - var compressType files.CompressType - switch { - case strings.HasSuffix(fileName, ".tar.gz"), strings.HasSuffix(fileName, ".tgz"): - compressType = files.TarGz - case strings.HasSuffix(fileName, ".zip"): - compressType = files.Zip - } - if err := fileOp.Decompress(req.File, dstDir, compressType); err != nil { + if err := handleUnTar(req.File, dstDir); err != nil { _ = os.RemoveAll(dstDir) return err } diff --git a/backend/app/service/backup_website.go b/backend/app/service/backup_website.go index 24eeafedd..ae975e0ad 100644 --- a/backend/app/service/backup_website.go +++ b/backend/app/service/backup_website.go @@ -152,6 +152,7 @@ func handleWebsiteRecover(website *model.Website, recoverFile string, isRollback if err := websiteRepo.SaveWithoutCtx(&oldWebsite); err != nil { return err } + isOk = true return nil } @@ -194,11 +195,11 @@ func handleWebsiteBackup(website *model.Website, backupDir, fileName string) err global.LOG.Info("put app.tar.gz into tmp dir successful") } websiteDir := fmt.Sprintf("%s/openresty/%s/www/sites/%s", constant.AppInstallDir, nginxInfo.Name, website.Alias) - if err := fileOp.Compress([]string{websiteDir}, tmpDir, fmt.Sprintf("%s.web.tar.gz", website.Alias), files.TarGz); err != nil { + if err := handleTar(websiteDir, tmpDir, fmt.Sprintf("%s.web.tar.gz", website.Alias), ""); err != nil { return err } global.LOG.Info("put web.tar.gz into tmp dir successful, now start to tar tmp dir") - if err := fileOp.Compress([]string{tmpDir}, backupDir, fileName, files.TarGz); err != nil { + if err := handleTar(tmpDir, backupDir, fileName, ""); err != nil { return err } diff --git a/backend/app/service/snapshot.go b/backend/app/service/snapshot.go index 586ea15cb..17557c7c2 100644 --- a/backend/app/service/snapshot.go +++ b/backend/app/service/snapshot.go @@ -190,7 +190,7 @@ func (u *SnapshotService) SnapshotCreate(req dto.SnapshotCreate) error { return } - if err := fileOp.Compress([]string{rootDir}, fmt.Sprintf("%s/system", localDir), fmt.Sprintf("1panel_%s_%s.tar.gz", versionItem.Value, timeNow), files.TarGz); err != nil { + if err := handleTar(rootDir, fmt.Sprintf("%s/system", localDir), fmt.Sprintf("1panel_%s_%s.tar.gz", versionItem.Value, timeNow), ""); err != nil { updateSnapshotStatus(snap.ID, constant.StatusFailed, err.Error()) return } @@ -264,7 +264,7 @@ func (u *SnapshotService) SnapshotRecover(req dto.SnapshotRecover) error { } fileOp := files.NewFileOp() if !isReTry || snap.InterruptStep == "Decompress" || (isReTry && req.ReDownload) { - if err := fileOp.Decompress(fmt.Sprintf("%s/%s.tar.gz", baseDir, snap.Name), baseDir, files.TarGz); err != nil { + if err := handleUnTar(fmt.Sprintf("%s/%s.tar.gz", baseDir, snap.Name), baseDir); err != nil { if req.ReDownload { updateRecoverStatus(snap.ID, snap.InterruptStep, constant.StatusFailed, fmt.Sprintf("decompress file failed, err: %v", err)) return diff --git a/frontend/src/components/backup/index.vue b/frontend/src/components/backup/index.vue index d8fd7530b..53dee6852 100644 --- a/frontend/src/components/backup/index.vue +++ b/frontend/src/components/backup/index.vue @@ -28,7 +28,11 @@ - + { } return true; } - if ( - !rawFile.name.endsWith('.sql') && - !rawFile.name.endsWith('.zip') && - !rawFile.name.endsWith('.tar.gz') && - !rawFile.name.endsWith('.sql.gz') && - !rawFile.name.endsWith('.zip') && - !rawFile.name.endsWith('.tgz') - ) { + if (!rawFile.name.endsWith('.sql') && !rawFile.name.endsWith('.tar.gz') && !rawFile.name.endsWith('.sql.gz')) { MsgError(i18n.global.t('commons.msg.unSupportType')); return false; } diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 61b2c2136..e2ef5ca88 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -291,9 +291,8 @@ export default { 'This port is the exposed port of the container. You need to save the modification separately and restart the container!', selectFile: 'Select file', - supportUpType: 'Only sql, zip, sql.gz, and (tar.gz gz tgz) files within 10 MB are supported', - zipFormat: - 'zip, tar.gz compressed package structure: test.zip or test.tar.gz compressed package must contain test.sql', + supportUpType: 'Only sql, sql.gz, and tar.gz files within 10 MB are supported', + zipFormat: 'tar.gz compressed package structure: test.tar.gz compressed package must contain test.sql', currentStatus: 'Current state', runTime: 'Startup time', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index f4c3b92ed..ee4998889 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -299,8 +299,8 @@ export default { selectFile: '选择文件', dropHelper: '将上传文件拖拽到此处,或者', clickHelper: '点击上传', - supportUpType: '仅支持 10M 以内 sql、zip、sql.gz、(tar.gz gz tgz) 文件', - zipFormat: 'zip、tar.gz 压缩包结构:test.zip 或 test.tar.gz 压缩包内,必需包含 test.sql', + supportUpType: '仅支持 10M 以内 sql、sql.gz、tar.gz 文件', + zipFormat: 'tar.gz 压缩包结构:test.tar.gz 压缩包内,必需包含 test.sql', currentStatus: '当前状态', baseParam: '基础参数', diff --git a/frontend/src/views/app-store/installed/index.vue b/frontend/src/views/app-store/installed/index.vue index ffadbc927..ae96eb6f2 100644 --- a/frontend/src/views/app-store/installed/index.vue +++ b/frontend/src/views/app-store/installed/index.vue @@ -104,6 +104,7 @@ plain round size="small" + :disabled="installed.status !== 'Running'" @click="openUploads(installed.app.key, installed.name)" v-if="mode === 'installed'" > @@ -115,6 +116,7 @@ plain round size="small" + :disabled="installed.status !== 'Running'" @click="openBackups(installed.app.key, installed.name)" v-if="mode === 'installed'" >