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.
On this page
Methods for Copying Blobs
Azure Storage provides flexible options for copying blobs, catering to different scenarios:
- REST API: The fundamental method, accessible via SDKs or direct HTTP requests.
- Azure CLI: A command-line interface for managing Azure resources.
- Azure PowerShell: A scripting environment for managing Azure resources.
- Azure Storage Explorer: A cross-platform GUI tool for managing storage resources.
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
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.
Performance Considerations
Several factors can influence the performance of blob copy operations:
- Network Bandwidth: For cross-account or URL copies, the bandwidth between the source and Azure is a key factor.
- Storage Account Throughput: The target storage account's performance tier (Standard vs. Premium) and configured throughput limits can impact copy speed.
- Blob Size: Larger blobs naturally take longer to copy.
- Concurrency: Performing multiple copy operations concurrently can improve overall throughput, but individual operations might take longer.
For best performance, ensure your source and destination storage accounts are in the same region where possible, especially for cross-account copies.
Copy Status property of the destination blob.