diff --git a/ee/agent/storage/bbolt/backup.go b/ee/agent/storage/bbolt/backup.go index f26315c6a4..b7cf92022a 100644 --- a/ee/agent/storage/bbolt/backup.go +++ b/ee/agent/storage/bbolt/backup.go @@ -13,8 +13,8 @@ import ( ) const ( - backupInitialDelay = 10 * time.Minute - backupInterval = 1 * time.Hour + backupInitialDelay = 10 * time.Second + backupInterval = 1 * time.Minute numberOfOldBackupsToRetain = 3 ) @@ -136,8 +136,11 @@ func (d *databaseBackupSaver) rotate() error { } } - if err := os.Rename(baseBackupPath, fmt.Sprintf("%s.1", baseBackupPath)); err != nil { - return fmt.Errorf("rotating %s: %w", baseBackupPath, err) + // Rename launcher.db.bak, if present + if _, err := os.Stat(baseBackupPath); err == nil { + if err := os.Rename(baseBackupPath, fmt.Sprintf("%s.1", baseBackupPath)); err != nil { + return fmt.Errorf("rotating %s: %w", baseBackupPath, err) + } } return nil diff --git a/ee/agent/storage/bbolt/backup_test.go b/ee/agent/storage/bbolt/backup_test.go index 657b5c3de5..c92cdd74f7 100644 --- a/ee/agent/storage/bbolt/backup_test.go +++ b/ee/agent/storage/bbolt/backup_test.go @@ -147,6 +147,10 @@ func Test_rotate(t *testing.T) { } } } + + // Test rotation when backup db does not exist + _ = os.Remove(backupDbFileLocation) + require.NoError(t, d.rotate(), "must be able to rotate even when launcher.db.bak does not exist") } func TestInterrupt_Multiple(t *testing.T) {