使用 AzCopy 和 Blob 存储传输数据Transfer data with AzCopy and Blob storage

AzCopy 是一个命令行实用工具,可用于向/从存储帐户复制数据,或者在存储帐户之间复制数据。AzCopy is a command-line utility that you can use to copy data to, from, or between storage accounts. 本文包含适用于 Blob 存储的示例命令。This article contains example commands that work with Blob storage.

Tip

本文中的示例将路径参数括在单引号 ('') 中。The examples in this article enclose 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 ('').

入门Get started

请参阅 AzCopy 入门一文下载 AzCopy,并了解如何提供存储服务的授权凭据。See the Get started with AzCopy article to download AzCopy and learn about the ways that you can provide authorization credentials to the storage service.

Note

本文中的示例假设你已使用 AzCopy login 命令验证自己的身份。The examples in this article assume that you've authenticated your identity by using the AzCopy login command. 然后,AzCopy 会使用你的 Azure AD 帐户来授权访问 Blob 存储中的数据。AzCopy then uses your Azure AD account to authorize access to data in Blob storage.

如果你希望使用 SAS 令牌来授权访问 Blob 数据,可将该令牌追加到每个 AzCopy 命令中的资源 URL。If you'd rather use a SAS token to authorize access to blob data, then you can append that token to the resource URL in each AzCopy command.

例如:'https://<storage-account-name>.blob.core.chinacloudapi.cn/<container-name>?<SAS-token>'For example: 'https://<storage-account-name>.blob.core.chinacloudapi.cn/<container-name>?<SAS-token>'.

创建容器Create a container

可以使用 azcopy make 命令创建容器。You can use the azcopy make command to create a container. 本部分中的示例创建名为 mycontainer 的容器。The examples in this section create a container named mycontainer.

语法Syntax azcopy make 'https://<storage-account-name>.<blob or dfs>.core.chinacloudapi.cn/<container-name>'
示例Example azcopy make 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer'
示例(分层命名空间)Example (hierarchical namespace) azcopy make 'https://mystorageaccount.dfs.core.chinacloudapi.cn/mycontainer'

有关详细参考文档,请参阅 azcopy makeFor detailed reference docs, see azcopy make.

上传文件Upload files

可以使用 azcopy copy 命令从本地计算机上传文件和目录。You can use the azcopy copy command to upload files and directories from your local computer.

本部分包含以下示例:This section contains the following examples:

  • 上传文件Upload a file
  • 上传目录Upload a directory
  • 上传目录的内容Upload the contents of a directory
  • 上传特定的文件Upload specific files

Tip

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

方案Scenario 标志Flag
将文件作为追加 Blob 或页 Blob 上传。Upload files as Append Blobs or Page Blobs. --blob-type=[BlockBlob|PageBlob|AppendBlob]--blob-type=[BlockBlob|PageBlob|AppendBlob]
上传到特定访问层(如存档层)。Upload to a specific access tier (such as the archive tier). --block-blob-tier=[None|Hot|Cool|Archive]--block-blob-tier=[None|Hot|Cool|Archive]

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

上传文件Upload a file

语法Syntax azcopy copy '<local-file-path>' 'https://<storage-account-name>.<blob or dfs>.core.chinacloudapi.cn/<container-name>/<blob-name>'
示例Example azcopy copy 'C:\myDirectory\myTextFile.txt' 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/myTextFile.txt'
示例(分层命名空间)Example (hierarchical namespace) azcopy copy 'C:\myDirectory\myTextFile.txt' 'https://mystorageaccount.dfs.core.chinacloudapi.cn/mycontainer/myTextFile.txt'

还可以在文件路径或文件名中的任意位置使用通配符 (*) 来上传文件。You can also upload a file by using a wildcard symbol (*) anywhere in the file path or file name. 例如:'C:\myDirectory\*.txt'C:\my*\*.txtFor example: 'C:\myDirectory\*.txt', or C:\my*\*.txt.

上传目录Upload a directory

此示例将某个目录(以及该目录中的所有文件)复制到 Blob 容器。This example copies a directory (and all of the files in that directory) to a blob container. 结果是该文件共享中出现一个同名的容器。The result is a directory in the container by the same name.

语法Syntax azcopy copy '<local-directory-path>' 'https://<storage-account-name>.<blob or dfs>.core.chinacloudapi.cn/<container-name>' --recursive
示例Example azcopy copy 'C:\myDirectory' 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer' --recursive
示例(分层命名空间)Example (hierarchical namespace) azcopy copy 'C:\myDirectory' 'https://mystorageaccount.dfs.core.chinacloudapi.cn/mycontainer' --recursive

若要复制到容器中的某个目录,只需在命令字符串中指定该目录的名称。To copy to a directory within the container, just specify the name of that directory in your command string.

示例Example azcopy copy 'C:\myDirectory' 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/myBlobDirectory' --recursive
示例(分层命名空间)Example (hierarchical namespace) azcopy copy 'C:\myDirectory' 'https://mystorageaccount.dfs.core.chinacloudapi.cn/mycontainer/myBlobDirectory' --recursive

如果指定的目录名称在容器中不存在,AzCopy 将以该名称创建一个新目录。If you specify the name of a directory that does not exist in the container, AzCopy creates a new directory by that name.

上传目录的内容Upload the contents of a directory

可以使用通配符 (*) 上传目录的内容,而无需复制包含的目录本身。You can upload the contents of a directory without copying the containing directory itself by using the wildcard symbol (*).

语法Syntax azcopy copy '<local-directory-path>\*' 'https://<storage-account-name>.<blob or dfs>.core.chinacloudapi.cn/<container-name>/<directory-path>
示例Example azcopy copy 'C:\myDirectory\*' 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/myBlobDirectory'
示例(分层命名空间)Example (hierarchical namespace) azcopy copy 'C:\myDirectory\*' 'https://mystorageaccount.dfs.core.chinacloudapi.cn/mycontainer/myBlobDirectory'

Note

追加 --recursive 标志可以上传所有子目录中的文件。Append the --recursive flag to upload files in all sub-directories.

上传特定的文件Upload specific files

可以指定完整的文件名,或使用包含通配符 (*) 的部分名称。You can specify complete file names, or use partial names with wildcard characters (*).

指定多个完整文件名Specify multiple complete file names

结合 --include-path 选项使用 azcopy copy 命令。Use the azcopy copy command with the --include-path option. 使用分号 (;) 分隔各个文件名。Separate individual file names by using a semicolon (;).

语法Syntax azcopy copy '<local-directory-path>' 'https://<storage-account-name>.<blob or dfs>.core.chinacloudapi.cn/<container-name>' --include-path <semicolon-separated-file-list>
示例Example azcopy copy 'C:\myDirectory' 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer' --include-path 'photos;documents\myFile.txt' --recursive
示例(分层命名空间)Example (hierarchical namespace) azcopy copy 'C:\myDirectory' 'https://mystorageaccount.dfs.core.chinacloudapi.cn/mycontainer' --include-path 'photos;documents\myFile.txt' --recursive

在此示例中,AzCopy 将传输 C:\myDirectory\photos 目录和 C:\myDirectory\documents\myFile.txt 文件。In this example, AzCopy transfers the C:\myDirectory\photos directory and the C:\myDirectory\documents\myFile.txt file. 需要包含 --recursive 选项才能传输 C:\myDirectory\photos 目录中的所有文件。You need to include the --recursive option to transfer all files in the C:\myDirectory\photos directory.

还可以使用 --exclude-path 选项来排除文件。You can also exclude files by using the --exclude-path option. 有关详细信息,请参阅 azcopy copy 参考文档。To learn more, see azcopy copy reference docs.

使用通配符Use wildcard characters

结合 --include-pattern 选项使用 azcopy copy 命令。Use the azcopy copy command with the --include-pattern option. 指定包含通配符的部分名称。Specify partial names that include the wildcard characters. 使用分号 (;) 分隔名称。Separate names by using a semicolin (;).

