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
- Create a new build configuration. I made a project under my root project named Backups and then a build configuration named TeamCity
- Go to triggers and select
Schedule Triggerin the dropdown. Mine is set to go off every Sunday at 12am
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
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!