Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build server database cleanup script
- Loading branch information
1 parent
c1cfa7b
commit 2020f81
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |