Click here to Skip to main content
15,887,214 members
Articles / Programming Languages / C#
Tip/Trick

Backing up a TeamCity server

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
5 Mar 2016Apache2 min read 8.3K   2  
A tool helping you to backup all your TeamCity projects and their settings.

The elevator pitch

If you are using TeamCity from JetBrains, are you sure that you continuously are backing up all your projects and their settings?

If not, perhaps I can help you?

What if I told you that you can run the backup process as any other project within TeamCity. By dogfooding the backup to TeamCity, all information is kept within the same system, and the backup history is as clearly visualized as your continuous deliveries.

Pretty smart huh?

GitHub

The source code can be found in the GitHub project TeamCity Backup.

Configuration

I've created a small console application that is capable of triggering TeamCity to perform a backup by means of using the official REST API.

Lets take a look at the options you have for performing a backup.

C:\>TeamCityBackup.exe /?
TeamCity Backup  version 1.0.3.0
Copyright FantasticFiasco 2014-2016

Usage:
   TeamCityBackup /server=url /username=value /password=value
     [/filename=file] [/addtimestamp=true|false]
     [/includeconfigs=true|false] [/includedatabase=true|false]
     [/includebuildlogs=true|false] [/includepersonalchanges=true|false]

Options:
   /?, /h, /help                Displays this help text.
   /addtimestamp                Whether backup file name should be suffixed
                                with a timestamp. Default value is true.
   /filename, /f                The prefix of the backup file name.
                                The default value is 'TeamCity_Backup'.
   /includebuildlogs            Whether to include build
                                logs. Default value is true.
   /includeconfigs              Whether to include configuration.
                                Default value is true.
   /includedatabase             Whether to include database.
                                Default value is true.
   /includepersonalchanges      Whether to include personal
                                changes. Default value is true.
   /password, /p                The password of a TeamCity administrator.
   /server, /s                  The address of the TeamCity server.
   /username, /u                The username of a TeamCity administrator.

Out of these options only three are mandatory:

  • server - The address of the TeamCity server
  • username - The username of a TeamCity administrator
  • password - The password of a TeamCity administrator

Basic example

This command would perform a backup of a TeamCity server located on www.myteamcityserver.com using the credentials of the TeamCity administrator teamcity_user.

C:\>TeamCityBackup.exe /server=www.myteamcityserver.com /username=teamcity_user /password=password

Setting up a TeamCity project

The following steps describe how one would create a TeamCity project with the responsibility to backup the TeamCity server once every week. It assumes that you are willing to fork the GitHub repository. If you aren't, you can download the latest release, check it into your version control system and adapt the steps to your new scenario.

  1. Fork this GitHub repository.
  2. Create a new TeamCity project and name it TeamCity Backup.
  3. Add a VCS root that points to your forked GitHub repository.
  4. Add a scheduled trigger that is configured to occur once a week.
  5. Add a Visual Studio (sln) build step with the following configuration:
    • Solution file path: src/TeamCityBackup.sln
    • Targets: Rebuild
    • Configuration: Release
  6. Add a Command Line build step with the following configuration:
    • Command executable: src/TeamCityBackup/bin/Release/TeamCityBackup.exe
    • Command parameters: /server=www.myteamcityserver.com /username=teamcity_user /password=password

That's it! You now have a working backup solution that will backup your TeamCity server once a week.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Software Developer Axis Communications
Sweden Sweden
Got my first computer in the 90's and loved it even though it sounded like a coffeemaker.

Now getting paid for designing cool applications, and drinks the coffee instead of listening to it being made.

Comments and Discussions

 
-- There are no messages in this forum --