Created
August 2, 2013 06:14
-
-
Save HowardvanRooijen/6137830 to your computer and use it in GitHub Desktop.
Originally by Ivan Leonenko: http://ileonenko.wordpress.com/2012/09/19/automatic-teamcity-backup-with-powershell/
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
function Execute-HTTPPostCommand() { | |
param( | |
[string] $url, | |
[string] $username, | |
[string] $password | |
) | |
$authInfo = $username + ":" + $password | |
$authInfo = [System.Convert]::ToBase64String([System.Text.Encoding]::Default.GetBytes($authInfo)) | |
$webRequest = [System.Net.WebRequest]::Create($url) | |
$webRequest.ContentType = "text/html" | |
$PostStr = [System.Text.Encoding]::Default.GetBytes("") | |
$webrequest.ContentLength = $PostStr.Length | |
$webRequest.Headers["Authorization"] = "Basic " + $authInfo | |
$webRequest.PreAuthenticate = $true | |
$webRequest.Method = "POST" | |
$requestStream = $webRequest.GetRequestStream() | |
$requestStream.Write($PostStr, 0, $PostStr.length) | |
$requestStream.Close() | |
[System.Net.WebResponse] $resp = $webRequest.GetResponse(); | |
$rs = $resp.GetResponseStream(); | |
[System.IO.StreamReader] $sr = New-Object System.IO.StreamReader -argumentList $rs; | |
[string] $results = $sr.ReadToEnd(); | |
return $results; | |
} | |
function Execute-TeamCityBackup() { | |
param( | |
[string] $server, | |
[string] $addTimestamp, | |
[string] $includeConfigs, | |
[string] $includeDatabase, | |
[string] $includeBuildLogs, | |
[string] $includePersonalChanges, | |
[string] $fileName, | |
[string] $userName, | |
[string] $password | |
) | |
$TeamCityURL = [System.String]::Format("{0}/httpAuth/app/rest/server/backup?addTimestamp={1}&includeConfigs={2}&includeDatabase={3}&includeBuildLogs={4}&includePersonalChanges={5}&fileName={6}", | |
$server, | |
$addTimestamp, | |
$includeConfigs, | |
$includeDatabase, | |
$includeBuildLogs, | |
$includePersonalChanges, | |
$fileName); | |
Execute-HTTPPostCommand $TeamCityURL $username $password | |
} | |
$server = "http://YOUR_SERVER" | |
$addTimestamp = $true | |
$includeConfigs = $true | |
$includeDatabase = $true | |
$includeBuildLogs = $true | |
$includePersonalChanges = $true | |
$fileName = "TeamCity_Backup_" | |
$username = "USERNAME" # Must be a TeamCity Admin | |
$password = "PASSWORD" | |
Execute-TeamCityBackup $server $addTimestamp $includeConfigs $includeDatabase $includeBuildLogs $includePersonalChanges $fileName $username $password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment