Skip to content

Commit

Permalink
Build server database cleanup script
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBoike committed May 13, 2016
1 parent c1cfa7b commit 2020f81
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions utils/CleanDatabases.ps1
@@ -0,0 +1,26 @@
$DatabaseUrl = "http://localhost:8083"
$DatabasePath = "C:\RavenDBv3\Data"
$WaitMinutes = 0
$ignore = @( "system", "databases" )

function TC-Write([string]$name) {
Write-Output "##teamcity[message text='$name']"
}

TC-Write "Running RavenDB Database Cleaner"
TC-Write "RavenDB URL: $DatabaseUrl"
TC-Write "RavenDB Data Path: $DatabasePath"

$databases = Get-ChildItem $DatabasePath -Directory `
| Where-Object { $ignore -notcontains $_.Name } `
| Where-Object { $_.CreationTimeUtc -lt (([DateTime]::UtcNow).AddMinutes(-$WaitMinutes)) }


foreach($database in $databases) {
TC-Write "Deleting $database"
$deleteUrl = "$($DatabaseUrl)/admin/databases/$([Uri]::EscapeDataString($database.Name))?hard-delete=true"
TC-Write "DELETE $deleteUrl"
Invoke-RestMethod $deleteUrl -Method Delete
}

Write-Host Completed

0 comments on commit 2020f81

Please sign in to comment.