fix: 备份恢复失败问题解决

pull/189/head
ssongliu 2023-03-07 15:51:48 +08:00 committed by ssongliu
parent 8f5028463a
commit f57db29317
9 changed files with 21 additions and 30 deletions

View File

@ -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) 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 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 err
} }
return nil return nil

View File

@ -72,8 +72,7 @@ func (u *BackupService) MysqlRecoverByUpload(req dto.CommonRecover) error {
} }
file := req.File file := req.File
fileName := path.Base(req.File) fileName := path.Base(req.File)
if !strings.HasSuffix(fileName, ".sql") && !strings.HasSuffix(fileName, ".gz") { if strings.HasSuffix(fileName, ".tar.gz") {
fileOp := files.NewFileOp()
fileNameItem := time.Now().Format("20060102150405") fileNameItem := time.Now().Format("20060102150405")
dstDir := fmt.Sprintf("%s/%s", path.Dir(req.File), fileNameItem) dstDir := fmt.Sprintf("%s/%s", path.Dir(req.File), fileNameItem)
if _, err := os.Stat(dstDir); err != nil && os.IsNotExist(err) { 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) return fmt.Errorf("mkdir %s failed, err: %v", dstDir, err)
} }
} }
var compressType files.CompressType if err := handleUnTar(req.File, dstDir); err != nil {
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 {
_ = os.RemoveAll(dstDir) _ = os.RemoveAll(dstDir)
return err return err
} }

View File

@ -152,6 +152,7 @@ func handleWebsiteRecover(website *model.Website, recoverFile string, isRollback
if err := websiteRepo.SaveWithoutCtx(&oldWebsite); err != nil { if err := websiteRepo.SaveWithoutCtx(&oldWebsite); err != nil {
return err return err
} }
isOk = true
return nil 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") 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) 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 return err
} }
global.LOG.Info("put web.tar.gz into tmp dir successful, now start to tar tmp dir") 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 return err
} }

View File

@ -190,7 +190,7 @@ func (u *SnapshotService) SnapshotCreate(req dto.SnapshotCreate) error {
return 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()) updateSnapshotStatus(snap.ID, constant.StatusFailed, err.Error())
return return
} }
@ -264,7 +264,7 @@ func (u *SnapshotService) SnapshotRecover(req dto.SnapshotRecover) error {
} }
fileOp := files.NewFileOp() fileOp := files.NewFileOp()
if !isReTry || snap.InterruptStep == "Decompress" || (isReTry && req.ReDownload) { 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 { if req.ReDownload {
updateRecoverStatus(snap.ID, snap.InterruptStep, constant.StatusFailed, fmt.Sprintf("decompress file failed, err: %v", err)) updateRecoverStatus(snap.ID, snap.InterruptStep, constant.StatusFailed, fmt.Sprintf("decompress file failed, err: %v", err))
return return

View File

@ -28,7 +28,11 @@
<el-table-column type="selection" fix /> <el-table-column type="selection" fix />
<el-table-column :label="$t('commons.table.name')" prop="fileName" show-overflow-tooltip /> <el-table-column :label="$t('commons.table.name')" prop="fileName" show-overflow-tooltip />
<el-table-column :label="$t('database.source')" prop="backupType"> <el-table-column :label="$t('database.source')" prop="backupType">
<template #default="{ row }">{{ $t('setting.' + row.source) }}</template> <template #default="{ row }">
<span v-if="row.source">
{{ $t('setting.' + row.source) }}
</span>
</template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
prop="createdAt" prop="createdAt"

View File

@ -169,14 +169,7 @@ const beforeAvatarUpload = (rawFile) => {
} }
return true; return true;
} }
if ( if (!rawFile.name.endsWith('.sql') && !rawFile.name.endsWith('.tar.gz') && !rawFile.name.endsWith('.sql.gz')) {
!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')
) {
MsgError(i18n.global.t('commons.msg.unSupportType')); MsgError(i18n.global.t('commons.msg.unSupportType'));
return false; return false;
} }

View File

@ -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!', 'This port is the exposed port of the container. You need to save the modification separately and restart the container!',
selectFile: 'Select file', selectFile: 'Select file',
supportUpType: 'Only sql, zip, sql.gz, and (tar.gz gz tgz) files within 10 MB are supported', supportUpType: 'Only sql, sql.gz, and tar.gz files within 10 MB are supported',
zipFormat: zipFormat: 'tar.gz compressed package structure: test.tar.gz compressed package must contain test.sql',
'zip, tar.gz compressed package structure: test.zip or test.tar.gz compressed package must contain test.sql',
currentStatus: 'Current state', currentStatus: 'Current state',
runTime: 'Startup time', runTime: 'Startup time',

View File

@ -299,8 +299,8 @@ export default {
selectFile: '', selectFile: '',
dropHelper: '', dropHelper: '',
clickHelper: '', clickHelper: '',
supportUpType: ' 10M sqlzipsql.gz(tar.gz gz tgz) ', supportUpType: ' 10M sqlsql.gztar.gz ',
zipFormat: 'ziptar.gz test.zip test.tar.gz test.sql', zipFormat: 'tar.gz test.tar.gz test.sql',
currentStatus: '', currentStatus: '',
baseParam: '', baseParam: '',

View File

@ -104,6 +104,7 @@
plain plain
round round
size="small" size="small"
:disabled="installed.status !== 'Running'"
@click="openUploads(installed.app.key, installed.name)" @click="openUploads(installed.app.key, installed.name)"
v-if="mode === 'installed'" v-if="mode === 'installed'"
> >
@ -115,6 +116,7 @@
plain plain
round round
size="small" size="small"
:disabled="installed.status !== 'Running'"
@click="openBackups(installed.app.key, installed.name)" @click="openBackups(installed.app.key, installed.name)"
v-if="mode === 'installed'" v-if="mode === 'installed'"
> >