azure devops repos backup

jihad majed 400 Reputation points
2024-10-01T10:35:43.8633333+00:00

How can I take backups for a code in Azure repos daily?

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
39,571 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Iheanacho Chukwu 1,020 Reputation points
    2024-10-01T23:42:01.6066667+00:00

    Please remember to "Accept Answer" if answer helped you. This will help us as well as others in the community who might be researching similar questions.

    Hello jihad majed,

    Thank you for posting this in Microsoft Q&A. 

    You can write a script, that clone and archive a repository and then stores the archive in your desired backup location, such as Azure Blob Storage, another repo, etc. This can be run as a cron job within Azure DevOps pipeline. Here is one example:

    trigger:
      branches:
        include:
          - main
    
    schedules:
      - cron: "0 2 * * *"
        branches:
          include:
            - main
        always: true
    
    pool: 
      name: 'linux-agent-pool'
    
    variables:
      BACKUP_PATH: "/tmp/repo_backup_$(Build.BuildId)"
      SERVICE_CONNECTION: "eng-lab-automation"
      STORAGE_ACCOUNT: "nachotestingsto"
      CONTAINER: "azure-repos"
    
    steps:
      - script: |
          rm -rf $(BACKUP_PATH)  # Remove the directory if it exists
          mkdir -p $(BACKUP_PATH)
          git clone $(Build.Repository.Uri) $(BACKUP_PATH)
          tar -czf $(BACKUP_PATH).tar.gz -C $(BACKUP_PATH) .
        displayName: 'Clone Repository and Create Backup Archive'
    
      - task: AzureCLI@2
        inputs:
          azureSubscription: $(SERVICE_CONNECTION)
          scriptType: 'bash'
          scriptLocation: 'inlineScript'
          inlineScript: |
            az storage blob upload --account-name $(STORAGE_ACCOUNT) --container-name $(CONTAINER) --name repo_backup_$(Build.SourceBranchName)_$(Build.BuildId).tar.gz --file $(BACKUP_PATH).tar.gz
        displayName: 'Upload Backup to Azure Blob Storage'
    

    Here we archive a repo and upload to an Azure Storage Account. See the sample pipeline run - https://dev.azure.com/nacho-chukwu/Infrastructure%20As%20A%20Code/_build/results?buildId=48&view=logs&j=12f1170f-54f2-53f3-20dd-22fc7dff55f9&t=78db2542-c627-4140-8a7a-d06178fff4e4

    User's image

    Alternatively, you may consider using third-party solutions that offer Azure DevOps backups, such as Commvault and Backrightup that offer backup solutions for Azure DevOps Repos.

    Thanks,
    Iheanacho

    2 people found this answer helpful.
    0 comments No comments

  2. SadiqhAhmed-MSFT 46,036 Reputation points Microsoft Employee
    2024-10-01T11:04:26.0133333+00:00

    @jihad majed Greetings!

    Currently, Azure DevOps is not supported on Microsoft Q&A. Please check this supported products list here (more to be added later on).

    However, the Azure DevOps team and community are active and answering questions on https://developercommunity.visualstudio.com/spaces/21/index.html Please post your question there and experts will guide you.

    You can also ask for help on Stack overflow: https://stackoverflow.com/questions/tagged/azure-devops or request for support here : https://azure.microsoft.com/en-us/support/devops/

    215816-image.png


    If the response helped, do "Accept Answer" and up-vote it

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.