Copy Blobs in Azure Storage

This document outlines the various methods for copying blobs within Azure Storage, including copying within the same storage account, across different storage accounts, and from other cloud providers.

Methods for Copying Blobs

Azure Storage provides flexible options for copying blobs, catering to different scenarios:

Copying within the Same Storage Account

Copying a blob within the same storage account is an efficient operation. The source and destination blobs can be in the same or different containers. Azure Storage handles this operation server-side, meaning no data is transferred over the network from the client.

Using Azure CLI

The az storage blob copy start command is used to initiate a blob copy operation. You'll need the source and destination container and blob names, and the storage account name.


az storage blob copy start \
    --account-name  \
    --source-container  \
    --source-blob  \
    --destination-container  \
    --destination-blob  \
    --auth-mode login
            

Using Azure PowerShell

The Start-AzStorageBlobCopy cmdlet performs the copy operation.


$ctx = New-AzStorageContext -StorageAccountName ""
$source = Get-AzStorageBlob -Container "" -Blob "" -Context $ctx
Start-AzStorageBlobCopy -Context $ctx -SrcBlob $source.Name -SrcContainer "" -DestBlob "" -DestContainer ""
            

Copying Across Storage Accounts

Copying a blob between different Azure Storage accounts is also a server-side operation. This is useful for data migration or replication.

Using Azure CLI

For cross-account copies, you'll need to authenticate to both source and destination accounts.


az storage blob copy start \
    --source-account-name  \
    --source-container  \
    --source-blob  \
    --destination-account-name  \
    --destination-container  \
    --destination-blob  \
    --auth-mode login
            

Using Azure PowerShell

Create separate contexts for source and destination accounts.


$sourceContext = New-AzStorageContext -StorageAccountName "" -StorageAccountKey ""
$destContext = New-AzStorageContext -StorageAccountName "" -StorageAccountKey ""

$sourceBlob = Get-AzStorageBlob -Container "" -Blob "" -Context $sourceContext
Start-AzStorageBlobCopy -Context $destContext -SrcBlob $sourceBlob.Name -SrcContainer "" -DestBlob "" -DestContainer ""
            

Copying from a URL

You can copy a blob from a publicly accessible URL or a SAS-authenticated URL directly into your Azure Storage account. This is very efficient as it bypasses client-side downloads.

Using Azure CLI

The --source-uri parameter is used for this purpose.


az storage blob copy start \
    --account-name  \
    --destination-container  \
    --destination-blob  \
    --source-uri "" \
    --auth-mode login
            
Tip: If the source URI is private, ensure you include a Shared Access Signature (SAS) in the URI to grant temporary access.

Using REST API

The PUT Blob operation with the x-ms-copy-source header can be used.


PUT /{destination-container-name}/{destination-blob-name} HTTP/1.1
x-ms-version: 2019-02-02
x-ms-copy-source: /{source-storage-account-name}/{source-container-name}/{source-blob-name}
Content-Length: 0
Authorization: SharedKey {your-storage-account-name}:{your-storage-account-key}
Date: {current-date-time}

Copying from Other Cloud Providers

To copy data from other cloud providers (like Amazon S3 or Google Cloud Storage), you can use the "Copy from URL" method. First, export the data from the source cloud to a publicly accessible URL or a SAS-protected URL, and then use the Azure Storage copy functionality.

Note: For large-scale migrations from other cloud providers, consider using tools like Azure Data Factory or Azure Migrate which offer more robust and managed solutions.

Performance Considerations

Several factors can influence the performance of blob copy operations:

For best performance, ensure your source and destination storage accounts are in the same region where possible, especially for cross-account copies.

Tip: You can monitor the progress of copy operations by checking the Copy Status property of the destination blob.
View Blob REST API Reference Get Started with Azure CLI Learn Azure PowerShell