Azure CLI Image Copy Extension – allows you to copy virtual machine images between regions with just one command.


imageThis is an extension to azure cli that allows copying virtual machine images between regions with just one command.

The extension simplifies the process and also enables you to save time by copying to multiple regions in parallel. This is now becoming a question I am getting a lot from UK Academics who now wish to move existing Azure resources to the UK Azure Data Center

How to use

Step1. You need Azure Command Line Interface Installed

Step 2. Install Azure CLI

see https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest 

Install on macOS

On macOS, you are able to install either with Homebrew or manually.

Install with Homebrew
  1. If you don't have it already, install Homebrew by following the Homebrew installation instructions.

  2. If you have previously installed the CLI manually, follow the manual uninstall instructions.

  3. Update your local Homebrew repositories.

    bashCopy

    brew update
    
  4. Install the azure-cli package.

    bashCopy

    brew install azure-cli
    

Note

If you previously installed the Azure CLI 1.0 with Homebrew, instead of installing the package you can get CLI 2.0 through the regular Homebrew upgrade process.

bashCopy

brew upgrade
Install manually
  1. Install Azure CLI 2.0 with curl.

    bashCopy

    curl -L https://aka.ms/InstallAzureCli | bash
    
  2. You may have to restart your shell for some changes to take effect.

    bashCopy

    exec -l $SHELL
    
  3. Run the CLI from the command prompt with the az command.

Install on Windows

Install with MSI for the Windows command-line

To install the CLI on Windows and use it in the Windows command-line, download and run the Azure CLI Installer (MSI).

Install with apt-get for Bash on Ubuntu on Windows
  1. If you don't have Bash on Windows, install it.

  2. Open the Bash shell.

  3. Modify your sources list.

    bashCopy

    echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" | \
         sudo tee /etc/apt/sources.list.d/azure-cli.list
    
  4. Run the following sudo commands:

    bashCopy

    sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 52E16F86FEE04B979B07E28DB02C46DF417A0893 sudo apt-get install apt-transport-https sudo apt-get update && sudo apt-get install azure-cli

  5. Run the CLI from the command prompt with the az command

image

Step 3. Install the Extension

First, install the extension:

az extension add --name image-copy-extension

image

Step4, Run the Extension command

Then, call it as you would any other az command:

az image copy --source-resource-group mySources-rg --source-object-name myImage --target-location uksouth northeurope --target-resource-group "images-repo-rg" --cleanup

One thing you should keep in mind is that we are relying on the source os disk as the actual source for the copy. So, when you "capture" a new image off a vm in Azure, don't delete the os disk if your intention is to copy it to other regions.

Other options and examples of using the extensions can be viewed with the help command:

az image copy --help

Opensource

This extension is also available at https://github.com/Azure/azure-cli-extensions/tree/master/src/image-copy so if your interested in building out your own extensions.

Comments (4)

  1. Dave Rendón says:

    Thanks Lee, will this work also for Gov Regions?

    1. Lee Stott says:

      Yes this should work as its simply Azure CLI commands.

  2. flame brk says:

    we try to copy vm image from westeurope to southeastasia:
    seems, this going extremly slow, after half of a hour we have just 0,2%:
    southeastasia – Copying blob to target storage account
    southeastasia – Copy progress: 0.0%
    southeastasia – Copy progress: 0.1%
    southeastasia – Copy progress: 0.2%
    it is by design, or we misunderstand something?

    1. Lee Stott says:

      Hi Flame brk

      Have you tried copying the file from a different network? We have seen some issues with poor performance due to Campus firewalling when people have tried from another ISP the copying of the file has been fine.

Skip to main content