Windows install script fails to migrate old data dir
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.ps1andStart-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 theFilebeatsubdirectory.
├── 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:
- Original PR with the migration changes and more detailed instructions https://github.com/elastic/beats/pull/43995
Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)
FYI @belimawr as I think you did the initial version of this.
Since we already know the fix I am in favour of just doing it.
Since we already know the fix I am in favour of just doing it.
Agreed, the fix seems straightforward. I created an issue because I'm going on PTO for two weeks and didn't want to leave this hanging. Testing this is a bit time-consuming, so I wanted to pave the way for whoever will work on it in the meantime.
Yeah, we should just fix this. As @mauri870 said, it is a small change, but time consuming to test. I'm trying to finish some other tasks for the FF, so I'm not sure I'll have time to also take this one if we want it done before the FF.
One thing to make sure is that the fix works for both: someone updating from an old Filebeat version (before the path change) and someone updating from the current buggy version to the fixed one.