Skip to content

Commit

Permalink
Fix rotation after falling back to backup db
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Jun 18, 2024
1 parent e75bd61 commit 822af61
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ee/agent/storage/bbolt/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
)

const (
backupInitialDelay = 10 * time.Minute
backupInterval = 1 * time.Hour
backupInitialDelay = 10 * time.Second
backupInterval = 1 * time.Minute
numberOfOldBackupsToRetain = 3
)

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions ee/agent/storage/bbolt/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 822af61

Please sign in to comment.