首页 > 解决方案 > TeamCity 按计划备份并复制到 Azure,REST 脚本改进

问题描述

我正在编写一个脚本来按计划运行 TeamCity 备份,因为默认情况下它没有这样的选项,然后将其复制到 Azure 存储帐户。

该脚本正在运行,但我想做一些改进。

  1. 我希望 Powershell 检查备份文件的可用性以供下载(Test-Path 等)。现在,它只需要休眠 360 秒。
  2. 我想在 Azure 存储帐户上配置保留策略。
#API key for TeamCity as TC parameter
$key = "%key%"

$date = Get-Date -Format "yyyy-MM-dd"

$file = "TeamCity-Backup-$date.zip"

#URI for initialize backup
$uri = "https://teamcity.test.com/app/rest/server/backup?addTimestamp=false&includeConfigs=true&includeDatabase=true&includeBuildLogs=false&fileName=$file"


#URI for downloading backup
$uri1 = "https://teamcity.test.com/get/file/backup/$file"

 $header = @{  "Authorization"="Bearer $key"  }

#Initialize
Invoke-RestMethod -Method Post -Uri $uri -Header $header   

#Wait for backup
sleep -Seconds 360

#
#Need function or method for checking file availibility
#

#Download
Invoke-RestMethod -Method Get -Uri $uri1 -Header $header -OutFile "$file"

#Key to BLOB
$key_storage = "%key_storage%"

#Copy to Azure
azcopy.exe copy $file "https://myblob.blob.core.windows.net/teamcity-backups$key_storage"

#
#Funtion for retention Azure Blob
#

标签: azurepowershellteamcity

解决方案


推荐阅读