语法Syntax azcopy copy '<local-directory-path>' 'https://<storage-account-name>.<blob or dfs>.core.chinacloudapi.cn/<container-name>' --include-pattern <semicolon-separated-file-list-with-wildcard-characters>
示例Example azcopy copy 'C:\myDirectory' 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer' --include-pattern 'myFile*.txt;*.pdf*'
示例(分层命名空间)Example (hierarchical namespace) azcopy copy 'C:\myDirectory' 'https://mystorageaccount.dfs.core.chinacloudapi.cn/mycontainer' --include-pattern 'myFile*.txt;*.pdf*'

还可以使用 --exclude-pattern 选项来排除文件。You can also exclude files by using the --exclude-pattern option. 有关详细信息,请参阅 azcopy copy 参考文档。To learn more, see azcopy copy reference docs.

--include-pattern--exclude-pattern 选项仅适用于文件名,而不适用于路径。The --include-pattern and --exclude-pattern options apply only to filenames and not to the path. 若要复制目录树中存在的所有文本文件,请使用 –recursive 选项获取整个目录树,然后使用 –include-pattern 并指定 *.txt 来获取所有文本文件。If you want to copy all of the text files that exist in a directory tree, use the –recursive option to get the entire directory tree, and then use the –include-pattern and specify *.txt to get all of the text files.

下载文件Download files

可以使用 azcopy copy 命令将 Blob、目录和容器下载到本地计算机。You can use the azcopy copy command to download blobs, directories, and containers to your local computer.

本部分包含以下示例:This section contains the following examples:

  • 下载文件Download a file
  • 下载目录Download a directory
  • 下载目录的内容Download the contents of a directory
  • 下载特定的文件Download specific files

Tip

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

方案Scenario 标志Flag
自动解压缩文件。Automatically decompress files. --decompress--decompress
指定你希望与复制相关的日志条目达到何种详细程度。Specify how detailed you want your copy-related log entries to be. --log-level=[WARNING|ERROR|INFO|NONE]--log-level=[WARNING|ERROR|INFO|NONE]
指定是否以及如何覆盖目标位置的冲突文件和 Blob。Specify if and how to overwrite the conflicting files and blobs at the destination. --overwrite=[true|false|ifSourceNewer|prompt]--overwrite=[true|false|ifSourceNewer|prompt]

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

Note

如果 Blob 的 Content-md5 属性值包含哈希,AzCopy 将计算已下载的数据的 MD5 哈希,并验证存储在该 Blob 的 Content-md5 属性中的 MD5 哈希是否与计算出的哈希相匹配。If the Content-md5 property value of a blob contains a hash, AzCopy calculates an MD5 hash for downloaded data and verifies that the MD5 hash stored in the blob's Content-md5 property matches the calculated hash. 如果这些值不匹配,除非通过将 --check-md5=NoCheck--check-md5=LogOnly 追加到 copy 命令来重写此行为,否则下载将会失败。If these values don't match, the download fails unless you override this behavior by appending --check-md5=NoCheck or --check-md5=LogOnly to the copy command.

下载文件Download a file

语法Syntax azcopy copy 'https://<storage-account-name>.<blob or dfs>.core.chinacloudapi.cn/<container-name>/<blob-path>' '<local-file-path>'
示例Example azcopy copy 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/myTextFile.txt' 'C:\myDirectory\myTextFile.txt'
示例(分层命名空间)Example (hierarchical namespace) azcopy copy 'https://mystorageaccount.dfs.core.chinacloudapi.cn/mycontainer/myTextFile.txt' 'C:\myDirectory\myTextFile.txt'

下载目录Download a directory

语法Syntax azcopy copy 'https://<storage-account-name>.<blob or dfs>.core.chinacloudapi.cn/<container-name>/<directory-path>' '<local-directory-path>' --recursive
示例Example azcopy copy 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/myBlobDirectory' 'C:\myDirectory' --recursive
示例(分层命名空间)Example (hierarchical namespace) azcopy copy 'https://mystorageaccount.dfs.core.chinacloudapi.cn/mycontainer/myBlobDirectory' 'C:\myDirectory' --recursive

此示例将生成名为 C:\myDirectory\myBlobDirectory 的目录,其中包含所有已下载的文件。This example results in a directory named C:\myDirectory\myBlobDirectory that contains all of the downloaded files.

下载目录的内容Download the contents of a directory

可以使用通配符 (*) 下载目录的内容,而无需复制包含的目录本身。You can download the contents of a directory without copying the containing directory itself by using the wildcard symbol (*).

Note

目前,只有不使用分层命名空间的帐户才支持此方案。Currently, this scenario is supported only for accounts that don't have a hierarchical namespace.

语法Syntax azcopy copy 'https://<storage-account-name>.blob.core.chinacloudapi.cn/<container-name>/*' '<local-directory-path>/'
示例Example azcopy copy 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/myBlobDirectory/*' 'C:\myDirectory'

Note

追加 --recursive 标志可以下载所有子目录中的文件。Append the --recursive flag to download files in all sub-directories.

下载特定的文件Download specific files

可以指定完整的文件名,或使用包含通配符 (*) 的部分名称。You can specify complete file names, or use partial names with wildcard characters (*).

指定多个完整文件名Specify multiple complete file names

结合 --include-path 选项使用 azcopy copy 命令。Use the azcopy copy command with the --include-path option. 使用分号 (;) 分隔各个文件名。Separate individual file names by using a semicolin (;).

语法Syntax azcopy copy 'https://<storage-account-name>.<blob or dfs>.core.chinacloudapi.cn/<container-or-directory-name>' '<local-directory-path>' --include-path <semicolon-separated-file-list>
示例Example azcopy copy 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/FileDirectory' 'C:\myDirectory' --include-path 'photos;documents\myFile.txt' --recursive
示例(分层命名空间)Example (hierarchical namespace) azcopy copy 'https://mystorageaccount.dfs.core.chinacloudapi.cn/mycontainer/FileDirectory' 'C:\myDirectory' --include-path 'photos;documents\myFile.txt'--recursive

在此示例中,AzCopy 将传输 https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/FileDirectory/photos 目录和 https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/FileDirectory/documents/myFile.txt 文件。In this example, AzCopy transfers the https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/FileDirectory/photos directory and the https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/FileDirectory/documents/myFile.txt file. 需要包含 --recursive 选项才能传输 https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/FileDirectory/photos 目录中的所有文件。You need to include the --recursive option to transfer all files in the https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/FileDirectory/photos directory.

还可以使用 --exclude-path 选项来排除文件。You can also exclude files by using the --exclude-path option. 有关详细信息,请参阅 azcopy copy 参考文档。To learn more, see azcopy copy reference docs.

使用通配符Use wildcard characters

结合 --include-pattern 选项使用 azcopy copy 命令。Use the azcopy copy command with the --include-pattern option. 指定包含通配符的部分名称。Specify partial names that include the wildcard characters. 使用分号 (;) 分隔名称。Separate names by using a semicolin (;).

语法Syntax azcopy copy 'https://<storage-account-name>.<blob or dfs>.core.chinacloudapi.cn/<container-or-directory-name>' '<local-directory-path>' --include-pattern <semicolon-separated-file-list-with-wildcard-characters>
示例Example azcopy copy 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/FileDirectory' 'C:\myDirectory' --include-pattern 'myFile*.txt;*.pdf*'
示例(分层命名空间)Example (hierarchical namespace) azcopy copy 'https://mystorageaccount.dfs.core.chinacloudapi.cn/mycontainer/FileDirectory' 'C:\myDirectory' --include-pattern 'myFile*.txt;*.pdf*'

还可以使用 --exclude-pattern 选项来排除文件。You can also exclude files by using the --exclude-pattern option. 有关详细信息,请参阅 azcopy copy 参考文档。To learn more, see azcopy copy reference docs.

--include-pattern--exclude-pattern 选项仅适用于文件名,而不适用于路径。The --include-pattern and --exclude-pattern options apply only to filenames and not to the path. 若要复制目录树中存在的所有文本文件,请使用 –recursive 选项获取整个目录树,然后使用 –include-pattern 并指定 *.txt 来获取所有文本文件。If you want to copy all of the text files that exist in a directory tree, use the –recursive option to get the entire directory tree, and then use the –include-pattern and specify *.txt to get all of the text files.

在存储帐户之间复制 BlobCopy blobs between storage accounts

可以使用 AzCopy 将 Blob 复制到其他存储帐户。You can use AzCopy to copy blobs to other storage accounts. 复制操作是同步的,因此,当命令返回时,表示已复制所有文件。The copy operation is synchronous so when the command returns, that indicates that all files have been copied.

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_CONCURRENCY_VALUE 环境变量的值来提高这些操作的吞吐量。You can increase the throughput of these operations by setting the value of the AZCOPY_CONCURRENCY_VALUE environment variable. 有关详细信息,请参阅优化吞吐量To learn more, see Optimize throughput.

Note

此方案在当前版本中存在以下限制。This scenario has the following limitations in the current release.

  • 必须向每个源 URL 追加一个 SAS 令牌。You have to append a SAS token to each source URL. 如果使用 Azure Active Directory (AD) 提供授权凭据,则只能从目标 URL 中省略 SAS 令牌。If you provide authorization credentials by using Azure Active Directory (AD), you can omit the SAS token only from the destination URL.
  • 高级块 Blob 存储帐户不支持访问层。Premium block blob storage accounts don't support access tiers. 请通过将 s2s-preserve-access-tier 设置为 false(例如:--s2s-preserve-access-tier=false),在复制操作中省略 Blob 的访问层。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).

本部分包含以下示例:This section contains the following examples:

  • 将 Blob 复制到另一个存储帐户Copy a blob to another storage account
  • 将目录复制到另一个存储帐户Copy a directory to another storage account
  • 将容器复制到另一个存储帐户Copy a container to another storage account
  • 将所有容器、目录和文件复制到另一个存储帐户Copy all containers, directories, and files to another storage account

这些示例也适用于具有分层命名空间的帐户。These examples also work with accounts that have a hierarchical namespace. Data Lake Storage 上的多协议访问使你可以在这些帐户上使用相同的 URL 语法 (blob.core.chinacloudapi.cn)。Multi-protocol access on Data Lake Storage enables you to use the same URL syntax (blob.core.chinacloudapi.cn) on those accounts.

Tip

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

方案Scenario 标志Flag
将文件复制为追加 Blob 或页 Blob。Copy files as Append Blobs or Page 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.

将 Blob 复制到另一个存储帐户Copy a blob to another storage account

对具有分层命名空间的帐户使用相同的 URL 语法 (blob.core.chinacloudapi.cn)。Use the same URL syntax (blob.core.chinacloudapi.cn) for accounts that have a hierarchical namespace.

语法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'
示例(分层命名空间)Example (hierarchical namespace) 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'

将目录复制到另一个存储帐户Copy a directory to another storage account

对具有分层命名空间的帐户使用相同的 URL 语法 (blob.core.chinacloudapi.cn)。Use the same URL syntax (blob.core.chinacloudapi.cn) for accounts that have a hierarchical namespace.

语法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
示例(分层命名空间)Example (hierarchical namespace) 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

将容器复制到另一个存储帐户Copy a container to another storage account

对具有分层命名空间的帐户使用相同的 URL 语法 (blob.core.chinacloudapi.cn)。Use the same URL syntax (blob.core.chinacloudapi.cn) for accounts that have a hierarchical namespace.

语法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
示例(分层命名空间)Example (hierarchical namespace) 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

将所有容器、目录和 Blob 复制到另一个存储帐户Copy all containers, directories, and blobs to another storage account

对具有分层命名空间的帐户使用相同的 URL 语法 (blob.core.chinacloudapi.cn)。Use the same URL syntax (blob.core.chinacloudapi.cn) for accounts that have a hierarchical namespace.

语法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
示例(分层命名空间)Example (hierarchical namespace) 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

同步文件Synchronize files

可将本地文件系统的内容与 Blob 容器同步。You can synchronize the contents of a local file system with a blob container. 还可以将容器和虚拟目录相互同步。You can also synchronize containers and virtual directories with one another. 同步是单向的。Synchronization is one-way. 换言之,需要选择这两个终结点中哪一个是源,哪一个是目标。In other words, you choose which of these two endpoints is the source and which one is the destination. 同步也使用服务器到服务器 API。Synchronization also uses server to server APIs. 本部分中提供的示例也适用于具有分层命名空间的帐户。The examples presented in this section also work with accounts that have a hierarchical namespace.

Note

当前版本的 AzCopy 不会在其他源和目标之间同步(例如:文件存储或 Amazon Web Services (AWS) S3 桶)。The current release of AzCopy doesn't synchronize between other sources and destinations (For example: File storage or Amazon Web Services (AWS) S3 buckets).

sync 命令比较文件名和上次修改时间戳。The sync command compares file names and last modified timestamps. 如果将 --delete-destination 可选标志设置为 trueprompt 值,当目标目录中的文件不在源目录中存在时,会删除这些文件。Set the --delete-destination optional flag to a value of true or prompt to delete files in the destination directory if those files no longer exist in the source directory.

如果将 --delete-destination 标志设置为 true,AzCopy 将删除文件且不提供提示。If you set the --delete-destination flag to true AzCopy deletes files without providing a prompt. 若要在 AzCopy 删除文件之前显示提示,请将 --delete-destination 标志设置为 promptIf you want a prompt to appear before AzCopy deletes a file, set the --delete-destination flag to prompt.

Note

为了防止意外删除,请务必在使用 --delete-destination=prompt|true 标志之前启用软删除功能。To prevent accidental deletions, make sure to enable the soft delete feature before you use the --delete-destination=prompt|true flag.

Tip

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

方案Scenario 标志Flag
指定下载时应验证 MD5 哈希的严格程度。Specify how strictly MD5 hashes should be validated when downloading. --check-md5=[NoCheck|LogOnly|FailIfDifferent|FailIfDifferentOrMissing]--check-md5=[NoCheck|LogOnly|FailIfDifferent|FailIfDifferentOrMissing]
基于模式排除文件。Exclude files based on a pattern. --exclude-path--exclude-path
指定你希望与同步相关的日志条目达到何种详细程度。Specify how detailed you want your sync-related log entries to be. --log-level=[WARNING|ERROR|INFO|NONE]--log-level=[WARNING|ERROR|INFO|NONE]

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

使用对本地文件系统所做的更改来更新容器Update a container with changes to a local file system

在这种情况下,容器是目标,本地文件系统是源。In this case, the container is the destination, and the local file system is the source.

语法Syntax azcopy sync '<local-directory-path>' 'https://<storage-account-name>.blob.core.chinacloudapi.cn/<container-name>' --recursive
示例Example azcopy sync 'C:\myDirectory' 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer' --recursive

使用对容器所做的更改来更新本地文件系统Update a local file system with changes to a container

在这种情况下,本地文件系统是目标,容器是源。In this case, the local file system is the destination, and the container is the source.

语法Syntax azcopy sync 'https://<storage-account-name>.blob.core.chinacloudapi.cn/<container-name>' 'C:\myDirectory' --recursive
示例Example azcopy sync 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer' 'C:\myDirectory' --recursive

使用一个容器的更改来更新另一个容器Update a container with changes in another container

此命令中显示的第一个容器是源。The first container that appears in this command is the source. 第二个是目标。The second one is the destination.

语法Syntax azcopy sync 'https://<source-storage-account-name>.blob.core.chinacloudapi.cn/<container-name>' 'https://<destination-storage-account-name>.blob.core.chinacloudapi.cn/<container-name>' --recursive
示例Example azcopy sync 'https://mysourceaccount.blob.core.chinacloudapi.cn/mycontainer' 'https://mydestinationaccount.blob.core.chinacloudapi.cn/mycontainer' --recursive

使用对另一个文件共享中的目录所做的更改来更新某个目录Update a directory with changes to a directory in another file share

此命令中显示的第一个目录是源。The first directory that appears in this command is the source. 第二个是目标。The second one is the destination.

语法Syntax azcopy sync 'https://<source-storage-account-name>.blob.core.chinacloudapi.cn/<container-name>/<directory-name>' 'https://<destination-storage-account-name>.blob.core.chinacloudapi.cn/<container-name>/<directory-name>' --recursive
示例Example azcopy sync 'https://mysourceaccount.blob.core.chinacloudapi.cn/<container-name>/myDirectory' 'https://mydestinationaccount.blob.core.chinacloudapi.cn/mycontainer/myDirectory' --recursive

后续步骤Next steps

在以下文章中查找更多示例:Find more examples in any of these articles: