我们正在使用Teamcity 6.5.6专业版,它提供了备份选项,但我没有看到任何安排备份运行时间的选项。
我不确定这个版本的Teamcity是否支持定期备份。如果无法通过Teamcity GUI实现,请问是否有其他选项可用?
请问是否可以帮忙解决问题?
谢谢。
我不确定这个版本的Teamcity是否支持定期备份。如果无法通过Teamcity GUI实现,请问是否有其他选项可用?
请问是否可以帮忙解决问题?
谢谢。
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
)
$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 "USER" "PASSWORD"
}
$server = "http://YOUR_SERVER"
$addTimestamp = $true
$includeConfigs = $true
$includeDatabase = $true
$includeBuildLogs = $true
$includePersonalChanges = $true
$fileName = "TeamCity_Backup_"
Execute-TeamCityBackup $server $addTimestamp $includeConfigs $includeDatabase $includeBuildLogs $includePersonalChanges $fileName
您可以使用REST API来运行备份。我们实际上使用TeamCity在每天的午夜运行预定构建。该构建会调用rest api来执行备份。
如果您不想编写程序来执行您的任务,只需运行此命令:
wget --user=*** --password=*** "http://localhost:8085/httpAuth/app/rest/server/backup?includeConfigs=true&includeDatabase=true&includeBuildLogs=true&fileName=ScheduledBackup-" --post-data=
将星号替换为您的TeamCity登录信息。
在Windows上,您可以通过安装Cygwin软件包来获取WGET。
wget
也包含在unxutils中。获取unxutils.zip和unxupdates.zip; 解压缩工具,解压缩更新,将更新移动到unxutils的usr/local/wbin
文件夹中,然后在$PATH上注册它。 - Damon对于那些希望从Mac OS触发构建的人(在TeamCity上使用“命令行”运行程序):
curl --basic --user user:password -X POST "http://team.city.server:8111/httpAuth/app/rest/server/backup?includeConfigs=true&includeDatabase=true&includeBuildLogs=true&fileName=ScheduledBackup"
curl
应该是任何操作系统上的选项。在 Windows 上,您可以通过 msysgit 获取它,该工具使用 MinGW (http://www.mingw.org/),如果您让它为所有命令提示符安装 Git 命令,则使其成为每个人的候选。另外,根据手册,curl
默认为基本身份验证模式,因此,如果保持命令简单,则可能可以删除 --basic
。YMMV 因此请在您的操作系统上进行测试。 - Damoncurl --basic --user user:pasword -X POST "%teamcity.serverUrl%/httpAuth/app/rest/server/backup?includeConfigs=true&includeDatabase=true&includeBuildLogs=true&fileName=ScheduledBackup"
从@Ivan Leonenko的脚本开始,我添加了一些代码行以等待备份结束后再退出。
function Execute-HTTPCommand() {
param(
[string] $method,
[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 = $method
if ($method -ne "GET")
{
$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);
Write-Host "Starting TeamCity backup"
Execute-HTTPCommand "POST" $TeamCityURL $username $password
}
function Wait-TeamCityBackup() {
param(
[string] $server,
[string] $username,
[string] $password
)
$GetBackupStatusUrl = [System.String]::Format("{0}/httpAuth/app/rest/server/backup",
$server);
do {
Start-Sleep -Seconds 1
$backupStatus = Execute-HTTPCommand "GET" $GetBackupStatusUrl $username $password
Write-Host $backupStatus
} while ($backupStatus -eq 'Running')
}
$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
Wait-TeamCityBackup $server $username $password