Azure devops formerly known as visual studio team service is a SAAS for devops. It is a good practice to back up the source code regularly or even, it may be required by the company. However, there is no out of box solution according to microsoft.
Although Microsoft does commit to keep data safe:
- azure devops data is saved at azure storage and azure sql, both are backed up in 2 regions in the same geography.
- azure devops offers a 99.9% uptime SLA guarantee.
But we have no control over the backup mentioned above. Here I recommend several ways to do the backup:
- use Backrightup and integrate using its plugin into azure devops. Very easy and it can backup not only source code but also pipelines. Good service good price. The cost is per repo, therefore if you have many repositories, the price might be high.
- use cron job on vm use
git clone
to copy the repo. The drawback is that every time when there is a new repo, you have to change the cron job. - use azure devops rest api to programmably backup the source code.
Option 1 and 2 are pretty obvious. Let us check how we could backup the repo based on the third option.
This solution is based on python, so that it could be used in either windows or linux environment.
- go to right upper corner click personal access tokens.
- specify required fields in following picture to create a pat and copy it. (make sure the pat has code reading right)
The source code could be found at here at github. Clone it and replace the organization and PAT with your own data.
The code uses azure devops rest api to get project list and then all repos url based on project list. At last, the code calls git cmd to clone the repo.
Depending on ur environment, you could run the backup code in windows as a scheduler job or in linux as cron job. Or you could even run it as function app in azure.