(req dto.CommonBackup)
| 27 | ) |
| 28 | |
| 29 | func (u *BackupService) WebsiteBackup(req dto.CommonBackup) error { |
| 30 | website, err := websiteRepo.GetFirst(websiteRepo.WithAlias(req.DetailName)) |
| 31 | if err != nil { |
| 32 | return err |
| 33 | } |
| 34 | |
| 35 | timeNow := time.Now().Format(constant.DateTimeSlimLayout) |
| 36 | itemDir := fmt.Sprintf("website/%s", website.Alias) |
| 37 | backupDir := path.Join(global.Dir.LocalBackupDir, itemDir) |
| 38 | fileName := fmt.Sprintf("%s_%s.tar.gz", website.Alias, timeNow+common.RandStrAndNum(5)) |
| 39 | |
| 40 | record := &model.BackupRecord{ |
| 41 | Type: "website", |
| 42 | Name: website.Alias, |
| 43 | DetailName: website.Alias, |
| 44 | SourceAccountIDs: "1", |
| 45 | DownloadAccountID: 1, |
| 46 | FileDir: itemDir, |
| 47 | FileName: fileName, |
| 48 | TaskID: req.TaskID, |
| 49 | Status: constant.StatusWaiting, |
| 50 | Description: req.Description, |
| 51 | } |
| 52 | if err = backupRepo.CreateRecord(record); err != nil { |
| 53 | global.LOG.Errorf("save backup record failed, err: %v", err) |
| 54 | return err |
| 55 | } |
| 56 | if err = handleWebsiteBackup(&website, nil, record.ID, backupDir, fileName, "", req.Secret, req.TaskID); err != nil { |
| 57 | global.LOG.Errorf("backup website %s failed, err: %v", website.Alias, err) |
| 58 | return err |
| 59 | } |
| 60 | return nil |
| 61 | } |
| 62 | |
| 63 | func (u *BackupService) WebsiteRecover(req dto.CommonRecover) error { |
| 64 | website, err := websiteRepo.GetFirst(websiteRepo.WithAlias(req.DetailName)) |
nothing calls this directly
no test coverage detected