I am looking for the options to take a weekly backup of Azure DevOps repositories. Is this possible in Azure DevOps out of the box? If not what are the other alternatives.
-
Of course it's possible, but where do you want to store the backup ? – LoLance Jun 04 '20 at 02:24
-
@LanceLi-MSFT on azure storage. but as (this)[https://learn.microsoft.com/en-us/azure/devops/organizations/security/data-protection?view=azure-devops&viewFallbackFrom=azdevops#data-availability] says our data is replicated on multiple locations ,so do we really need to create a backup at own for DR. – amyy Jun 04 '20 at 06:41
-
1Actually I think the backup is not necessary cause your personal repos are protected well by Microsoft. But, a backup is never a bad idea in our life! So feel free to do that if you do want a backup somewhere, you can follow my answer to do what you want~ – LoLance Jun 04 '20 at 06:46
-
@LanceLi-MSFT I really appreciate your guidance and prompt reply.Thankyou – amyy Jun 04 '20 at 07:17
-
@LanceLi-MSFT can we automate this backup process to take scheduled backups???how? – amyy Jun 08 '20 at 08:39
-
1Set the `When to build` and disable the `Only schedule builds if ...`, can't it work? – LoLance Jun 08 '20 at 08:40
-
@LanceLi-MSFT what all the permissions i need to configure this. Currently I don't have any permission in Azure DevOps, and I need to tell my organization about all required permission. – amyy Jun 24 '20 at 12:39
-
1For step1: You need the permission to create and edit a pipeline. For step3: since you're trying to deploy to azure storage using Azure File copy task, you would need a service connection([ARM service connection](https://learn.microsoft.com/en-us/azure/devops/pipelines/library/connect-to-azure?view=azure-devops)). – LoLance Jun 25 '20 at 01:39
-
1The service connection would use some Azure permission (not azure devops!). So if you have Azure-related permission(same account in azure and azure devops) to access the service principle(which can access the storage), you can create it yourself. Or you can ask your admin to make a service connection for you and give your access to the service connection via `Service connection Security(You can easily find related docs online for this option)`. – LoLance Jun 25 '20 at 01:46
-
@LanceLi-MSFT thanks, I want to backup this in local machine not on Azure cloud, do wee need to download it everytime when build is ready or it will be automated ? – amyy Jun 25 '20 at 07:12
-
1If you use Publish build artifact task, you need to download it manually every week. (If you don't download it, it will be hosted in cloud, you can download it whenever you want. Be careful to avoid the pipeline run is [unvalid](https://learn.microsoft.com/en-us/azure/devops/pipelines/policies/retention?view=azure-devops&tabs=yaml#run-retention).) – LoLance Jun 25 '20 at 07:20
-
1Another direction for total automatically process: Assuming you're trying to download the file to machineA, then machineA should be running whenever the pipeline is triggered, right? So you can consider installing a self-agent in machineA, using Service mode!!! Then edit the pipeline to make it use the self-agent to run the pipeline. Now you can easily copy the backup to any folder(Use a copy task or cmd task with xcopy command instead of Publish build artifact task) in machineA when the pipeline is executed in machineA. – LoLance Jun 25 '20 at 07:35
-
@LanceLi-MSFT i am getting error for task ArchiveFiles@2, in rootFolderOrFile: i am not able to locate my repository folder here,please let me know the correct format – amyy Jul 29 '20 at 15:31
-
See [this](https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml), normally `$(System.DefaultWorkingDirectory)` represents the root folder of your repo. – LoLance Jul 30 '20 at 05:37
-
@LanceLi-MSFT yes i did the same but when I am selecting particular repo or particular folder,the its not working , – amyy Jul 31 '20 at 09:37
-
Build or release pipeline? One repo or multiple repos used in your pipeline? I normally add cmd task that calls `dir` command(windows) / `ls` command(linux) to help us list the folders. – LoLance Jul 31 '20 at 09:42
-
@LanceLi-MSFT build pileline,and single repo – amyy Jul 31 '20 at 15:02
-
Got it, see my another post [here](https://stackoverflow.com/a/61949323/10910450). Normally if that's a github repo, your input should be `rootFolderOrFile: '$(System.DefaultWorkingDirectory)/{RepoName}.git', it's because the mirror file would be placed in a newly created repoName.git folder.(And this folder normally exists in default working directory). ` – LoLance Aug 03 '20 at 03:17
-
If this still can't help, edit your question to share the details about your yaml/classic pipeline, so that I can check for you directly. – LoLance Aug 03 '20 at 03:18
1 Answers
All you need to do is to create a pipeline scheduled every week. Steps to make the backup:
1.Check Configure schedules for pipelines , I suggest you can create a classic build pipeline which will be scheduled on One day in a week:
Enable the Only schedule builds if the source or pipeline has changed
if you want to do the backup only when the source repo is changed.
2.The first task of your pipeline can be a CMD task with content: git clone --mirror https://{Your PAT}@dev.azure.com/{OrgName}/{ProjectName}/_git/{RepoName}
Then you can use an ArchiveFiles task to zip the backup into a Backup.zip
file.
More details about this part you can check my another post here. (Also you can name the backup.zip with buildId, using this $(Build.ArtifactStagingDirectory)/Backup-$(Build.BuildId).zip
in archiveFile
input)
3.After that you need a final task to store the Backup.zip
/Backup-$(Build.BuildId).zip
file.
If you want to store the backup in Azure Storage, you can use AzureFileCopy
task. (Similar scenario like above link~)
If you want to store the backup in local machine, you can use Publish Build Artifact
task to publish the Artifact. Then you can download it in local machine whenever the build is valid.
You can also create a github private repo to store the backups, every time in the end of the pipeline commit the new Backup.zip to github repo. (Use CMD task with git commands.)
In addition: See Azure DevOps Repos synchronization between Organization, you have another direction. Not backup, but synchronize Azure DevOps Repos and Github repo.

- 25,666
- 1
- 39
- 73