'How to import all images from an ACR repository to another ACR in different tenant

Scenario: I have 4 repos in an ACR(azure container registry) with multiple images in each repo. I want to move all the repos and all images in it to a different ACR(azure container registry) What I have Done: I have used below command to import a single image in an ACR(azure container registry) repo to another ACR repo.

az acr import \
  --name myregistry \
  --source sourceregistry.azurecr.io/sourcerrepo:tag \
  --image targetimage:tag \
  --username <SP_App_ID> \
  --password <SP_Passwd>

Problem: The above command only imports a single image based on the tag given.

Solution Needed: What I want to achieve is to import all the image inside a single repo of an ACR to a different ACR.

Please let me know if anyone have any solution for this.



Solution 1:[1]

Whipped up this script using pwsh and az cli:

$SourceAcrName="source ACR Name"
$DestinationAcrName="destination ACR Name"

$Repos= az acr repository list --name $SourceAcrName | ConvertFrom-Json

foreach ($repo in $Repos) {
    $Tags = az acr repository show-tags -n $SourceAcrName --repository $repo | ConvertFrom-Json
    foreach ($tag in $Tags) {
        az acr import -r $SourceAcrName -n $DestinationAcrName --source "${repo}:${tag}" --no-wait
    }
}

It will copy all repositories and tags in the ACR to the destination ACR. the --no-wait parameter allows the tasks to run in the background in Azure, so you don't have to wait for confirmation.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Maraudingas