better snapshots management
This commit is contained in:
@@ -480,6 +480,8 @@ func (s *Server) handleAdminDeleteSnapshot(w http.ResponseWriter, r *http.Reques
|
|||||||
if snap != nil {
|
if snap != nil {
|
||||||
if snap.StorageType == "s3" && s.s3Backend != nil {
|
if snap.StorageType == "s3" && s.s3Backend != nil {
|
||||||
s.s3Backend.Delete(context.Background(), snap.StorageKey)
|
s.s3Backend.Delete(context.Background(), snap.StorageKey)
|
||||||
|
} else if snap.StorageType == "local" && s.localBackend != nil {
|
||||||
|
s.localBackend.Delete(context.Background(), snap.StorageKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,21 +126,21 @@ func (s *Server) rotateSnapshots(clientID string) (int, int64) {
|
|||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select appropriate backend
|
// Delete snapshots - use correct backend based on each snapshot's storage type
|
||||||
var backend StorageBackend
|
|
||||||
if s.s3Backend != nil {
|
|
||||||
backend = s.s3Backend
|
|
||||||
} else if s.localBackend != nil {
|
|
||||||
backend = s.localBackend
|
|
||||||
} else {
|
|
||||||
log.Printf("No storage backend available for rotation")
|
|
||||||
return 0, 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete snapshots
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
for _, snap := range toDelete {
|
for _, snap := range toDelete {
|
||||||
if err := backend.Delete(ctx, snap.StorageKey); err != nil {
|
// Determine which backend to use for this specific snapshot
|
||||||
|
var snapBackend StorageBackend
|
||||||
|
if snap.StorageType == "s3" && s.s3Backend != nil {
|
||||||
|
snapBackend = s.s3Backend
|
||||||
|
} else if snap.StorageType == "local" && s.localBackend != nil {
|
||||||
|
snapBackend = s.localBackend
|
||||||
|
} else {
|
||||||
|
log.Printf("No storage backend available for snapshot %s (type: %s)", snap.SnapshotID, snap.StorageType)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := snapBackend.Delete(ctx, snap.StorageKey); err != nil {
|
||||||
log.Printf("Error deleting snapshot %s: %v", snap.StorageKey, err)
|
log.Printf("Error deleting snapshot %s: %v", snap.StorageKey, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -326,6 +326,7 @@ func (s *Server) HandleUploadStream(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save metadata to database
|
// Save metadata to database
|
||||||
|
// Use actual storage type where snapshot was stored (not always s3)
|
||||||
metadata := &SnapshotMetadata{
|
metadata := &SnapshotMetadata{
|
||||||
ClientID: clientID,
|
ClientID: clientID,
|
||||||
SnapshotID: storageKey,
|
SnapshotID: storageKey,
|
||||||
@@ -333,7 +334,7 @@ func (s *Server) HandleUploadStream(w http.ResponseWriter, r *http.Request) {
|
|||||||
SizeBytes: actualSize,
|
SizeBytes: actualSize,
|
||||||
DatasetName: datasetName,
|
DatasetName: datasetName,
|
||||||
StorageKey: storageKey,
|
StorageKey: storageKey,
|
||||||
StorageType: "s3",
|
StorageType: client.StorageType, // Use actual storage type from client config
|
||||||
Compressed: compressedStr == "true",
|
Compressed: compressedStr == "true",
|
||||||
Incremental: incrementalStr == "true",
|
Incremental: incrementalStr == "true",
|
||||||
BaseSnapshot: baseSnapshot,
|
BaseSnapshot: baseSnapshot,
|
||||||
@@ -450,15 +451,17 @@ func (s *Server) HandleDownload(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use snapshot's own storage_type to determine which backend to use
|
||||||
|
// This enables mixed storage scenarios (e.g., full on local, incrementals on S3)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
var backend StorageBackend
|
var backend StorageBackend
|
||||||
|
|
||||||
if client.StorageType == "s3" && s.s3Backend != nil {
|
if targetSnapshot.StorageType == "s3" && s.s3Backend != nil {
|
||||||
backend = s.s3Backend
|
backend = s.s3Backend
|
||||||
} else if s.localBackend != nil {
|
} else if targetSnapshot.StorageType == "local" && s.localBackend != nil {
|
||||||
backend = s.localBackend
|
backend = s.localBackend
|
||||||
} else {
|
} else {
|
||||||
http.Error(w, "No storage backend available", http.StatusInternalServerError)
|
http.Error(w, "No storage backend available for this snapshot's storage type", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user