Search code examples
azure-devopsbackupdevopsazure-devops-rest-api

backup of Azure DevOps repositories


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.


Solution

  • 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:

    enter image description here

    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.