mirror of
https://github.com/databasus/databasus.git
synced 2026-04-06 00:32:03 +02:00
FIX (copying): Fix persisting same interval over copying
This commit is contained in:
@@ -20,7 +20,6 @@ import (
|
||||
"postgresus-backend/internal/features/disk"
|
||||
healthcheck_attempt "postgresus-backend/internal/features/healthcheck/attempt"
|
||||
healthcheck_config "postgresus-backend/internal/features/healthcheck/config"
|
||||
postgres_monitoring_collectors "postgresus-backend/internal/features/monitoring/postgres/collectors"
|
||||
postgres_monitoring_metrics "postgresus-backend/internal/features/monitoring/postgres/metrics"
|
||||
postgres_monitoring_settings "postgresus-backend/internal/features/monitoring/postgres/settings"
|
||||
"postgresus-backend/internal/features/notifiers"
|
||||
@@ -210,10 +209,6 @@ func runBackgroundTasks(log *slog.Logger) {
|
||||
go runWithPanicLogging(log, "postgres monitoring metrics background service", func() {
|
||||
postgres_monitoring_metrics.GetPostgresMonitoringMetricsBackgroundService().Run()
|
||||
})
|
||||
|
||||
go runWithPanicLogging(log, "postgres monitoring collectors background service", func() {
|
||||
postgres_monitoring_collectors.GetDbMonitoringBackgroundService().Run()
|
||||
})
|
||||
}
|
||||
|
||||
func runWithPanicLogging(log *slog.Logger, serviceName string, fn func()) {
|
||||
|
||||
@@ -90,3 +90,18 @@ func (b *BackupConfig) Validate() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *BackupConfig) Copy(newDatabaseID uuid.UUID) *BackupConfig {
|
||||
return &BackupConfig{
|
||||
DatabaseID: newDatabaseID,
|
||||
IsBackupsEnabled: b.IsBackupsEnabled,
|
||||
StorePeriod: b.StorePeriod,
|
||||
BackupIntervalID: uuid.Nil,
|
||||
BackupInterval: b.BackupInterval.Copy(),
|
||||
StorageID: b.StorageID,
|
||||
SendNotificationsOn: b.SendNotificationsOn,
|
||||
IsRetryIfFailed: b.IsRetryIfFailed,
|
||||
MaxFailedTriesCount: b.MaxFailedTriesCount,
|
||||
CpuCount: b.CpuCount,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +130,20 @@ func (s *BackupConfigService) GetBackupConfigsWithEnabledBackups() ([]*BackupCon
|
||||
return s.backupConfigRepository.GetWithEnabledBackups()
|
||||
}
|
||||
|
||||
func (s *BackupConfigService) OnDatabaseCopied(originalDatabaseID, newDatabaseID uuid.UUID) {
|
||||
originalConfig, err := s.GetBackupConfigByDbId(originalDatabaseID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
newConfig := originalConfig.Copy(newDatabaseID)
|
||||
|
||||
_, err = s.SaveBackupConfig(newConfig)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (s *BackupConfigService) initializeDefaultConfig(
|
||||
databaseID uuid.UUID,
|
||||
) error {
|
||||
@@ -164,27 +178,3 @@ func storageIDsEqual(id1, id2 *uuid.UUID) bool {
|
||||
}
|
||||
return *id1 == *id2
|
||||
}
|
||||
|
||||
func (s *BackupConfigService) OnDatabaseCopied(originalDatabaseID, newDatabaseID uuid.UUID) {
|
||||
originalConfig, err := s.GetBackupConfigByDbId(originalDatabaseID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
newConfig := &BackupConfig{
|
||||
DatabaseID: newDatabaseID,
|
||||
IsBackupsEnabled: originalConfig.IsBackupsEnabled,
|
||||
StorePeriod: originalConfig.StorePeriod,
|
||||
BackupIntervalID: originalConfig.BackupIntervalID,
|
||||
StorageID: originalConfig.StorageID,
|
||||
SendNotificationsOn: originalConfig.SendNotificationsOn,
|
||||
IsRetryIfFailed: originalConfig.IsRetryIfFailed,
|
||||
MaxFailedTriesCount: originalConfig.MaxFailedTriesCount,
|
||||
CpuCount: originalConfig.CpuCount,
|
||||
}
|
||||
|
||||
_, err = s.SaveBackupConfig(newConfig)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +64,16 @@ func (i *Interval) ShouldTriggerBackup(now time.Time, lastBackupTime *time.Time)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Interval) Copy() *Interval {
|
||||
return &Interval{
|
||||
ID: uuid.Nil,
|
||||
Interval: i.Interval,
|
||||
TimeOfDay: i.TimeOfDay,
|
||||
Weekday: i.Weekday,
|
||||
DayOfMonth: i.DayOfMonth,
|
||||
}
|
||||
}
|
||||
|
||||
// daily trigger: honour the TimeOfDay slot and catch up the previous one
|
||||
func (i *Interval) shouldTriggerDaily(now, lastBackup time.Time) bool {
|
||||
if i.TimeOfDay == nil {
|
||||
|
||||
Reference in New Issue
Block a user