使用 AzCopy v10 将文件上传到 Azure Blob 存储Upload files to Azure Blob storage by using AzCopy v10

可以使用 AzCopy v10 命令行实用程序将文件和目录上传到 Blob 存储。You can upload files and directories to Blob storage by using the AzCopy v10 command-line utility.

若要查看其他类型任务(如下载 Blob、与 Blob 存储同步或在帐户之间复制 Blob)的示例,请参阅本文的后续步骤部分中提供的链接。To see examples for other types of tasks such as downloading blobs, 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>'.

创建容器Create a container

可以使用 azcopy make 命令创建容器。You can use the azcopy make command to create a container.

提示

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

使用 azcopy copy 命令上传文件。Upload a file 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 '<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

使用 azcopy copy 命令上传目录。Upload a directory by using the azcopy copy command.

此示例将某个目录(以及该目录中的所有文件)复制到 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.

提示

此示例将路径参数括在单引号 ('') 内。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 '<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 doesn't exist in the container, AzCopy creates a new directory by that name.

上传目录内容Upload directory contents

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

提示

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

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

上传特定的文件Upload specific files

可以使用完整的文件名、包含通配符 (*) 的部分名称或者日期和时间来上传特定文件。You can upload specific files 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 ('').

指定多个完整文件名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 目录中的所有文件。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.

上传在某个日期和时间之前或之后修改的文件Upload files 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 upload files that were modified on or after the specified date.

语法Syntax azcopy copy '<local-directory-path>\*' 'https://<storage-account-name>.<blob or dfs>.core.chinacloudapi.cn/<container-or-directory-name>' --include-after <Date-Time-in-ISO-8601-format>
示例Example azcopy copy 'C:\myDirectory\*' 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/FileDirectory' --include-after '2020-08-19T15:04:00Z'
示例(分层命名空间)Example (hierarchical namespace) azcopy copy 'C:\myDirectory\*' 'https://mystorageaccount.dfs.core.chinacloudapi.cn/mycontainer/FileDirectory' --include-after '2020-08-19T15:04:00Z'

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

使用可选标志上传Upload with optional flags

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

后续步骤Next steps

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