使用 AzCopy 从 Azure Blob 存储下载 BlobDownload blobs from Azure Blob storage by using AzCopy

你可以使用 AzCopy v10 命令行实用程序从 Blob 存储下载 Blob 和目录。You can download blobs and directories from Blob storage by using the AzCopy v10 command-line utility.

若要查看其他类型任务(如上传文件、与 Blob 存储同步或在帐户之间复制 Blob)的示例,请参阅本文的下一步部分中提供的链接。To see examples for other types of tasks such as uploading files, synchronizing with Blob storage, or copying blobs between accounts, see the links presented in the Next Steps section of this article.

入门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.

备注

本文中的示例假定你已使用 Azure Active Directory (Azure AD) 提供了授权凭据。The examples in this article assume that you've provided authorization credentials by using Azure Active Directory (Azure AD).

如果你希望使用 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>'.

下载 blobDownload a blob

使用 azcopy copy 命令下载 Blob。Download a blob 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://<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'

备注

如果 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 directory

使用 azcopy copy 命令下载目录。Download a directory 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://<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 的目录,其中包含所有已下载的 Blob。This example results in a directory named C:\myDirectory\myBlobDirectory that contains all of the downloaded blobs.

下载目录内容Download directory contents

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

提示

此示例将路径参数括在单引号 ('') 内。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 ('').

备注

目前,只有不使用分层命名空间的帐户才支持此方案。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'

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

下载特定的 BlobDownload specific blobs

可以使用完整的文件名、包含通配符 (*) 的部分名称或者日期和时间来下载特定 Blob。You can download specific blobs by using complete file names, partial names with wildcard characters (*), or by using dates and times.

提示

这些示例将路径参数括在单引号 ('') 内。These examples 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 ('').

指定多个完整 Blob 名Specify multiple complete blob names

结合 --include-path 选项使用 azcopy copy 命令。Use the azcopy copy command with the --include-path option. 使用分号 (;) 分隔各个 Blob 名。Separate individual blob 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 目录中的所有 Blob。Include the --recursive option to transfer all blobs in the https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/FileDirectory/photos directory.

还可使用 --exclude-path 选项来排除 Blob。You can also exclude blobs 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 选项来排除 Blob。You can also exclude blobs by using the --exclude-pattern option. 有关详细信息,请参阅 azcopy copy 参考文档。To learn more, see azcopy copy reference docs.

--include-pattern--exclude-pattern 选项仅适用于 Blob 名,而不适用于路径。The --include-pattern and --exclude-pattern options apply only to blob names and not to the path. 若要复制目录树中存在的所有文本文件 (Blob),请使用 -recursive 选项获取整个目录树,然后使用 -include-pattern 并指定 *.txt 来获取所有文本文件。If you want to copy all of the text files (blobs) 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.

下载在某个日期和时间之前或之后修改的 BlobDownload blobs that were modified before or after a date and time

azcopy copy 命令与 --include-before--include-after 选项结合使用。Use the azcopy copy command with the --include-before or --include-after option. 以 ISO-8601 格式指定日期和时间(例如 2020-08-19T15:04:00Z)。Specify a date and time in ISO-8601 format (For example: 2020-08-19T15:04:00Z).

以下示例下载在指定日期或之后修改的文件。The following examples download files that were modified on or after the specified date.

语法Syntax

azcopy copy 'https://<storage-account-name>.<blob or dfs>.core.chinacloudapi.cn/<container-or-directory-name>/*' '<local-directory-path>' --include-after <Date-Time-in-ISO-8601-format>

示例Example

azcopy copy 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/FileDirectory/*' 'C:\myDirectory'  --include-after '2020-08-19T15:04:00Z'

示例(分层命名空间)Example (hierarchical namespace)

azcopy copy 'https://mystorageaccount.dfs.core.chinacloudapi.cn/mycontainer/FileDirectory/*' 'C:\myDirectory'  --include-after '2020-08-19T15:04:00Z'

如需详细的参考,请查看 azcopy copy 参考文档。For detailed reference, see the azcopy copy reference docs.

下载 blob 的早期版本Download previous versions of a blob

如果已启用 blob 版本控制,则可以下载 blob 的一个或多个早期版本。If you've enabled blob versioning, you can download one or more previous versions of a blob.

首先,创建一个包含版本 ID 列表的文本文件。First, create a text file that contains a list of version IDs. 每个版本 ID 必须出现在单独的行中。Each version ID must appear on a separate line. 例如:For example:

2020-08-17T05:50:34.2199403Z
2020-08-17T05:50:34.5041365Z
2020-08-17T05:50:36.7607103Z

然后,结合 --list-of-versions 选项使用 azcopy copy 命令。Then, use the azcopy copy command with the --list-of-versions option. 指定包含版本列表的文本文件的位置(例如:D:\\list-of-versions.txt)。Specify the location of the text file that contains the list of versions (For example: D:\\list-of-versions.txt).

下载 Blob 快照Download a blob snapshot

可通过引用 Blob 快照的 DateTime 值来下载 Blob 快照You can download a blob snapshot by referencing the DateTime value of a blob snapshot.

语法Syntax

azcopy copy 'https://<storage-account-name>.<blob or dfs>.core.chinacloudapi.cn/<container-name>/<blob-path>?sharesnapshot=<DateTime-of-snapshot>' '<local-file-path>'

示例Example

azcopy copy 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/myTextFile.txt?sharesnapshot=2020-09-23T08:21:07.0000000Z' 'C:\myDirectory\myTextFile.txt'

示例(分层命名空间)Example (hierarchical namespace)

azcopy copy 'https://mystorageaccount.dfs.core.chinacloudapi.cn/mycontainer/myTextFile.txt?sharesnapshot=2020-09-23T08:21:07.0000000Z' 'C:\myDirectory\myTextFile.txt'

备注

如果使用 SAS 令牌授权访问 Blob 数据,则在 SAS 令牌之后追加快照 DateTime。If you are using a SAS token to authorize access to blob data, then append snapshot DateTime after the SAS token. 例如:'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/myTextFile.txt?sv=2018-03-28&ss=bjqt&srs=sco&sp=rjklhjup&se=2019-05-10T04:37:48Z&st=2019-05-09T20:37:48Z&spr=https&sig=%2FSOVEFfsKDqRry4bk3qz1vAQFwY5DDzp2%2B%2F3Eykf%2FJLs%3D&sharesnapshot=2020-09-23T08:21:07.0000000Z'For example: 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/myTextFile.txt?sv=2018-03-28&ss=bjqt&srs=sco&sp=rjklhjup&se=2019-05-10T04:37:48Z&st=2019-05-09T20:37:48Z&spr=https&sig=%2FSOVEFfsKDqRry4bk3qz1vAQFwY5DDzp2%2B%2F3Eykf%2FJLs%3D&sharesnapshot=2020-09-23T08:21:07.0000000Z'.

下载可选标志Download with optional flags

可以通过使用可选标志来调整下载操作。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.

后续步骤Next steps

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

请参阅以下文章,配置设置、优化性能和排查问题:See these articles to configure settings, optimize performance, and troubleshoot issues: