Backup your Team Services Git Repositories with VSTS Vault
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:
1. 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
2. Configure VSTS.Vault Settings
Modify as needed the following parameters in the Vsts.Vault.exe.config file
<applicationSettings> <Vsts.Vault.WindowsService.Properties.Settings> <setting name="BackupInterval" serializeAs="String"> <value>300000</value> </setting> <setting name="ServiceName" serializeAs="String"> <value>Vsts.Vault</value> </setting> </Vsts.Vault.WindowsService.Properties.Settings> </applicationSettings> <VaultConfiguration Username="[User name as specified in your Team Services Alternate Authentication Credentials]" UserEmail="[An email required just required by Git pull through LibGit2Sharp]" Password="[Password as specified in your Team Services Alternate Authentication Credentials]" Account="[The name of your Team Services account (Not the full Url)]" TargetFolder="[Full path of the folder where the copy of your repositories will live]" />
3. Install the VSTS.Vault service
Run the following command
If you look through the VSTS.Vault code base you’ll see some interesting features:
- Use of MEF as to implement dependency injection
- Use of LibGit2Sharp
- Use of Visual Studio Team Services REST API
- 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!