First of all, Ensure that the user which will be running this call has the Change backup settings and control backup process
privilege.
#
# TC Backup Launcher
# Script to launch a backup on the TeamCity Server
#
Param(
[Parameter(Mandatory=$true)][string]$username,
[Parameter(Mandatory=$true)][string]$password
)
Begin
{
$url = "http://teamcity:8111/httpAuth/app/rest/server/backup?includeConfigs=true&includeDatabase=true&includeBuildLogs=false&fileName=TeamCity_Backup"
$username = <username>
$password = <password>
# Function to realize a POST Operation
function Execute-HTTPPostCommand() {
param(
[string] $target = $null
)
$request = [System.Net.WebRequest]::Create($target)
Write-Host "POST: " $request.RequestUri
$request.PreAuthenticate = $true
$request.Method = "POST"
$request.ContentType = "application/xml"
$request.Headers.Add("AUTHORIZATION", "Basic");
$request.Accept = "*"
$request.Credentials = New-Object System.Net.NetworkCredential($username, $password)
$response = $request.GetResponse()
$xmlout = ""
if($response)
{
$sr = [Io.StreamReader]($response.GetResponseStream())
$xmlout = $sr.ReadToEnd()
}
return $xmlout;
}
Write-Host "Creating a new Backup:"
Execute-HTTPPostCommand $url
}
The important part is the URL to call with method POST :
You can specify the settings you want to backup as in the web interface.