Skip to content

Commit b05e573

Browse files
feat: 升级应用增加备份选项 (#1750)
Refs #1742
1 parent 3b9f92e commit b05e573

File tree

10 files changed

+22
-6
lines changed

10 files changed

+22
-6
lines changed

backend/app/dto/request/app.go

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type AppInstalledOperate struct {
5858
ForceDelete bool `json:"forceDelete"`
5959
DeleteBackup bool `json:"deleteBackup"`
6060
DeleteDB bool `json:"deleteDB"`
61+
Backup bool `json:"backup"`
6162
}
6263

6364
type AppInstalledUpdate struct {

backend/app/service/app_install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (a *AppInstallService) Operate(req request.AppInstalledOperate) error {
236236
case constant.Sync:
237237
return syncById(install.ID)
238238
case constant.Upgrade:
239-
return upgradeInstall(install.ID, req.DetailId)
239+
return upgradeInstall(install.ID, req.DetailId, req.Backup)
240240
default:
241241
return errors.New("operate not support")
242242
}

backend/app/service/app_utils.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func deleteLink(ctx context.Context, install *model.AppInstall, deleteDB bool, f
227227
return appInstallResourceRepo.DeleteBy(ctx, appInstallResourceRepo.WithAppInstallId(install.ID))
228228
}
229229

230-
func upgradeInstall(installId uint, detailId uint) error {
230+
func upgradeInstall(installId uint, detailId uint, backup bool) error {
231231
install, err := appInstallRepo.GetFirst(commonRepo.WithByID(installId))
232232
if err != nil {
233233
return err
@@ -239,13 +239,14 @@ func upgradeInstall(installId uint, detailId uint) error {
239239
if install.Version == detail.Version {
240240
return errors.New("two version is same")
241241
}
242-
if err := NewIBackupService().AppBackup(dto.CommonBackup{Name: install.App.Key, DetailName: install.Name}); err != nil {
243-
return err
244-
}
245-
246242
install.Status = constant.Upgrading
247243

248244
go func() {
245+
if backup {
246+
if err = NewIBackupService().AppBackup(dto.CommonBackup{Name: install.App.Key, DetailName: install.Name}); err != nil {
247+
global.LOG.Errorf(i18n.GetMsgWithMap("ErrAppBackup", map[string]interface{}{"name": install.Name, "err": err.Error()}))
248+
}
249+
}
249250
var upErr error
250251
defer func() {
251252
if upErr != nil {

backend/i18n/lang/en.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ ErrNoSuchHost: "Network connection failed"
4444
ErrImagePullTimeOut: 'Image pull timeout'
4545
ErrContainerNotFound: '{{ .name }} container does not exist'
4646
ErrContainerMsg: '{{ .name }} container is abnormal, please check the log on the container page for details'
47+
ErrAppBackup: '{{ .name }} application backup failed err {{.err}}'
4748

4849
#file
4950
ErrFileCanNotRead: "File can not read"

backend/i18n/lang/zh-Hant.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ ErrNoSuchHost: "網路連接失敗"
4444
ErrImagePullTimeOut: "鏡像拉取超時"
4545
ErrContainerNotFound: '{{ .name }} 容器不存在'
4646
ErrContainerMsg: '{{ .name }} 容器異常,具體請在容器頁面查看日誌'
47+
ErrAppBackup: '{{ .name }} 應用備份失敗 err {{.err}}'
4748

4849
#file
4950
ErrFileCanNotRead: "此文件不支持預覽"

backend/i18n/lang/zh.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ ErrNoSuchHost: "网络连接失败"
4444
ErrImagePullTimeOut: '镜像拉取超时'
4545
ErrContainerNotFound: '{{ .name }} 容器不存在'
4646
ErrContainerMsg: '{{ .name }} 容器异常,具体请在容器页面查看日志'
47+
ErrAppBackup: '{{ .name }} 应用备份失败 err {{.err}}'
4748

4849
#file
4950
ErrFileCanNotRead: "此文件不支持预览"

frontend/src/lang/modules/en.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,8 @@ const message = {
12211221
cancelIgnore: 'Cancel ignore',
12221222
ignoreList: 'ignore list',
12231223
appHelper: 'Please view the installation instructions of some applications on the application details page',
1224+
backupApp: 'Backup application before upgrade',
1225+
backupAppHelper: 'If the upgrade fails, you can use the application backup to roll back',
12241226
},
12251227
website: {
12261228
website: 'Website',

frontend/src/lang/modules/tw.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,8 @@ const message = {
11661166
cancelIgnore: '取消忽略',
11671167
ignoreList: '忽略列表',
11681168
appHelper: '部分應用的安裝使用說明請在應用詳情頁查看',
1169+
backupApp: '升級前備份應用',
1170+
backupAppHelper: '升級失敗可以使用應用備份回滾',
11691171
},
11701172
website: {
11711173
website: '網站',

frontend/src/lang/modules/zh.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,8 @@ const message = {
11661166
cancelIgnore: '取消忽略',
11671167
ignoreList: '忽略列表',
11681168
appHelper: '部分应用的安装使用说明请在应用详情页查看',
1169+
backupApp: '升级前备份应用',
1170+
backupAppHelper: '升级失败可以使用应用备份回滚',
11691171
},
11701172
website: {
11711173
website: '网站',

frontend/src/views/app-store/installed/upgrade/index.vue

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
></el-option>
2828
</el-select>
2929
</el-form-item>
30+
<el-form-item prop="backup" v-if="operateReq.operate === 'upgrade'">
31+
<el-checkbox v-model="operateReq.backup" :label="$t('app.backupApp')" />
32+
<span class="input-help">{{ $t('app.backupAppHelper') }}</span>
33+
</el-form-item>
3034
</el-form>
3135
</el-col>
3236
</el-row>
@@ -59,6 +63,7 @@ const operateReq = reactive({
5963
detailId: 0,
6064
operate: 'upgrade',
6165
installId: 0,
66+
backup: true,
6267
});
6368
const resourceName = ref('');
6469
const rules = ref<any>({

0 commit comments

Comments
 (0)