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