mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
feat: 计划任务应用、网站备份增加排除规则 (#4810)
This commit is contained in:
parent
164a48c99f
commit
e8fb727676
@ -40,7 +40,7 @@ func (u *BackupService) AppBackup(req dto.CommonBackup) (*model.BackupRecord, er
|
|||||||
backupDir := path.Join(localDir, itemDir)
|
backupDir := path.Join(localDir, itemDir)
|
||||||
|
|
||||||
fileName := fmt.Sprintf("%s_%s.tar.gz", req.DetailName, timeNow+common.RandStrAndNum(5))
|
fileName := fmt.Sprintf("%s_%s.tar.gz", req.DetailName, timeNow+common.RandStrAndNum(5))
|
||||||
if err := handleAppBackup(&install, backupDir, fileName); err != nil {
|
if err := handleAppBackup(&install, backupDir, fileName, ""); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ func (u *BackupService) AppRecover(req dto.CommonRecover) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleAppBackup(install *model.AppInstall, backupDir, fileName string) error {
|
func handleAppBackup(install *model.AppInstall, backupDir, fileName string, excludes string) error {
|
||||||
fileOp := files.NewFileOp()
|
fileOp := files.NewFileOp()
|
||||||
tmpDir := fmt.Sprintf("%s/%s", backupDir, strings.ReplaceAll(fileName, ".tar.gz", ""))
|
tmpDir := fmt.Sprintf("%s/%s", backupDir, strings.ReplaceAll(fileName, ".tar.gz", ""))
|
||||||
if !fileOp.Stat(tmpDir) {
|
if !fileOp.Stat(tmpDir) {
|
||||||
@ -103,7 +103,7 @@ func handleAppBackup(install *model.AppInstall, backupDir, fileName string) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
appPath := install.GetPath()
|
appPath := install.GetPath()
|
||||||
if err := handleTar(appPath, tmpDir, "app.tar.gz", ""); err != nil {
|
if err := handleTar(appPath, tmpDir, "app.tar.gz", excludes); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ func handleAppRecover(install *model.AppInstall, recoverFile string, isRollback
|
|||||||
|
|
||||||
if !isRollback {
|
if !isRollback {
|
||||||
rollbackFile := path.Join(global.CONF.System.TmpDir, fmt.Sprintf("app/%s_%s.tar.gz", install.Name, time.Now().Format("20060102150405")))
|
rollbackFile := path.Join(global.CONF.System.TmpDir, fmt.Sprintf("app/%s_%s.tar.gz", install.Name, time.Now().Format("20060102150405")))
|
||||||
if err := handleAppBackup(install, path.Dir(rollbackFile), path.Base(rollbackFile)); err != nil {
|
if err := handleAppBackup(install, path.Dir(rollbackFile), path.Base(rollbackFile), ""); err != nil {
|
||||||
return fmt.Errorf("backup app %s for rollback before recover failed, err: %v", install.Name, err)
|
return fmt.Errorf("backup app %s for rollback before recover failed, err: %v", install.Name, err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -4,18 +4,19 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/model"
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/global"
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/app/model"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/global"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
||||||
)
|
)
|
||||||
|
|
||||||
func handleRuntimeBackup(runtime *model.Runtime, backupDir, fileName string) error {
|
func handleRuntimeBackup(runtime *model.Runtime, backupDir, fileName string, excludes string) error {
|
||||||
fileOp := files.NewFileOp()
|
fileOp := files.NewFileOp()
|
||||||
tmpDir := fmt.Sprintf("%s/%s", backupDir, strings.ReplaceAll(fileName, ".tar.gz", ""))
|
tmpDir := fmt.Sprintf("%s/%s", backupDir, strings.ReplaceAll(fileName, ".tar.gz", ""))
|
||||||
if !fileOp.Stat(tmpDir) {
|
if !fileOp.Stat(tmpDir) {
|
||||||
@ -34,7 +35,7 @@ func handleRuntimeBackup(runtime *model.Runtime, backupDir, fileName string) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
appPath := runtime.GetPath()
|
appPath := runtime.GetPath()
|
||||||
if err := handleTar(appPath, tmpDir, "runtime.tar.gz", ""); err != nil {
|
if err := handleTar(appPath, tmpDir, "runtime.tar.gz", excludes); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := handleTar(tmpDir, backupDir, fileName, ""); err != nil {
|
if err := handleTar(tmpDir, backupDir, fileName, ""); err != nil {
|
||||||
@ -72,7 +73,7 @@ func handleRuntimeRecover(runtime *model.Runtime, recoverFile string, isRollback
|
|||||||
|
|
||||||
if !isRollback {
|
if !isRollback {
|
||||||
rollbackFile := path.Join(global.CONF.System.TmpDir, fmt.Sprintf("runtime/%s_%s.tar.gz", runtime.Name, time.Now().Format("20060102150405")))
|
rollbackFile := path.Join(global.CONF.System.TmpDir, fmt.Sprintf("runtime/%s_%s.tar.gz", runtime.Name, time.Now().Format("20060102150405")))
|
||||||
if err := handleRuntimeBackup(runtime, path.Dir(rollbackFile), path.Base(rollbackFile)); err != nil {
|
if err := handleRuntimeBackup(runtime, path.Dir(rollbackFile), path.Base(rollbackFile), ""); err != nil {
|
||||||
return fmt.Errorf("backup runtime %s for rollback before recover failed, err: %v", runtime.Name, err)
|
return fmt.Errorf("backup runtime %s for rollback before recover failed, err: %v", runtime.Name, err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -35,7 +35,7 @@ func (u *BackupService) WebsiteBackup(req dto.CommonBackup) error {
|
|||||||
itemDir := fmt.Sprintf("website/%s", req.Name)
|
itemDir := fmt.Sprintf("website/%s", req.Name)
|
||||||
backupDir := path.Join(localDir, itemDir)
|
backupDir := path.Join(localDir, itemDir)
|
||||||
fileName := fmt.Sprintf("%s_%s.tar.gz", website.PrimaryDomain, timeNow+common.RandStrAndNum(5))
|
fileName := fmt.Sprintf("%s_%s.tar.gz", website.PrimaryDomain, timeNow+common.RandStrAndNum(5))
|
||||||
if err := handleWebsiteBackup(&website, backupDir, fileName); err != nil {
|
if err := handleWebsiteBackup(&website, backupDir, fileName, ""); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ func handleWebsiteRecover(website *model.Website, recoverFile string, isRollback
|
|||||||
isOk := false
|
isOk := false
|
||||||
if !isRollback {
|
if !isRollback {
|
||||||
rollbackFile := path.Join(global.CONF.System.TmpDir, fmt.Sprintf("website/%s_%s.tar.gz", website.Alias, time.Now().Format("20060102150405")))
|
rollbackFile := path.Join(global.CONF.System.TmpDir, fmt.Sprintf("website/%s_%s.tar.gz", website.Alias, time.Now().Format("20060102150405")))
|
||||||
if err := handleWebsiteBackup(website, path.Dir(rollbackFile), path.Base(rollbackFile)); err != nil {
|
if err := handleWebsiteBackup(website, path.Dir(rollbackFile), path.Base(rollbackFile), ""); err != nil {
|
||||||
return fmt.Errorf("backup website %s for rollback before recover failed, err: %v", website.Alias, err)
|
return fmt.Errorf("backup website %s for rollback before recover failed, err: %v", website.Alias, err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -182,7 +182,7 @@ func handleWebsiteRecover(website *model.Website, recoverFile string, isRollback
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleWebsiteBackup(website *model.Website, backupDir, fileName string) error {
|
func handleWebsiteBackup(website *model.Website, backupDir, fileName string, excludes string) error {
|
||||||
fileOp := files.NewFileOp()
|
fileOp := files.NewFileOp()
|
||||||
tmpDir := fmt.Sprintf("%s/%s", backupDir, strings.ReplaceAll(fileName, ".tar.gz", ""))
|
tmpDir := fmt.Sprintf("%s/%s", backupDir, strings.ReplaceAll(fileName, ".tar.gz", ""))
|
||||||
if !fileOp.Stat(tmpDir) {
|
if !fileOp.Stat(tmpDir) {
|
||||||
@ -216,7 +216,7 @@ func handleWebsiteBackup(website *model.Website, backupDir, fileName string) err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := handleAppBackup(&app, tmpDir, fmt.Sprintf("%s.app.tar.gz", website.Alias)); err != nil {
|
if err := handleAppBackup(&app, tmpDir, fmt.Sprintf("%s.app.tar.gz", website.Alias), excludes); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
global.LOG.Info("put app.tar.gz into tmp dir successful")
|
global.LOG.Info("put app.tar.gz into tmp dir successful")
|
||||||
@ -226,7 +226,7 @@ func handleWebsiteBackup(website *model.Website, backupDir, fileName string) err
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if runtime.Type == constant.RuntimeNode {
|
if runtime.Type == constant.RuntimeNode {
|
||||||
if err := handleRuntimeBackup(runtime, tmpDir, fmt.Sprintf("%s.runtime.tar.gz", website.Alias)); err != nil {
|
if err := handleRuntimeBackup(runtime, tmpDir, fmt.Sprintf("%s.runtime.tar.gz", website.Alias), excludes); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
global.LOG.Info("put runtime.tar.gz into tmp dir successful")
|
global.LOG.Info("put runtime.tar.gz into tmp dir successful")
|
||||||
@ -234,7 +234,7 @@ func handleWebsiteBackup(website *model.Website, backupDir, fileName string) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 := handleTar(websiteDir, tmpDir, fmt.Sprintf("%s.web.tar.gz", website.Alias), ""); err != nil {
|
if err := handleTar(websiteDir, tmpDir, fmt.Sprintf("%s.web.tar.gz", website.Alias), excludes); 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")
|
||||||
|
@ -41,7 +41,7 @@ func (u *CronjobService) handleApp(cronjob model.Cronjob, startTime time.Time) e
|
|||||||
record.Source, record.BackupType = loadRecordPath(cronjob, accountMap)
|
record.Source, record.BackupType = loadRecordPath(cronjob, accountMap)
|
||||||
backupDir := path.Join(global.CONF.System.TmpDir, fmt.Sprintf("app/%s/%s", app.App.Key, app.Name))
|
backupDir := path.Join(global.CONF.System.TmpDir, fmt.Sprintf("app/%s/%s", app.App.Key, app.Name))
|
||||||
record.FileName = fmt.Sprintf("app_%s_%s.tar.gz", app.Name, startTime.Format("20060102150405")+common.RandStrAndNum(5))
|
record.FileName = fmt.Sprintf("app_%s_%s.tar.gz", app.Name, startTime.Format("20060102150405")+common.RandStrAndNum(5))
|
||||||
if err := handleAppBackup(&app, backupDir, record.FileName); err != nil {
|
if err := handleAppBackup(&app, backupDir, record.FileName, cronjob.ExclusionRules); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
downloadPath, err := u.uploadCronjobBackFile(cronjob, accountMap, path.Join(backupDir, record.FileName))
|
downloadPath, err := u.uploadCronjobBackFile(cronjob, accountMap, path.Join(backupDir, record.FileName))
|
||||||
@ -74,7 +74,7 @@ func (u *CronjobService) handleWebsite(cronjob model.Cronjob, startTime time.Tim
|
|||||||
record.Source, record.BackupType = loadRecordPath(cronjob, accountMap)
|
record.Source, record.BackupType = loadRecordPath(cronjob, accountMap)
|
||||||
backupDir := path.Join(global.CONF.System.TmpDir, fmt.Sprintf("website/%s", web.PrimaryDomain))
|
backupDir := path.Join(global.CONF.System.TmpDir, fmt.Sprintf("website/%s", web.PrimaryDomain))
|
||||||
record.FileName = fmt.Sprintf("website_%s_%s.tar.gz", web.PrimaryDomain, startTime.Format("20060102150405")+common.RandStrAndNum(5))
|
record.FileName = fmt.Sprintf("website_%s_%s.tar.gz", web.PrimaryDomain, startTime.Format("20060102150405")+common.RandStrAndNum(5))
|
||||||
if err := handleWebsiteBackup(&web, backupDir, record.FileName); err != nil {
|
if err := handleWebsiteBackup(&web, backupDir, record.FileName, cronjob.ExclusionRules); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
downloadPath, err := u.uploadCronjobBackFile(cronjob, accountMap, path.Join(backupDir, record.FileName))
|
downloadPath, err := u.uploadCronjobBackFile(cronjob, accountMap, path.Join(backupDir, record.FileName))
|
||||||
|
@ -837,6 +837,7 @@ const message = {
|
|||||||
allOptionHelper:
|
allOptionHelper:
|
||||||
'The current task plan is to back up all [{0}]. Direct download is not supported at the moment. You can check the backup list of [{0}] menu.',
|
'The current task plan is to back up all [{0}]. Direct download is not supported at the moment. You can check the backup list of [{0}] menu.',
|
||||||
exclusionRules: 'Exclusive rule',
|
exclusionRules: 'Exclusive rule',
|
||||||
|
exclusionRulesHelper: 'The exclusion rules will apply to all compression operations of this backup.',
|
||||||
default_download_path: 'Default Download Link',
|
default_download_path: 'Default Download Link',
|
||||||
saveLocal: 'Retain local backups (the same as the number of cloud storage copies)',
|
saveLocal: 'Retain local backups (the same as the number of cloud storage copies)',
|
||||||
url: 'URL Address',
|
url: 'URL Address',
|
||||||
|
@ -797,6 +797,7 @@ const message = {
|
|||||||
snapshot: '系統快照',
|
snapshot: '系統快照',
|
||||||
allOptionHelper: '當前計劃任務為備份所有【{0}】,暫不支持直接下載,可在【{0}】備份列表中查看',
|
allOptionHelper: '當前計劃任務為備份所有【{0}】,暫不支持直接下載,可在【{0}】備份列表中查看',
|
||||||
exclusionRules: '排除規則',
|
exclusionRules: '排除規則',
|
||||||
|
exclusionRulesHelper: '排除規則將對此次備份的所有壓縮操作生效',
|
||||||
default_download_path: '默認下載地址',
|
default_download_path: '默認下載地址',
|
||||||
saveLocal: '同時保留本地備份(和雲存儲保留份數一致)',
|
saveLocal: '同時保留本地備份(和雲存儲保留份數一致)',
|
||||||
url: 'URL 地址',
|
url: 'URL 地址',
|
||||||
|
@ -798,6 +798,7 @@ const message = {
|
|||||||
snapshot: '系统快照',
|
snapshot: '系统快照',
|
||||||
allOptionHelper: '当前计划任务为备份所有【{0}】,暂不支持直接下载,可在【{0}】备份列表中查看',
|
allOptionHelper: '当前计划任务为备份所有【{0}】,暂不支持直接下载,可在【{0}】备份列表中查看',
|
||||||
exclusionRules: '排除规则',
|
exclusionRules: '排除规则',
|
||||||
|
exclusionRulesHelper: '排除规则将对此次备份的所有压缩操作生效',
|
||||||
default_download_path: '默认下载地址',
|
default_download_path: '默认下载地址',
|
||||||
saveLocal: '同时保留本地备份(和云存储保留份数一致)',
|
saveLocal: '同时保留本地备份(和云存储保留份数一致)',
|
||||||
url: 'URL 地址',
|
url: 'URL 地址',
|
||||||
|
@ -320,7 +320,7 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item
|
<el-form-item
|
||||||
v-if="dialogData.rowData!.type === 'directory'"
|
v-if="hasExclusionRules()"
|
||||||
:label="$t('cronjob.exclusionRules')"
|
:label="$t('cronjob.exclusionRules')"
|
||||||
prop="exclusionRules"
|
prop="exclusionRules"
|
||||||
>
|
>
|
||||||
@ -331,6 +331,7 @@
|
|||||||
clearable
|
clearable
|
||||||
v-model="dialogData.rowData!.exclusionRules"
|
v-model="dialogData.rowData!.exclusionRules"
|
||||||
/>
|
/>
|
||||||
|
<span class="input-help">{{ $t('cronjob.exclusionRulesHelper') }}</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
@ -681,6 +682,14 @@ function isBackup() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasExclusionRules() {
|
||||||
|
return (
|
||||||
|
dialogData.value.rowData!.type === 'app' ||
|
||||||
|
dialogData.value.rowData!.type === 'website' ||
|
||||||
|
dialogData.value.rowData!.type === 'directory'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function hasScript() {
|
function hasScript() {
|
||||||
return dialogData.value.rowData!.type === 'shell';
|
return dialogData.value.rowData!.type === 'shell';
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user