diff --git a/backend/app/service/snapshot.go b/backend/app/service/snapshot.go index 074ad9bce..ceaf76df2 100644 --- a/backend/app/service/snapshot.go +++ b/backend/app/service/snapshot.go @@ -71,13 +71,14 @@ func (u *SnapshotService) SnapshotImport(req dto.SnapshotImport) error { } } for _, snap := range req.Names { - nameItems := strings.Split(snap, "_") - if !strings.HasPrefix(snap, "1panel_v") || !strings.HasSuffix(snap, ".tar.gz") || len(nameItems) != 3 { - return fmt.Errorf("incorrect snapshot name format of %s", snap) + shortName := strings.TrimPrefix(snap, "snapshot_") + nameItems := strings.Split(shortName, "_") + if !strings.HasPrefix(shortName, "1panel_v") || !strings.HasSuffix(shortName, ".tar.gz") || len(nameItems) != 3 { + return fmt.Errorf("incorrect snapshot name format of %s", shortName) } formatTime, err := time.Parse("20060102150405", strings.ReplaceAll(nameItems[2], ".tar.gz", "")) if err != nil { - return fmt.Errorf("incorrect snapshot name format of %s", snap) + return fmt.Errorf("incorrect snapshot name format of %s", shortName) } if strings.HasSuffix(snap, ".tar.gz") { snap = strings.ReplaceAll(snap, ".tar.gz", "") diff --git a/backend/app/service/snapshot_create.go b/backend/app/service/snapshot_create.go index a601b1e76..4cdb098f2 100644 --- a/backend/app/service/snapshot_create.go +++ b/backend/app/service/snapshot_create.go @@ -171,6 +171,7 @@ func snapCompress(snap snapHelper, rootDir string) { size := common.LoadSizeUnit(float64(stat.Size())) global.LOG.Debugf("compress successful! size of file: %s", size) snap.Status.Compress = constant.StatusDone + snap.Status.Size = size _ = snapshotRepo.UpdateStatus(snap.Status.ID, map[string]interface{}{"compress": constant.StatusDone, "size": size}) }