Last active
August 29, 2015 14:11
-
-
Save dennisroche/e1719ce43187a561730d to your computer and use it in GitHub Desktop.
Backup TeamCity
This file contains hidden or 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
| #TeamCityBackup | |
| #Requires –Version 4 | |
| #Requires -RunAsAdministrator | |
| Param | |
| ( | |
| [Parameter(Mandatory, HelpMessage="Team City installation directory, e.g. C:\TeamCity")] | |
| [ValidateNotNullOrEmpty()] | |
| [ValidateScript({ Test-Path $_ })] | |
| [String]$TeamCityInstallation = "C:\TeamCity", | |
| [Parameter(Mandatory, HelpMessage="Team City data directory, e.g. C:\ProgramData\JetBrains\TeamCity\")] | |
| [ValidateNotNullOrEmpty()] | |
| [ValidateScript({ Test-Path $_ })] | |
| [String]$TeamCityData = "C:\ProgramData\JetBrains\TeamCity\" | |
| ) | |
| # Supports TeamCity 6.x and above | |
| # http://confluence.jetbrains.com/display/TCD8/TeamCity+Data+Backup | |
| # Restoring a backup | |
| # http://confluence.jetbrains.com/display/TCD8/Restoring+TeamCity+Data+from+Backup | |
| $VerbosePreference = "Continue" | |
| $ErrorActionPreference = "Stop" | |
| trap { | |
| Pop-Location | |
| Write-Error $_ | |
| Exit 1 | |
| } | |
| $BinLocation = "$TeamCityInstallation\bin" | |
| $BackupLocation = "$TeamCityData\backup" | |
| If (Test-Path -Path $BackupLocation\*.zip) { | |
| Write-Host "Deleting previous backups" | |
| Get-ChildItem -Path $BackupLocation -Recurse -Include *.zip | % { $_.Delete() } | |
| } | |
| # First shutdown the Team City instance | |
| Write-Host "Shutdown TeamCity Server" | |
| Stop-Service -Name "TeamCity" -Verbose | |
| Try { | |
| # With the server offline, create a backup. | |
| Write-Host "Backup TeamCity configuration, database, and build logs" | |
| # http://confluence.jetbrains.com/display/TCD8/Creating+Backup+via+maintainDB+command-line+tool | |
| Push-Location $BinLocation | |
| & .\maintainDB.cmd backup --include-config --include-database | Write-Verbose | |
| Pop-Location | |
| If (-not (Test-Path -Path $BackupLocation\*.zip)) { | |
| Throw "No backup found in '$BackupLocation\*.zip'" | |
| } | |
| Write-Host "Backup complete." -ForegroundColor Green | |
| } Finally { | |
| # Restart | |
| Start-Service -Name "TeamCity" -Verbose | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment