使用 AzCopy v10 在 Azure 存储帐户之间复制 BlobCopy blobs between Azure storage accounts by using AzCopy v10

可以使用 AzCopy v10 命令行实用程序在存储帐户之间复制 Blob、目录和容器。You can copy blobs, directories, and containers between storage accounts by using the AzCopy v10 command-line utility.

若要查看其他类型任务(如上传文件、下载 Blob 以及与 Blob 存储同步)的示例,请参阅本文的后续步骤部分中提供的链接。To see examples for other types of tasks such as uploading files, downloading blobs, and synchronizing with Blob storage, see the links presented in the Next Steps section of this article.

AzCopy 使用服务器到服务器 API,因此,数据会直接在存储服务器之间复制。AzCopy uses server-to-server APIs, so data is copied directly between storage servers. 这些复制操作不会占用计算机的网络带宽。These copy operations don't use the network bandwidth of your computer.

若要下载 AzCopy 并了解如何向存储服务提供授权凭据,请参阅 AzCopy 入门To download AzCopy and learn about the ways that you can provide authorization credentials to the storage service, see Get started with AzCopy.

指南Guidelines

将以下指南应用于 AzCopy 命令。Apply the following guidelines to your AzCopy commands.

  • 客户端必须具有对源和目标存储帐户的网络访问权限。Your client must have network access to both the source and destination storage accounts. 若要了解如何配置每个存储帐户的网络设置,请参阅配置 Azure 存储防火墙和虚拟网络To learn how to configure the network settings for each storage account, see Configure Azure Storage firewalls and virtual networks.

  • 将 SAS 令牌追加到每个源 URL。Append a SAS token to each source URL.

    如果使用 Azure Active Directory (Azure AD) 提供授权凭据,则只能从目标 URL 中省略 SAS 令牌。If you provide authorization credentials by using Azure Active Directory (Azure AD), you can omit the SAS token only from the destination URL. 请确保已在目标帐户中设置了适当的角色。Make sure that you've set up the proper roles in your destination account. 请参阅选项 1:使用 Azure Active DirectorySee Option 1: Use Azure Active Directory.

    本文中的示例假设你已使用 Azure AD 验证了身份,因此这些示例省略了目标 URL 中的 SAS 令牌。The examples in this article assume that you've authenticated your identity by using Azure AD so the examples omit the SAS tokens from the destination URL.

  • 如果复制到高级块 Blob 存储帐户,请通过将 s2s-preserve-access-tier 设置为 false(例如:--s2s-preserve-access-tier=false),在复制操作中省略 Blob 的访问层。If you copy to a premium block blob storage account, omit the access tier of a blob from the copy operation by setting the s2s-preserve-access-tier to false (For example: --s2s-preserve-access-tier=false). 高级块 Blob 存储帐户不支持访问层。Premium block blob storage accounts don't support access tiers.

  • 如果复制到具有分层命名空间的帐户或从其中复制,请在 URL 语法中使用 blob.core.chinacloudapi.cn 而不是 dfs.core.chinacloudapi.cnIf you copy to or from an account that has a hierarchical namespace, use blob.core.chinacloudapi.cn instead of dfs.core.chinacloudapi.cn in the URL syntax. Data Lake Storage 上的多协议访问使你可以使用 blob.core.chinacloudapi.cn,这是帐户间复制方案的唯一受支持的语法。Multi-protocol access on Data Lake Storage enables you to use blob.core.chinacloudapi.cn, and it is the only supported syntax for account to account copy scenarios.

  • 可以通过设置 AZCOPY_CONCURRENCY_VALUE 环境变量的值来提高复制操作的吞吐量。You can increase the throughput of copy operations by setting the value of the AZCOPY_CONCURRENCY_VALUE environment variable. 有关详细信息,请参阅优化吞吐量To learn more, see Optimize throughput.

复制 BlobCopy a blob

使用 azcopy copy 命令将 Blob 复制到另一个存储帐户。Copy a blob to another storage account by using the azcopy copy command.

提示

此示例将路径参数括在单引号 ('') 内。This example encloses path arguments with single quotes (''). 在除 Windows 命令 Shell (cmd.exe) 以外的所有命令 shell 中,都请使用单引号。Use single quotes in all command shells except for the Windows Command Shell (cmd.exe). 如果使用 Windows 命令 Shell (cmd.exe),请用双引号 ("") 而不是单引号 ('') 括住路径参数。If you're using a Windows Command Shell (cmd.exe), enclose path arguments with double quotes ("") instead of single quotes ('').

语法Syntax azcopy copy 'https://<source-storage-account-name>.blob.core.chinacloudapi.cn/<container-name>/<blob-path><SAS-token>' 'https://<destination-storage-account-name>.blob.core.chinacloudapi.cn/<container-name>/<blob-path>'
示例Example azcopy copy 'https://mysourceaccount.blob.core.chinacloudapi.cn/mycontainer/myTextFile.txt?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' 'https://mydestinationaccount.blob.core.chinacloudapi.cn/mycontainer/myTextFile.txt'

复制操作是同步的,因此,当命令返回时,表示已复制所有文件。The copy operation is synchronous so when the command returns, that indicates that all files have been copied.

复制目录Copy a directory

使用 azcopy copy 命令将目录复制到另一个存储帐户。Copy a directory to another storage account by using the azcopy copy command.

提示

此示例将路径参数括在单引号 ('') 内。This example encloses path arguments with single quotes (''). 在除 Windows 命令 Shell (cmd.exe) 以外的所有命令 shell 中,都请使用单引号。Use single quotes in all command shells except for the Windows Command Shell (cmd.exe). 如果使用 Windows 命令 Shell (cmd.exe),请用双引号 ("") 而不是单引号 ('') 括住路径参数。If you're using a Windows Command Shell (cmd.exe), enclose path arguments with double quotes ("") instead of single quotes ('').

语法Syntax azcopy copy 'https://<source-storage-account-name>.blob.core.chinacloudapi.cn/<container-name>/<directory-path><SAS-token>' 'https://<destination-storage-account-name>.blob.core.chinacloudapi.cn/<container-name>' --recursive
示例Example azcopy copy 'https://mysourceaccount.blob.core.chinacloudapi.cn/mycontainer/myBlobDirectory?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' 'https://mydestinationaccount.blob.core.chinacloudapi.cn/mycontainer' --recursive

复制操作是同步的,因此,当命令返回时,表示已复制所有文件。The copy operation is synchronous so when the command returns, that indicates that all files have been copied.

复制容器Copy a container

使用 azcopy copy 命令将容器复制到另一个存储帐户。Copy a container to another storage account by using the azcopy copy command.

提示

此示例将路径参数括在单引号 ('') 内。This example encloses path arguments with single quotes (''). 在除 Windows 命令 Shell (cmd.exe) 以外的所有命令 shell 中,都请使用单引号。Use single quotes in all command shells except for the Windows Command Shell (cmd.exe). 如果使用 Windows 命令 Shell (cmd.exe),请用双引号 ("") 而不是单引号 ('') 括住路径参数。If you're using a Windows Command Shell (cmd.exe), enclose path arguments with double quotes ("") instead of single quotes ('').

语法Syntax azcopy copy 'https://<source-storage-account-name>.blob.core.chinacloudapi.cn/<container-name><SAS-token>' 'https://<destination-storage-account-name>.blob.core.chinacloudapi.cn/<container-name>' --recursive
示例Example azcopy copy 'https://mysourceaccount.blob.core.chinacloudapi.cn/mycontainer?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' 'https://mydestinationaccount.blob.core.chinacloudapi.cn/mycontainer' --recursive

复制操作是同步的,因此,当命令返回时,表示已复制所有文件。The copy operation is synchronous so when the command returns, that indicates that all files have been copied.

复制容器、目录和 BlobCopy containers, directories, and blobs

使用 azcopy copy 命令将所有容器、目录和 Blob 复制到另一个存储帐户。Copy all containers, directories, and blobs to another storage account by using the azcopy copy command.

提示

此示例将路径参数括在单引号 ('') 内。This example encloses path arguments with single quotes (''). 在除 Windows 命令 Shell (cmd.exe) 以外的所有命令 shell 中,都请使用单引号。Use single quotes in all command shells except for the Windows Command Shell (cmd.exe). 如果使用 Windows 命令 Shell (cmd.exe),请用双引号 ("") 而不是单引号 ('') 括住路径参数。If you're using a Windows Command Shell (cmd.exe), enclose path arguments with double quotes ("") instead of single quotes ('').

语法Syntax azcopy copy 'https://<source-storage-account-name>.blob.core.chinacloudapi.cn/<SAS-token>' 'https://<destination-storage-account-name>.blob.core.chinacloudapi.cn/' --recursive
示例Example azcopy copy 'https://mysourceaccount.blob.core.chinacloudapi.cn/?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' 'https://mydestinationaccount.blob.core.chinacloudapi.cn' --recursive

复制操作是同步的,因此,当命令返回时,表示已复制所有文件。The copy operation is synchronous so when the command returns, that indicates that all files have been copied.

使用可选标志复制Copy with optional flags

可以通过使用可选标志来调整复制操作。You can tweak your copy operation by using optional flags. 下面是几个示例。Here's a few examples.

方案Scenario 标志Flag
将 Blob 复制为块 Blob、页 Blob 或追加 Blob。Copy blobs as Block, Page, or Append Blobs. --blob-type=[BlockBlob|PageBlob|AppendBlob]--blob-type=[BlockBlob|PageBlob|AppendBlob]
复制到特定访问层(如存档层)。Copy to a specific access tier (such as the archive tier). --block-blob-tier=[None|Hot|Cool|Archive]--block-blob-tier=[None|Hot|Cool|Archive]
自动解压缩文件。Automatically decompress files. --decompress=[gzip|deflate]--decompress=[gzip|deflate]

有关完整列表,请参阅选项For a complete list, see options.

后续步骤Next steps

如需了解更多示例,请参阅以下文章:Find more examples in these articles: