(req dto.CommonBackup)
| 29 | ) |
| 30 | |
| 31 | func (u *BackupService) AppBackup(req dto.CommonBackup) (*model.BackupRecord, error) { |
| 32 | app, err := appRepo.GetFirst(appRepo.WithKey(req.Name)) |
| 33 | if err != nil { |
| 34 | return nil, err |
| 35 | } |
| 36 | install, err := appInstallRepo.GetFirst(repo.WithByName(req.DetailName), appInstallRepo.WithAppId(app.ID)) |
| 37 | if err != nil { |
| 38 | return nil, err |
| 39 | } |
| 40 | timeNow := time.Now().Format(constant.DateTimeSlimLayout) |
| 41 | itemDir := fmt.Sprintf("app/%s/%s", req.Name, req.DetailName) |
| 42 | backupDir := path.Join(global.Dir.LocalBackupDir, itemDir) |
| 43 | |
| 44 | fileName := req.FileName |
| 45 | if req.FileName == "" { |
| 46 | fileName = fmt.Sprintf("%s_%s.tar.gz", req.DetailName, timeNow+common.RandStrAndNum(5)) |
| 47 | } |
| 48 | |
| 49 | record := &model.BackupRecord{ |
| 50 | Type: "app", |
| 51 | Name: req.Name, |
| 52 | DetailName: req.DetailName, |
| 53 | SourceAccountIDs: "1", |
| 54 | DownloadAccountID: 1, |
| 55 | FileDir: itemDir, |
| 56 | FileName: fileName, |
| 57 | TaskID: req.TaskID, |
| 58 | Status: constant.StatusWaiting, |
| 59 | Description: req.Description, |
| 60 | } |
| 61 | if err := backupRepo.CreateRecord(record); err != nil { |
| 62 | global.LOG.Errorf("save backup record failed, err: %v", err) |
| 63 | return nil, err |
| 64 | } |
| 65 | |
| 66 | if err = handleAppBackup(&install, nil, record.ID, backupDir, fileName, "", req.Secret, req.TaskID); err != nil { |
| 67 | global.LOG.Errorf("backup app %s failed, err: %v", req.DetailName, err) |
| 68 | return nil, err |
| 69 | } |
| 70 | |
| 71 | return record, nil |
| 72 | } |
| 73 | |
| 74 | func (u *BackupService) AppRecover(req dto.CommonRecover) error { |
| 75 | app, err := appRepo.GetFirst(appRepo.WithKey(req.Name)) |
nothing calls this directly
no test coverage detected