Automate team city backup

Use this simple build configuration to backup your team city data

Mon, 12 Jun 2023

Oddly enough, TeamCity does not have an automated backup process like Youtrack does. My best guess is that maybe it has something to do with the fact that TeamCity uses an external DB while Youtrack doesn’t. Not sure, here is a method I came up with to do a weekly backup

While there isn’t a built in automatic backup method, Jetbrains did provide us with a nice API that we can hit to start a backup. The API is easy to use and we only need to make 3 changes to a blank build configuration

  1. Create a new build configuration. I made a project under my root project named Backups and then a build configuration named TeamCity
  2. Go to triggers and select Schedule Trigger in the dropdown. Mine is set to go off every Sunday at 12am

Build Command

For this to work you need to do a little bit of research. Here is the official documation for the API command https://www.jetbrains.com/help/teamcity/rest/manage-data-backup.html#Start+Backup.

What you need to do is decide on the name of the file and what you want to backup. I personally wanted to backup the database, build logs and config. I also chose the name TeamCity_Backup. What that looks like is this

https://YourTeamCityAddress.com/app/rest/server/backup?includeConfigs=true&includeDatabase=true&includeBuildLogs=true&fileName=TeamCity_Backup.zip

If you wanted to copy my config, just change out YourTeamCityAddress.com for your web address

Once thats done you want to do enter this build command

curl --header "Authorization: Bearer %API_KEY%" -X POST 'https://YourTeamCityAddress.com/app/rest/server/backup?includeConfigs=true&includeDatabase=true&includeBuildLogs=true&fileName=TeamCity_Backup.zip'

You need curl for this to work, if you have a linux or mac machine you should have it already. As for windows you can use the curl image. My build agents consist of 2 mac agents and 1 windows agent so I opt to use the curl image so any of the 3 agents can run the build. Under Run steps within Container section put in the official curl container: curlimages/curl and set the image platform to linux.

The last piece is the API key, under parameters there should be a spot for you to enter in an API key now. To generate one do the following

Profile -> Access Tokens -> Create Key

Once you create a key add it back to this build configuration and you’re all set!

Buy Me A CoffeeDigitalOcean Referral Badge
Loading...
Edward Beazer

Edward Beazer - I just like to build shit. Sometimes I get stuck for hours, even days while trying to figure out how to solve an issue or implement a new feature. Hope my tips and tutorials can save you some time.

DigitalOcean Referral Badge