Shai Katz
Shai Katz

Reputation: 1863

TeamCity messages folder growth

My teamcity server diskspace is running very low. The main growing folder is the "Messages" folder and i'm wonder how i can define the clean-up policy to delete old logs from the messages folder.

Currently my clean-up rule looks like that:

History more than 15 days older than the last build and older than the 50th successful build
Artifacts more than 2 days older than the last build and older than the 10th successful build; artifact patterns: +:\\**\\*
Other items are kept forever
Do not prevent dependency artifacts cleanup 

Upvotes: 1

Views: 1216

Answers (2)

Martin Basista
Martin Basista

Reputation: 124

Might be far from the most efficient solution, but this is my powershell script that goes through the Message folder and deletes all the index (.i1) files that do not have corresponding message (.msg5). Takes a bit of time, but if you schedule it on sunday job in TC, you don`t have to worry about oweflowing Message folder ever again. Using TeamCity against it.

[CmdletBinding()]
param (
    [Parameter()]
    [string]$messageFolder = "G:\TeamCity\Data\system\messages"
)

function HasNoMessage {
    param([System.IO.FileInfo]$indexFile)

    foreach ($message in $messages)
    {
        if ($indexFile.Name.Contains($message.name))
        {
            return $false
        }
    }
    return $true
}

$folders = Get-ChildItem $messageFolder -Recurse | ?{ $_.PSIsContainer }
$count = 0
$totalSize = 0
$preserved = 0

foreach ($folder in $folders)
{
    $table = Get-ChildItem $folder.FullName -include *.i1 -recurse 
    $messages = Get-ChildItem $folder.FullName -include *.msg5 -recurse
    foreach ($index in $table)
    {
        if (HasNoMessage($index))
        {
            $count++
            $totalSize += $index.Length
            remove-item $index.FullName 
        }
        else {$preserved++}
    }
} 
Write-Output("Finished : total files removed : ", $count)
Write-Output("Total size cleaned in MegaBytes : ", ($totalSize / 1MB))
Write-Output("Preserved files : ",  $preserved) 

UPDATE : The new TeamCity version 9.x already has this taken care of so I strongly recomend to migrate

Upvotes: 2

BrokenGlass
BrokenGlass

Reputation: 160992

If you are running TeamCity 8 or older then there is a known issue that the messages folder is not cleaned correctly, check out the following links for workarounds (basically manually deleting the files that are not used anymore):

https://devnet.jetbrains.com/message/5518176#5518176

https://youtrack.jetbrains.com/issue/TW-36830#comment=27-754144

Upvotes: 3

Related Questions