AzCopy 入门Get started with AzCopy

AzCopy 是一个命令行实用工具,可用于向/从存储帐户复制 Blob 或文件。AzCopy is a command-line utility that you can use to copy blobs or files to or from a storage account. 本文将帮助你下载 AzCopy,连接到存储帐户,然后传输文件。This article helps you download AzCopy, connect to your storage account, and then transfer files.

备注

AzCopy V10 是当前支持的 AzCopy 版本。AzCopy V10 is the currently supported version of AzCopy.

如果需要使用旧版 AzCopy,请参阅本文的使用旧版 AzCopy 部分。If you need to use a previous version of AzCopy, see the Use the previous version of AzCopy section of this article.

下载 AzCopyDownload AzCopy

首先,将 AzCopy V10 可执行文件下载到计算机上的任意目录。First, download the AzCopy V10 executable file to any directory on your computer. AzCopy V10 是一个免安装的可执行文件。AzCopy V10 is just an executable file, so there's nothing to install.

这些文件压缩成 zip 文件(Windows 和 Mac)或 tar 文件(Linux)。These files are compressed as a zip file (Windows and Mac) or a tar file (Linux). 要在 Linux 上下载并解压缩 tar 文件,请参阅 Linux 分发文档。To download and decompress the tar file on Linux, see the documentation for your Linux distribution.

备注

若要向/从 Azure 表存储服务复制数据,请安装 AzCopy 版本 7.3If you want to copy data to and from your Azure Table storage service, then install AzCopy version 7.3.

运行 AzCopyRun AzCopy

为方便使用,请考虑将 AzCopy 可执行文件的目录位置添加到系统路径。For convenience, consider adding the directory location of the AzCopy executable to your system path for ease of use. 这样就可以在系统上的任何目录中键入 azcopyThat way you can type azcopy from any directory on your system.

如果不将 AzCopy 目录添加到系统路径,则必须将目录切换到 AzCopy 可执行文件所在的位置,然后在 Windows PowerShell 命令提示符中键入 azcopy.\azcopyIf you choose not to add the AzCopy directory to your path, you'll have to change directories to the location of your AzCopy executable and type azcopy or .\azcopy in Windows PowerShell command prompts.

系统不会自动向 Azure 存储帐户的所有者分配数据访问权限。As an owner of your Azure Storage account, you aren't automatically assigned permissions to access data. 在使用 AzCopy 执行任何有意义的操作之前,需确定如何向存储服务提供身份验证凭据。Before you can do anything meaningful with AzCopy, you need to decide how you'll provide authorization credentials to the storage service.

授权 AzCopyAuthorize AzCopy

可以使用 Azure Active Directory (AD) 或共享访问签名 (SAS) 令牌来提供授权凭据。You can provide authorization credentials by using Azure Active Directory (AD), or by using a Shared Access Signature (SAS) token.

请参考下表:Use this table as a guide:

存储类型Storage type 当前支持的授权方法Currently supported method of authorization
Blob 存储Blob storage Azure AD 和 SASAzure AD & SAS
Blob 存储(分层命名空间)Blob storage (hierarchical namespace) Azure AD 和 SASAzure AD & SAS
文件存储File storage 仅限 SASSAS only

选项 1:使用 Azure Active DirectoryOption 1: Use Azure Active Directory

此选项仅适用于 blob 存储。This option is available for blob Storage only. 使用 Azure Active Directory 可以一次性提供凭据,而无需向每个命令追加 SAS 令牌。By using Azure Active Directory, you can provide credentials once instead of having to append a SAS token to each command.

备注

在当前版本中,如果你打算在存储帐户之间复制 Blob,必须向每个源 URL 追加一个 SAS 令牌。In the current release, if you plan to copy blobs between storage accounts, you'll have to append a SAS token to each source URL. 只能在目标 URL 中省略 SAS 令牌。You can omit the SAS token only from the destination URL. 有关示例,请参阅在存储帐户之间复制 BlobFor examples, see Copy blobs between storage accounts.

若要使用 Azure AD 进行访问授权,请参阅使用 AzCopy 和 Azure Active Directory (Azure AD) 授权访问 BlobTo authorize access by using Azure AD, see Authorize access to blobs with AzCopy and Azure Active Directory (Azure AD).

选项 2:使用 SAS 令牌Option 2: Use a SAS token

可将 SAS 令牌追加到在 AzCopy 命令中使用的每个源或目标 URL。You can append a SAS token to each source or destination URL that use in your AzCopy commands.

此示例命令以递归方式将本地目录中的数据复制到 Blob 容器。This example command recursively copies data from a local directory to a blob container. 一个虚构的 SAS 令牌将追加到容器 URL 的末尾。A fictitious SAS token is appended to the end of the container URL.

azcopy copy "C:\local\path" "https://account.blob.core.chinacloudapi.cn/mycontainer1/?sv=2018-03-28&ss=bjqt&srt=sco&sp=rwddgcup&se=2019-05-01T05:01:17Z&st=2019-04-30T21:01:17Z&spr=https&sig=MGCXiyEzbtttkr3ewJIh2AR8KrghSy1DGM9ovN734bQF4%3D" --recursive=true

若要详细了解 SAS 令牌及其获取方式,请参阅使用共享访问签名 (SAS)To learn more about SAS tokens and how to obtain one, see Using shared access signatures (SAS).

备注

存储帐户的需要安全传输设置决定了与存储帐户的连接是否通过传输层安全 (TLS) 进行安全保护。The Secure transfer required setting of a storage account determines whether the connection to a storage account is secured with Transport Layer Security (TLS). 默认情况下,此设置处于启用状态。This setting is enabled by default.

传输数据Transfer data

对标识授权或获取 SAS 令牌后,即可开始传输数据。After you've authorized your identity or obtained a SAS token, you can begin transferring data.

若要查找示例命令,请参阅以下文章中的任何一篇。To find example commands, see any of these articles.

服务Service 文章Article
Azure Blob 存储Azure Blob Storage 将文件上传到 Azure Blob 存储Upload files to Azure Blob Storage
Azure Blob 存储Azure Blob Storage 从 Azure Blob 存储下载 BlobDownload blobs from Azure Blob Storage
Azure Blob 存储Azure Blob Storage 在 Azure 存储帐户之间复制 BlobCopy blobs between Azure storage accounts
Azure Blob 存储Azure Blob Storage 与 Azure Blob 存储同步Synchronize with Azure Blob Storage
Azure 文件Azure Files 使用 AzCopy 和文件存储传输数据Transfer data with AzCopy and file storage
Amazon S3Amazon S3 将数据从 Amazon S3 复制到 Azure 存储Copy data from Amazon S3 to Azure Storage
Google Cloud StorageGoogle Cloud Storage 将数据从 Google Cloud Storage 复制到 Azure 存储(预览版)Copy data from Google Cloud Storage to Azure Storage (preview)
Azure Stack 存储Azure Stack storage 使用 AzCopy 和 Azure Stack 存储传输数据Transfer data with AzCopy and Azure Stack storage

获取命令帮助Get command help

若要查看命令列表,请键入 azcopy -h 并按 ENTER 键。To see a list of commands, type azcopy -h and then press the ENTER key.

若要了解特定的命令,只需包含该命令的名称(例如:azcopy list -h)。To learn about a specific command, just include the name of the command (For example: azcopy list -h).

联机帮助Inline help

命令列表List of commands

下表列出了所有 AzCopy v10 命令。The following table lists all AzCopy v10 commands. 每个命令链接到参考文章。Each command links to a reference article.

命令Command 说明Description
azcopy benchazcopy bench 通过将测试数据上传到指定位置或从指定位置下载测试数据来运行性能基准测试。Runs a performance benchmark by uploading or downloading test data to or from a specified location.
azcopy copyazcopy copy 将源数据复制到目标位置Copies source data to a destination location
azcopy docazcopy doc 以 Markdown 格式生成工具的文档。Generates documentation for the tool in Markdown format.
azcopy envazcopy env 显示可配置 AzCopy 行为的环境变量。Shows the environment variables that can configure AzCopy's behavior.
azcopy jobsazcopy jobs 与管理作业相关的子命令。Subcommands related to managing jobs.
azcopy jobs cleanazcopy jobs clean 删除所有作业的所有日志和计划文件。Remove all log and plan files for all jobs.
azcopy jobs listazcopy jobs list 显示有关所有作业的信息。Displays information on all jobs.
azcopy jobs removeazcopy jobs remove 删除与给定作业 ID 关联的所有文件。Remove all files associated with the given job ID.
azcopy jobs resumeazcopy jobs resume 恢复具有给定作业 ID 的现有作业。Resumes the existing job with the given job ID.
azcopy jobs showazcopy jobs show 显示有关给定作业 ID 的详细信息。Shows detailed information for the given job ID.
azcopy loadazcopy load 与以特定格式传输数据相关的子命令。Subcommands related to transferring data in specific formats.
azcopy load clfsazcopy load clfs 将本地数据传输到容器中,并以 Microsoft 的 Avere Cloud FileSystem (CLFS) 格式存储。Transfers local data into a Container and stores it in Microsoft's Avere Cloud FileSystem (CLFS) format.
azcopy listazcopy list 列出给定资源中的实体。Lists the entities in a given resource.
azcopy loginazcopy login 登录到 Azure Active Directory 以访问 Azure 存储资源。Logs in to Azure Active Directory to access Azure Storage resources.
azcopy logoutazcopy logout 注销用户并终止对 Azure 存储资源的访问。Logs the user out and terminates access to Azure Storage resources.
azcopy makeazcopy make 创建容器或文件共享。Creates a container or file share.
azcopy removeazcopy remove 从 Azure 存储帐户中删除 blob 或文件。Delete blobs or files from an Azure storage account.
azcopy syncazcopy sync 将源位置复制到目标位置。Replicates the source location to the destination location.

