Issues
Issues copied to clipboard
Task logs for certain system tasks remain on disk
Severity
Not blocking
Version
Confirmed in 2025.2.10454 (but likely has been present for a while)
Latest Version
None
What happened?
Task logs for certain system tasks remain on disk. Similar to https://github.com/OctopusDeploy/Issues/issues/6065 and https://github.com/OctopusDeploy/Issues/issues/7451
Confirmed the following affected tasks types:
- Synchronize Community Step Templates
- Send Telemetry
- Check System Integrity
- Check target health for Default Machine Policy
- Synchronize external security groups
- Apply retention policies
- Process recurring scheduled triggers
- Check target health for cloud targets
- Acquire Step Packages
Possibly related to event retention.
Confirmed there is no reference to the ServerTasks IDs for the Task Logs on disk in the database. Orphaned ServerTasks yield a 404 via /api/tasks/ServerTasks-XXXXX.
Reproduction
Run the workaround script against a local instance that has event retention enabled.
Error and Stacktrace
More Information
No response
Workaround
# This script is intended to remove orphaned task logs from disk. Running the script as is will print the names of the task log files to be deleted.
# Line 45 responsible for deletion is commented out. Please take a backup of your task logs folder before uncommenting line 45 and deleting files.
# This script may not be suitable for working with a large number of task log files and may require adjustments to work in batches.
$ErrorActionPreference = "Stop";
# Define working variables
$octopusURL = "http://YOUR_OCTOPUS_URL"
$octopusAPIKey = "API-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
$header = @{ "X-Octopus-ApiKey" = $octopusAPIKey }
$taskLogsFolder = "PATH\TO\TASKLOGS" # i.e. C:\Octopus\TaskLogs
# Get list of files
$regex = '^(servertasks)-(\d+)_([a-zA-Z0-9]+)\.(txt)$'
$taskLogs = Get-ChildItem -Path $taskLogsFolder -File | Where-Object { $_.Name -match $regex } | Select-Object -ExpandProperty Name
$taskIdNumbers = $taskLogs | ForEach-Object { if ($_ -match $regex) { $matches[2] } } | Sort-Object {[int]$_} -Unique
Write-Host "Found $($taskLogs.count) logs"
# Loop to find files that can be deleted
$tasksToDelete = @()
ForEach ($taskIdNumber in $taskIdNumbers) {
try {
Write-Host "Checking ServerTasks-$taskIdNumber"
$taskCheck = Invoke-RestMethod -Method Get -Uri "$octopusURL/api/tasks/ServerTasks-$taskIdNumber" -Headers $header
}
catch {
$response = $_.Exception.Response
if ($response.StatusCode -ieq "NotFound") {
$tasksToDelete += $taskIdNumber
Write-Host "Including ServerTasks-$taskIdNumber for task log deletion"
}
}
}
$filesToDelete = @()
ForEach ($task in $tasksToDelete) {
$list = $taskLogs | Where-Object { $_ -like "*$task*" }
ForEach ($item in $list) {
if ($filesToDelete -notcontains $item) {
$filesToDelete += $item
}
}
}
# Delete
ForEach ($file in $filesToDelete) {
# Remove-Item -Path "$taskLogsFolder\$file"
Write-Host "$taskLogsFolder\$file was deleted"
}