Disambiguate backup status constants for SLURP storage
This commit is contained in:
@@ -12,8 +12,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/robfig/cron/v3"
|
|
||||||
"chorus/pkg/crypto"
|
"chorus/pkg/crypto"
|
||||||
|
"github.com/robfig/cron/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BackupManagerImpl implements the BackupManager interface
|
// BackupManagerImpl implements the BackupManager interface
|
||||||
@@ -69,14 +69,14 @@ type BackupEvent struct {
|
|||||||
type BackupEventType string
|
type BackupEventType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
BackupStarted BackupEventType = "backup_started"
|
BackupEventStarted BackupEventType = "backup_started"
|
||||||
BackupProgress BackupEventType = "backup_progress"
|
BackupEventProgress BackupEventType = "backup_progress"
|
||||||
BackupCompleted BackupEventType = "backup_completed"
|
BackupEventCompleted BackupEventType = "backup_completed"
|
||||||
BackupFailed BackupEventType = "backup_failed"
|
BackupEventFailed BackupEventType = "backup_failed"
|
||||||
BackupValidated BackupEventType = "backup_validated"
|
BackupEventValidated BackupEventType = "backup_validated"
|
||||||
BackupRestored BackupEventType = "backup_restored"
|
BackupEventRestored BackupEventType = "backup_restored"
|
||||||
BackupDeleted BackupEventType = "backup_deleted"
|
BackupEventDeleted BackupEventType = "backup_deleted"
|
||||||
BackupScheduled BackupEventType = "backup_scheduled"
|
BackupEventScheduled BackupEventType = "backup_scheduled"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultBackupManagerOptions returns sensible defaults
|
// DefaultBackupManagerOptions returns sensible defaults
|
||||||
@@ -163,7 +163,7 @@ func (bm *BackupManagerImpl) CreateBackup(
|
|||||||
Encrypted: config.Encryption,
|
Encrypted: config.Encryption,
|
||||||
Incremental: config.Incremental,
|
Incremental: config.Incremental,
|
||||||
ParentBackupID: config.ParentBackupID,
|
ParentBackupID: config.ParentBackupID,
|
||||||
Status: BackupInProgress,
|
Status: BackupStatusInProgress,
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
RetentionUntil: time.Now().Add(config.Retention),
|
RetentionUntil: time.Now().Add(config.Retention),
|
||||||
}
|
}
|
||||||
@@ -174,7 +174,7 @@ func (bm *BackupManagerImpl) CreateBackup(
|
|||||||
ID: backupID,
|
ID: backupID,
|
||||||
Config: config,
|
Config: config,
|
||||||
StartTime: time.Now(),
|
StartTime: time.Now(),
|
||||||
Status: BackupInProgress,
|
Status: BackupStatusInProgress,
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ func (bm *BackupManagerImpl) CreateBackup(
|
|||||||
|
|
||||||
// Notify backup started
|
// Notify backup started
|
||||||
bm.notify(&BackupEvent{
|
bm.notify(&BackupEvent{
|
||||||
Type: BackupStarted,
|
Type: BackupEventStarted,
|
||||||
BackupID: backupID,
|
BackupID: backupID,
|
||||||
Message: fmt.Sprintf("Backup '%s' started", config.Name),
|
Message: fmt.Sprintf("Backup '%s' started", config.Name),
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
@@ -213,7 +213,7 @@ func (bm *BackupManagerImpl) RestoreBackup(
|
|||||||
return fmt.Errorf("backup %s not found", backupID)
|
return fmt.Errorf("backup %s not found", backupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if backupInfo.Status != BackupCompleted {
|
if backupInfo.Status != BackupStatusCompleted {
|
||||||
return fmt.Errorf("backup %s is not completed (status: %s)", backupID, backupInfo.Status)
|
return fmt.Errorf("backup %s is not completed (status: %s)", backupID, backupInfo.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,7 +276,7 @@ func (bm *BackupManagerImpl) DeleteBackup(ctx context.Context, backupID string)
|
|||||||
|
|
||||||
// Notify deletion
|
// Notify deletion
|
||||||
bm.notify(&BackupEvent{
|
bm.notify(&BackupEvent{
|
||||||
Type: BackupDeleted,
|
Type: BackupEventDeleted,
|
||||||
BackupID: backupID,
|
BackupID: backupID,
|
||||||
Message: fmt.Sprintf("Backup '%s' deleted", backupInfo.Name),
|
Message: fmt.Sprintf("Backup '%s' deleted", backupInfo.Name),
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
@@ -348,7 +348,7 @@ func (bm *BackupManagerImpl) ValidateBackup(
|
|||||||
|
|
||||||
// Notify validation completed
|
// Notify validation completed
|
||||||
bm.notify(&BackupEvent{
|
bm.notify(&BackupEvent{
|
||||||
Type: BackupValidated,
|
Type: BackupEventValidated,
|
||||||
BackupID: backupID,
|
BackupID: backupID,
|
||||||
Message: fmt.Sprintf("Backup validation completed (valid: %v)", validation.Valid),
|
Message: fmt.Sprintf("Backup validation completed (valid: %v)", validation.Valid),
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
@@ -396,7 +396,7 @@ func (bm *BackupManagerImpl) ScheduleBackup(
|
|||||||
|
|
||||||
// Notify scheduling
|
// Notify scheduling
|
||||||
bm.notify(&BackupEvent{
|
bm.notify(&BackupEvent{
|
||||||
Type: BackupScheduled,
|
Type: BackupEventScheduled,
|
||||||
BackupID: schedule.ID,
|
BackupID: schedule.ID,
|
||||||
Message: fmt.Sprintf("Backup schedule '%s' created", schedule.Name),
|
Message: fmt.Sprintf("Backup schedule '%s' created", schedule.Name),
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
@@ -429,13 +429,13 @@ func (bm *BackupManagerImpl) GetBackupStats(ctx context.Context) (*BackupStatist
|
|||||||
|
|
||||||
for _, backup := range bm.backups {
|
for _, backup := range bm.backups {
|
||||||
switch backup.Status {
|
switch backup.Status {
|
||||||
case BackupCompleted:
|
case BackupStatusCompleted:
|
||||||
stats.SuccessfulBackups++
|
stats.SuccessfulBackups++
|
||||||
if backup.CompletedAt != nil {
|
if backup.CompletedAt != nil {
|
||||||
backupTime := backup.CompletedAt.Sub(backup.CreatedAt)
|
backupTime := backup.CompletedAt.Sub(backup.CreatedAt)
|
||||||
totalTime += backupTime
|
totalTime += backupTime
|
||||||
}
|
}
|
||||||
case BackupFailed:
|
case BackupStatusFailed:
|
||||||
stats.FailedBackups++
|
stats.FailedBackups++
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -544,7 +544,7 @@ func (bm *BackupManagerImpl) performBackup(
|
|||||||
// Update backup info
|
// Update backup info
|
||||||
completedAt := time.Now()
|
completedAt := time.Now()
|
||||||
bm.mu.Lock()
|
bm.mu.Lock()
|
||||||
backupInfo.Status = BackupCompleted
|
backupInfo.Status = BackupStatusCompleted
|
||||||
backupInfo.DataSize = finalSize
|
backupInfo.DataSize = finalSize
|
||||||
backupInfo.CompressedSize = finalSize // Would be different if compression is applied
|
backupInfo.CompressedSize = finalSize // Would be different if compression is applied
|
||||||
backupInfo.Checksum = checksum
|
backupInfo.Checksum = checksum
|
||||||
@@ -560,7 +560,7 @@ func (bm *BackupManagerImpl) performBackup(
|
|||||||
|
|
||||||
// Notify completion
|
// Notify completion
|
||||||
bm.notify(&BackupEvent{
|
bm.notify(&BackupEvent{
|
||||||
Type: BackupCompleted,
|
Type: BackupEventCompleted,
|
||||||
BackupID: job.ID,
|
BackupID: job.ID,
|
||||||
Message: fmt.Sprintf("Backup '%s' completed successfully", job.Config.Name),
|
Message: fmt.Sprintf("Backup '%s' completed successfully", job.Config.Name),
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
@@ -607,7 +607,7 @@ func (bm *BackupManagerImpl) performRestore(
|
|||||||
|
|
||||||
// Notify restore completion
|
// Notify restore completion
|
||||||
bm.notify(&BackupEvent{
|
bm.notify(&BackupEvent{
|
||||||
Type: BackupRestored,
|
Type: BackupEventRestored,
|
||||||
BackupID: backupInfo.BackupID,
|
BackupID: backupInfo.BackupID,
|
||||||
Message: fmt.Sprintf("Backup '%s' restored successfully", backupInfo.Name),
|
Message: fmt.Sprintf("Backup '%s' restored successfully", backupInfo.Name),
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
@@ -706,13 +706,13 @@ func (bm *BackupManagerImpl) validateFile(filePath string) error {
|
|||||||
|
|
||||||
func (bm *BackupManagerImpl) failBackup(job *BackupJob, backupInfo *BackupInfo, err error) {
|
func (bm *BackupManagerImpl) failBackup(job *BackupJob, backupInfo *BackupInfo, err error) {
|
||||||
bm.mu.Lock()
|
bm.mu.Lock()
|
||||||
backupInfo.Status = BackupFailed
|
backupInfo.Status = BackupStatusFailed
|
||||||
backupInfo.ErrorMessage = err.Error()
|
backupInfo.ErrorMessage = err.Error()
|
||||||
job.Error = err
|
job.Error = err
|
||||||
bm.mu.Unlock()
|
bm.mu.Unlock()
|
||||||
|
|
||||||
bm.notify(&BackupEvent{
|
bm.notify(&BackupEvent{
|
||||||
Type: BackupFailed,
|
Type: BackupEventFailed,
|
||||||
BackupID: job.ID,
|
BackupID: job.ID,
|
||||||
Message: fmt.Sprintf("Backup '%s' failed: %v", job.Config.Name, err),
|
Message: fmt.Sprintf("Backup '%s' failed: %v", job.Config.Name, err),
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package storage
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"chorus/pkg/ucxl"
|
|
||||||
"chorus/pkg/crypto"
|
"chorus/pkg/crypto"
|
||||||
slurpContext "chorus/pkg/slurp/context"
|
slurpContext "chorus/pkg/slurp/context"
|
||||||
|
"chorus/pkg/ucxl"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ListCriteria represents criteria for listing contexts
|
// ListCriteria represents criteria for listing contexts
|
||||||
@@ -315,12 +315,15 @@ type BackupInfo struct {
|
|||||||
type BackupStatus string
|
type BackupStatus string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
BackupInProgress BackupStatus = "in_progress"
|
BackupStatusInProgress BackupStatus = "in_progress"
|
||||||
BackupCompleted BackupStatus = "completed"
|
BackupStatusCompleted BackupStatus = "completed"
|
||||||
BackupFailed BackupStatus = "failed"
|
BackupStatusFailed BackupStatus = "failed"
|
||||||
BackupCorrupted BackupStatus = "corrupted"
|
BackupStatusCorrupted BackupStatus = "corrupted"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DistributedStorageOptions aliases DistributedStoreOptions for backwards compatibility.
|
||||||
|
type DistributedStorageOptions = DistributedStoreOptions
|
||||||
|
|
||||||
// RestoreConfig represents restore configuration
|
// RestoreConfig represents restore configuration
|
||||||
type RestoreConfig struct {
|
type RestoreConfig struct {
|
||||||
BackupID string `json:"backup_id"` // Backup to restore from
|
BackupID string `json:"backup_id"` // Backup to restore from
|
||||||
|
|||||||
Reference in New Issue
Block a user