(req dto.CommonBackup)
| 72 | } |
| 73 | |
| 74 | func (u *BackupService) ComposeBackup(req dto.CommonBackup) error { |
| 75 | timeNow := time.Now().Format(constant.DateTimeSlimLayout) + common.RandStrAndNum(5) |
| 76 | fileName := req.FileName |
| 77 | if fileName == "" { |
| 78 | fileName = fmt.Sprintf("%s_%s.tar.gz", req.Name, timeNow) |
| 79 | } |
| 80 | if !strings.HasSuffix(fileName, ".tar.gz") { |
| 81 | fileName += ".tar.gz" |
| 82 | } |
| 83 | itemDir := fmt.Sprintf("compose/%s", req.Name) |
| 84 | backupDir := path.Join(global.Dir.LocalBackupDir, itemDir) |
| 85 | record := &model.BackupRecord{ |
| 86 | Type: req.Type, |
| 87 | Name: req.Name, |
| 88 | SourceAccountIDs: "1", |
| 89 | DownloadAccountID: 1, |
| 90 | FileDir: itemDir, |
| 91 | FileName: fileName, |
| 92 | TaskID: req.TaskID, |
| 93 | Status: constant.StatusWaiting, |
| 94 | Description: req.Description, |
| 95 | } |
| 96 | if err := backupRepo.CreateRecord(record); err != nil { |
| 97 | global.LOG.Errorf("save compose backup record failed, err: %v", err) |
| 98 | return err |
| 99 | } |
| 100 | if err := handleComposeBackup(req, nil, record.ID, backupDir, fileName); err != nil { |
| 101 | backupRepo.UpdateRecordByMap(record.ID, map[string]interface{}{"status": constant.StatusFailed, "message": err.Error()}) |
| 102 | return err |
| 103 | } |
| 104 | return nil |
| 105 | } |
| 106 | |
| 107 | func (u *BackupService) ComposeRecover(req dto.CommonRecover) error { |
| 108 | return handleComposeRecover(req, nil) |
nothing calls this directly
no test coverage detected