在脚本中使用Use in a script

在一段时间后,AzCopy 下载链接将指向新版 AzCopy。Over time, the AzCopy download link will point to new versions of AzCopy. 如果脚本会下载 AzCopy,而更高版本的 AzCopy 会修改该脚本所依赖的功能,则该脚本可能会停止工作。If your script downloads AzCopy, the script might stop working if a newer version of AzCopy modifies features that your script depends upon.

若要避免这些问题,请获取当前 AzCopy 版本的静态(不会更改)链接。To avoid these issues, obtain a static (unchanging) link to the current version of AzCopy. 这样,每次运行脚本时,它都会下载相同的 AzCopy 版本。That way, your script downloads the same exact version of AzCopy each time that it runs.

若要获取该链接,请运行以下命令:To obtain the link, run this command:

操作系统Operating system 命令Command
LinuxLinux curl -s -D- https://aka.ms/downloadazcopy-v10-linux | grep ^Location
WindowsWindows (curl https://aka.ms/downloadazcopy-v10-windows -MaximumRedirection 0 -ErrorAction silentlycontinue).headers.location

备注

对于 Linux,tar 命令中的 --strip-components=1 会删除包含版本名称的顶级文件夹,并改为将二进制文件直接提取到当前文件夹中。For Linux, --strip-components=1 on the tar command removes the top-level folder that contains the version name, and instead extracts the binary directly into the current folder. 这样,只需要更新 wget URL,即可使用 azcopy 的新版本更新脚本。This allows the script to be updated with a new version of azcopy by only updating the wget URL.

该 URL 显示在此命令的输出中。The URL appears in the output of this command. 然后,脚本可以使用该 URL 下载 AzCopy。Your script can then download AzCopy by using that URL.

操作系统Operating system 命令Command
LinuxLinux wget -O azcopy_v10.tar.gz https://aka.ms/downloadazcopy-v10-linux && tar -xf azcopy_v10.tar.gz --strip-components=1
WindowsWindows Invoke-WebRequest https://azcopyvnext.azureedge.net/release20190517/azcopy_windows_amd64_10.1.2.zip -OutFile azcopyv10.zip <<Unzip here>>

转义 SAS 令牌中的特殊字符Escape special characters in SAS tokens

在扩展名为 .cmd 的批处理文件中,必须转义 SAS 令牌中显示的 % 字符。In batch files that have the .cmd extension, you'll have to escape the % characters that appear in SAS tokens. 为此,可将一个附加的 % 字符添加到 SAS 令牌字符串中的现有 % 字符旁边。You can do that by adding an additional % character next to existing % characters in the SAS token string.

使用 Jenkins 运行脚本Run scripts by using Jenkins

如果你打算使用 Jenkins 运行脚本,请确保将以下命令放在脚本的开头。If you plan to use Jenkins to run scripts, make sure to place the following command at the beginning of the script.

/usr/bin/keyctl new_session

在 Azure 存储资源管理器中使用Use in Azure Storage Explorer

存储资源管理器使用 AzCopy 执行其所有数据传输操作。Storage Explorer uses AzCopy to perform all of its data transfer operations. 如果你想要利用 AzCopy 的性能优势,但同时又偏好使用图形用户界面而不是命令行来与文件进行交互,则可以使用存储资源管理器You can use Storage Explorer if you want to leverage the performance advantages of AzCopy, but you prefer to use a graphical user interface rather than the command line to interact with your files.

存储资源管理器使用帐户密钥执行操作,因此在登录到存储资源管理器后,无需额外提供授权凭据。Storage Explorer uses your account key to perform operations, so after you sign into Storage Explorer, you won't need to provide additional authorization credentials.

配置、优化和修复Configure, optimize, and fix

查看以下任意资源:See any of the following resources:

使用以前的版本Use a previous version

如果需要使用旧版 AzCopy,请参阅以下链接之一:If you need to use the previous version of AzCopy, see either of the following links:

后续步骤Next steps

如有任何疑问、问题或一般反馈,请在 GitHub 页上提交。If you have questions, issues, or general feedback, submit them on GitHub page.