Blog Post

Educator Developer Blog
3 MIN READ

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

Lee_Stott's avatar
Lee_Stott
Icon for Microsoft rankMicrosoft
Mar 21, 2019
First published on MSDN on Jan 18, 2018

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

Step 3. Install the Extension

First, install the extension:

az extension add --name image-copy-extension

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.

Updated Mar 21, 2019
Version 2.0
  • rchoudhari's avatar
    rchoudhari
    Copper Contributor

    The side effect of this command is , it create snapshot with public access which might not be a good case. Please eliminate that piece and this command will become a legend 🙂