Backup your Team Services Git Repositories with VSTS Vault: A simple windows service or console application designed to keep a local copy of all your code.

Since January 2016 we’ve moved the source code of more than 30 projects to Git repositories hosted by Visual Studio Team Services.

Moving to the cloud has some downsides and one thing that kept us thinking was the need to be sure that in the event of an internet connection failure or a Team Services outage we would be able to access our code and deploy hot fixes for our applications as part of our data protection plan.

Surfing on the web I found this post: Free Visual studio online backup tool that talks about VSOBackup a free tool to create backups of your code by dates.

We needed a solution capable of minimizing the RPO (Recovery Point Objetive) and where the backups could be connected to an on-premises Git Server such as GitBlit.

Those are the main reason we could not use VSOBackup and why, inspired by such a great code base, I created a Windows service: VSTS.Vault with the capability of cloning your Git repositories and then pulling for changes every 5 minutes which is the default setting.

Vsts.Vault is a Windows Service and to use it you’ll need to follow these steps:

Create Alternate Credentials for your Visual Studio Team Services Account


If you haven’t setup alternate credentials for your Visual Studio Team Services Account follow the instructions of the Alternate Access Credentials section of the following doc: Client Authentication Options

Configure VSTS.Vault Settings


Modify as needed the following parameters in the Vsts.Vault.exe.config file

 1   <applicationSettings>
 2    <Vsts.Vault.WindowsService.Properties.Settings>
 3      <setting name="BackupInterval" serializeAs="String">
 4        <value>300000</value>
 5      </setting>
 6      <setting name="ServiceName" serializeAs="String">
 7        <value>Vsts.Vault</value>
 8      </setting>
 9    </Vsts.Vault.WindowsService.Properties.Settings>
10  </applicationSettings>
11 
12  <VaultConfiguration
13    Username="[User name as specified in your Team Services Alternate Authentication Credentials]"
14    UserEmail="[An email required just required by Git pull through LibGit2Sharp]"
15    Password="[Password as specified in your Team Services Alternate Authentication Credentials]"
16    Account="[The name of your Team Services account (Not the full Url)]"
17    TargetFolder="[Full path of the folder where the copy of your repositories will live]" />

Install the VSTS.Vault service


Run the following command

If you look through the VSTS.Vault code base you’ll see some interesting features:

  1. Use of MEF as to implement dependency injection
  2. Use of LibGit2Sharp
  3. Use of Visual Studio Team Services REST API
  4. And the use of the Retry Pattern

To finish this post I have to say that We’ve been running the service now for more than a month and connected the resulting repository backups to GitBlit without issues.

Hope it helps!