Skip to content

Windows install script fails to migrate old data dir #48070

@mauri870

Description

@mauri870

When a beat is installed following the zip docs on a Windows system that has an older beat (<8.19) version installed, it migrates the old data dir but places it in the wrong location, causing the new beat instance to start with a fresh registry instead of reusing the migrated one.

For confirmed bugs, please report:

  • Version: Filebeat 8.19, 9.x, should affect any beat
  • Operating System: Windows 11 25H2, PowerShell 5.1.26100 and 6.2.3

Steps to Reproduce:

  • Download a Filebeat 8.15 windows zip and run .\install-service-filebeat.ps1 and Start-Service filebeat.
  • Verify that the data files exist at C:\ProgramData\Filebeat.
  • Download a Filebeat 9.2.2 windows zip and run .\install-service-filebeat.ps1.
  • The migrated files from the old Filebeat installation were placed in C:\Program Files\Filebeat-Data, one directory too high. They should have been placed inside the Filebeat subdirectory.
├── Filebeat-Data
│   ├── Filebeat
│   │   ├── filebeat.lock
│   │   ├── logs
│   │   ├── meta.json
│   │   └── registry
│   ├── filebeat.lock
│   ├── logs
│   ├── meta.json
│   └── registry

From my debugging session, changing the installation script seems to fix the issue:

diff --git a/dev-tools/packaging/templates/windows/install-service.ps1.tmpl b/dev-tools/packaging/templates/windows/install-service.ps1.tmpl
index 9dd27e2dd1..100f209041 100644
--- a/dev-tools/packaging/templates/windows/install-service.ps1.tmpl
+++ b/dev-tools/packaging/templates/windows/install-service.ps1.tmpl
@@ -46,7 +46,10 @@ If ($ForceLegacyPath -eq $True) {
 } elseif (Test-Path $LegacyDataPath) {
     Write-Output "Files found at $LegacyDataPath, moving them to $BasePath"
   Try {
-    Move-Item $LegacyDataPath $BasePath -ErrorAction Stop
+    if (-not (Test-Path $BasePath)) {
+      New-Item -ItemType Directory -Path $BasePath -ErrorAction Stop
+    }
+    Move-Item $LegacyDataPath "$BasePath\Filebeat" -Force -ErrorAction Stop
   } Catch {
     Write-Output "Could not move $LegacyDataPath to $BasePath"
     Write-Output "make sure the folder can be moved or set -ForceLegacyPath"

Related issues:

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions