Azure CLI Image Copy Extension – allows you to copy virtual machine images between regions with just one command.
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 macOSOn macOS, you are able to install either with Homebrew or manually.
Install with Homebrew-
If you don't have it already, install Homebrew by following the Homebrew installation instructions .
-
If you have previously installed the CLI manually, follow the manual uninstall instructions.
-
Update your local Homebrew repositories.
bashCopy
brew update
-
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
-
Install Azure CLI 2.0 with
curl
.bashCopy
curl -L https://aka.ms/InstallAzureCli | bash
-
You may have to restart your shell for some changes to take effect.
bashCopy
exec -l $SHELL
-
Run the CLI from the command prompt with the
az
command.
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-
If you don't have Bash on Windows, install it .
-
Open the Bash shell.
-
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
-
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
-
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.