使用 Windows 上的 AzCopy 传输数据Transfer data with the AzCopy on Windows

AzCopy 是一个命令行实用程序,专用于通过旨在实现最佳性能的简单命令将数据复制到 Azure Blob、文件和表存储以及从这些位置复制数据。AzCopy is a command-line utility designed for copying data to/from Azure Blob, File, and Table storage, using simple commands designed for optimal performance. 可在文件系统和存储帐户之间或在存储帐户之间复制数据。You can copy data between a file system and a storage account, or between storage accounts.

Important

本文介绍了较旧版本的 AzCopy。This article describes an older version of AzCopy. 若要安装最新版本的 AzCopy,请参阅 AzCopy v10To install the most recent version of AzCopy, see AzCopy v10.

如果你选择安装较旧版本的 AzCopy (AzCopy v8.1),则有多个版本可供下载。If you choose to install the older version of AzCopy (AzCopy v8.1), then there are multiple versions that you can download. AzCopy on Windows 提供 Windows 样式的命令行选项。AzCopy on Windows offers Windows style command-line options. AzCopy on Linux 面向 Linux 平台,它提供 POSIX 样式的命令行选项。AzCopy on Linux targets Linux platforms offering POSIX style command-line options. 本文介绍 Windows 上的 AzCopy。This article covers AzCopy on Windows.

下载并安装 AzCopy (v8.1) on WindowsDownload and install AzCopy (v8.1) on Windows

下载 AzCopy (v8.1) on WindowsDownload the AzCopy (v8.1) on Windows.

AzCopy on Windows 8.1 发行说明AzCopy on Windows 8.1 Release Notes

  • 最新版本不再支持表服务。Table service is no longer supported in the latest version. 如果使用表导出功能,请下载 AzCopy 7.3 版本。If you use Table export feature, download AzCopy 7.3 version.
  • 使用 .NET Core 2.1 构建,现在所有 .NET Core 依赖项都打包在安装中。Built with .NET Core 2.1, and all .NET Core dependencies are now packaged in the installation.
  • 添加了 OAuth 身份验证支持。Added OAuth authentication support. 使用 azcopy login 通过 Azure Active Directory 登录。Use azcopy login to log on using Azure Active Directory.

带表支持的 Azcopy (v7.3)Azcopy with Table support (v7.3)

下载带表支持的 AzCopy 7.3Download the AzCopy 7.3 with Table support.

安装后步骤Post-installation Step

使用安装程序安装 Windows 上的 AzCopy 后,打开一个命令窗口,然后导航到计算机上的 AzCopy 安装目录,该位置存放着可执行的 AzCopy.exeAfter installing AzCopy on Windows using the installer, open a command window and navigate to the AzCopy installation directory on your computer - where the AzCopy.exe executable is located. 如果需要,可以将 AzCopy 安装位置添加到系统路径。If desired, you can add the AzCopy installation location to your system path. 默认情况下,AzCopy 安装到 %ProgramFiles(x86)%\Microsoft SDKs\Azure\AzCopy%ProgramFiles%\Microsoft SDKs\Azure\AzCopyBy default, AzCopy is installed to %ProgramFiles(x86)%\Microsoft SDKs\Azure\AzCopy or %ProgramFiles%\Microsoft SDKs\Azure\AzCopy.

编写第一条 AzCopy 命令Writing your first AzCopy command

AzCopy 命令的基本语法是:The basic syntax for AzCopy commands is:

AzCopy /Source:<source> /Dest:<destination> [Options]

以下示例演示了将数据复制到 Azure Blob、文件和表以及从这些位置复制数据的各种情况。The following examples demonstrate a variety of scenarios for copying data to and from Azure Blobs, Files, and Tables. 请参阅 AzCopy 参数 部分,了解每个示例中使用的参数的详细说明。Refer to the AzCopy Parameters section for a detailed explanation of the parameters used in each sample.

从 Blob 存储下载 BlobDownload blobs from Blob storage

让我们了解使用 AzCopy 下载 Blob 的多种方式。Let's look at several ways to download blobs using AzCopy.

下载单个 BlobDownload a single blob

AzCopy /Source:https://myaccount.blob.core.chinacloudapi.cn/mycontainer /Dest:C:\myfolder /SourceKey:key /Pattern:"abc.txt"

请注意,如果文件夹 C:\myfolder 不存在,AzCopy 会创建该文件夹并将 abc.txt 下载到新文件夹中。Note that if the folder C:\myfolder does not exist, AzCopy creates it and download abc.txt into the new folder.

从次要区域下载单个 BlobDownload a single blob from the secondary region

AzCopy /Source:https://myaccount-secondary.blob.core.chinacloudapi.cn/mynewcontainer /Dest:C:\myfolder /SourceKey:key /Pattern:"abc.txt"

请注意,必须启用读取访问权限异地冗余存储才能访问次要区域。Note that you must have read-access geo-redundant storage enabled to access the secondary region.

下载容器中的所有 BlobDownload all blobs in a container

AzCopy /Source:https://myaccount.blob.core.chinacloudapi.cn/mycontainer /Dest:C:\myfolder /SourceKey:key /S

假定指定的容器中存在以下 blob:Assume the following blobs reside in the specified container:

abc.txt
abc1.txt
abc2.txt
vd1\a.txt
vd1\abcd.txt

下载操作完成后,目录 C:\myfolder 中将包括以下文件:After the download operation, the directory C:\myfolder includes the following files:

C:\myfolder\abc.txt
C:\myfolder\abc1.txt
C:\myfolder\abc2.txt
C:\myfolder\vd1\a.txt
C:\myfolder\vd1\abcd.txt

如果未指定选项 /S,则不会下载任何 Blob。If you do not specify option /S, no blobs are downloaded.

下载具有特定前缀的 BlobDownload blobs with a specific prefix

AzCopy /Source:https://myaccount.blob.core.chinacloudapi.cn/mycontainer /Dest:C:\myfolder /SourceKey:key /Pattern:a /S

假定指定的容器中存在以下 blob。Assume the following blobs reside in the specified container. 将下载所有以前缀 a 开头的 Blob:All blobs beginning with the prefix a are downloaded:

abc.txt
abc1.txt
abc2.txt
xyz.txt
vd1\a.txt
vd1\abcd.txt

下载操作完成后,文件夹 C:\myfolder 中将包括以下文件:After the download operation, the folder C:\myfolder includes the following files:

C:\myfolder\abc.txt
C:\myfolder\abc1.txt
C:\myfolder\abc2.txt

前缀适用于虚拟目录,后者构成了 blob 名称的第一个部分。The prefix applies to the virtual directory, which forms the first part of the blob name. 在上面所示的示例中,虚拟目录与指定的前缀不匹配,因此不会下载它。In the example shown above, the virtual directory does not match the specified prefix, so it is not downloaded. 此外,如果未指定选项 /S,AzCopy 将不会下载任何 blob。In addition, if the option /S is not specified, AzCopy does not download any blobs.

将已导出文件的上次修改时间设置为与源 blob 相同Set the last-modified time of exported files to be same as the source blobs

AzCopy /Source:https://myaccount.blob.core.chinacloudapi.cn/mycontainer /Dest:C:\myfolder /SourceKey:key /MT

还可以根据 Blob 的上次修改时间将其从下载操作中排除。You can also exclude blobs from the download operation based on their last-modified time. 例如,如果希望排除其上次修改时间与目标文件相同或晚于目标文件的 blob,则添加 /XN 选项:For example, if you want to exclude blobs whose last modified time is the same or newer than the destination file, add the /XN option:

AzCopy /Source:https://myaccount.blob.core.chinacloudapi.cn/mycontainer /Dest:C:\myfolder /SourceKey:key /MT /XN

如果想要排除其上次修改时间与目标文件相同或早于目标文件的 Blob,请添加 /XO 选项:If you want to exclude blobs whose last modified time is the same or older than the destination file, add the /XO option:

AzCopy /Source:https://myaccount.blob.core.chinacloudapi.cn/mycontainer /Dest:C:\myfolder /SourceKey:key /MT /XO

将 Blob 上传到 Blob 存储Upload blobs to Blob storage

让我们了解使用 AzCopy 上传 Blob 的多种方式。Let's look at several ways to upload blobs using AzCopy.

上传单个 BlobUpload a single blob

AzCopy /Source:C:\myfolder /Dest:https://myaccount.blob.core.chinacloudapi.cn/mycontainer /DestKey:key /Pattern:"abc.txt"

如果指定的目标容器不存在,则 AzCopy 将创建它并将文件上传到其中。If the specified destination container does not exist, AzCopy creates it and uploads the file into it.

将单个 Blob 上传到虚拟目录Upload a single blob to a virtual directory

AzCopy /Source:C:\myfolder /Dest:https://myaccount.blob.core.chinacloudapi.cn/mycontainer/vd /DestKey:key /Pattern:abc.txt

如果指定的虚拟目录不存在,AzCopy 将上传文件以在 Blob 名称中包含虚拟目录(例如上例中的 vd/abc.txt)。 If the specified virtual directory does not exist, AzCopy uploads the file to include the virtual directory in its name (e.g., vd/abc.txt in the example above).

上传文件夹中的所有 BlobUpload all blobs in a folder

AzCopy /Source:C:\myfolder /Dest:https://myaccount.blob.core.chinacloudapi.cn/mycontainer /DestKey:key /S

指定选项 /S 会以递归方式将指定目录的内容上传到 Blob 存储,这意味着也会上传所有子文件夹及其文件。Specifying option /S uploads the contents of the specified directory to Blob storage recursively, meaning that all subfolders and their files are uploaded as well. 例如,假定以下文件位于文件夹 C:\myfolder 中:For instance, assume the following files reside in folder C:\myfolder:

C:\myfolder\abc.txt
C:\myfolder\abc1.txt
C:\myfolder\abc2.txt
C:\myfolder\subfolder\a.txt
C:\myfolder\subfolder\abcd.txt

上传操作完成后,容器中将包括以下文件:After the upload operation, the container includes the following files:

abc.txt
abc1.txt
abc2.txt
subfolder\a.txt
subfolder\abcd.txt

如果未指定选项 /S,AzCopy 不会以递归方式上传。If you do not specify option /S, AzCopy does not upload recursively. 上传操作完成后,容器中将包括以下文件:After the upload operation, the container includes the following files:

abc.txt
abc1.txt
abc2.txt

上传与特定模式匹配的 BlobUpload blobs matching a specific pattern

AzCopy /Source:C:\myfolder /Dest:https://myaccount.blob.core.chinacloudapi.cn/mycontainer /DestKey:key /Pattern:a* /S

假定以下文件存在于文件夹 C:\myfolder中:Assume the following files reside in folder C:\myfolder:

C:\myfolder\abc.txt
C:\myfolder\abc1.txt
C:\myfolder\abc2.txt
C:\myfolder\xyz.txt
C:\myfolder\subfolder\a.txt
C:\myfolder\subfolder\abcd.txt

上传操作完成后,容器中将包括以下文件:After the upload operation, the container includes the following files:

abc.txt
abc1.txt
abc2.txt
subfolder\a.txt
subfolder\abcd.txt

如果未指定选项 /S,AzCopy 仅上传不会在虚拟目录中驻留的 blob:If you do not specify option /S, AzCopy only uploads blobs that don't reside in a virtual directory:

C:\myfolder\abc.txt
C:\myfolder\abc1.txt
C:\myfolder\abc2.txt

指定目标 blob 的 MIME 内容类型Specify the MIME content type of a destination blob

默认情况下,AzCopy 将目标 blob 的内容类型设置为 application/octet-streamBy default, AzCopy sets the content type of a destination blob to application/octet-stream. 从 3.1.0 版开始,可以通过选项 /SetContentType:[content-type]显示指定内容类型。Beginning with version 3.1.0, you can explicitly specify the content type via the option /SetContentType:[content-type]. 此语法会在上传操作中设置所有 blob 的内容类型。This syntax sets the content type for all blobs in an upload operation.

AzCopy /Source:C:\myfolder\ /Dest:https://myaccount.blob.core.chinacloudapi.cn/myContainer/ /DestKey:key /Pattern:ab /SetContentType:video/mp4

如果指定不带任何值的 /SetContentType,AzCopy 会根据文件扩展名设置每个 Blob 或文件的内容类型。If you specify /SetContentType without a value, AzCopy sets each blob or file's content type according to its file extension.

AzCopy /Source:C:\myfolder\ /Dest:https://myaccount.blob.core.chinacloudapi.cn/myContainer/ /DestKey:key /Pattern:ab /SetContentType

复制 Blob 存储中的 BlobCopy blobs in Blob storage

让我们了解使用 AzCopy 将 Blob 从一个位置复制到另一个位置的多种方法。Let's look at several ways to copy blobs from one location to another using AzCopy.

将单个 Blob 从一个容器复制到同一存储帐户中的另一个容器Copy a single blob from one container to another within the same storage account

AzCopy /Source:https://myaccount.blob.core.chinacloudapi.cn/mycontainer1 /Dest:https://myaccount.blob.core.chinacloudapi.cn/mycontainer2 /SourceKey:key /DestKey:key /Pattern:abc.txt

在存储帐户内复制某个 blob 时,将执行服务器端复制操作。When you copy a blob within a Storage account, a server-side copy operation is performed.

将单个 Blob 从一个存储帐户复制到另一个存储帐户Copy a single blob from one storage account to another

AzCopy /Source:https://sourceaccount.blob.core.chinacloudapi.cn/mycontainer1 /Dest:https://destaccount.blob.core.chinacloudapi.cn/mycontainer2 /SourceKey:key1 /DestKey:key2 /Pattern:abc.txt

在跨存储帐户复制某个 blob 时,会执行服务器端复制操作。When you copy a blob across Storage accounts, a server-side copy operation is performed.

将单个 Blob 从次要区域复制到主要区域Copy a single blob from the secondary region to the primary region

AzCopy /Source:https://myaccount1-secondary.blob.core.chinacloudapi.cn/mynewcontainer1 /Dest:https://myaccount2.blob.core.chinacloudapi.cn/mynewcontainer2 /SourceKey:key1 /DestKey:key2 /Pattern:abc.txt

请注意,必须启用读取访问权限异地冗余存储才能访问辅助存储。Note that you must have read-access geo-redundant storage enabled to access secondary storage.

将单个 Blob 及其快照从一个存储帐户复制到另一个存储帐户Copy a single blob and its snapshots from one storage account to another

AzCopy /Source:https://sourceaccount.blob.core.chinacloudapi.cn/mycontainer1 /Dest:https://destaccount.blob.core.chinacloudapi.cn/mycontainer2 /SourceKey:key1 /DestKey:key2 /Pattern:abc.txt /Snapshot

复制操作完成后,目标容器中将包括 blob 及其快照。After the copy operation, the target container includes the blob and its snapshots. 假定上面的示例中的 blob 具有两个快照,则容器将包括以下 blob 和快照:Assuming the blob in the example above has two snapshots, the container includes the following blob and snapshots:

abc.txt
abc (2013-02-25 080757).txt
abc (2014-02-21 150331).txt

将容器中的所有 Blob 复制到另一个存储帐户Copy all blobs in a container to another storage account

AzCopy /Source:https://sourceaccount.blob.core.chinacloudapi.cn/mycontainer1 
/Dest:https://destaccount.blob.core.chinacloudapi.cn/mycontainer2 /SourceKey:key1 /DestKey:key2 /S

指定选项 /S 会以递归方式上传指定容器的内容。Specifying option /S uploads the contents of the specified container recursively. 有关详细信息和示例,请参阅上传文件夹中的所有 BlobSee Upload all blobs in a folder for more information and an example.

将 Blob 从一个存储帐户同步复制到另一个存储帐户Synchronously copy blobs from one storage account to another

默认情况下,AzCopy 以异步方式复制两个存储终结点之间的数据。AzCopy by default copies data between two storage endpoints asynchronously. 因此,复制操作使用空闲的带宽容量在后台运行,没有规定 blob 复制速率的 SLA,AzCopy 会定期检查复制状态直到复制完成或失败。Therefore, the copy operation runs in the background using spare bandwidth capacity that has no SLA in terms of how fast a blob is copied, and AzCopy periodically checks the copy status until the copying is completed or failed.

/SyncCopy 选项可确保复制操作的速度一致。The /SyncCopy option ensures that the copy operation gets consistent speed. AzCopy 通过下载 blob,将 blob 从指定的源复制到本地内存,然后将上传到 Blob 存储目标,以实现同步复制。AzCopy performs the synchronous copy by downloading the blobs to copy from the specified source to local memory, and then uploading them to the Blob storage destination.

AzCopy /Source:https://myaccount1.blob.core.chinacloudapi.cn/myContainer/ /Dest:https://myaccount2.blob.core.chinacloudapi.cn/myContainer/ /SourceKey:key1 /DestKey:key2 /Pattern:ab /SyncCopy

/SyncCopy 可能会产生额外的对外费用,建议在与源存储帐户所在的同一区域的 Azure VM 中使用该选项,以避免对外费用。/SyncCopy might generate additional egress cost compared to asynchronous copy, the recommended approach is to use this option in an Azure VM that is in the same region as your source storage account to avoid egress cost.

从文件存储下载文件Download files from File storage

让我们了解使用 AzCopy 下载文件的多种方式。Let's look at several ways to download files using AzCopy.

下载单个文件Download a single file

AzCopy /Source:https://myaccount.file.core.chinacloudapi.cn/myfileshare/myfolder1/ /Dest:C:\myfolder /SourceKey:key /Pattern:abc.txt

如果指定的源是 Azure 文件共享,则必须指定确切的文件名(例如 abc.txt)以下载单个文件,或者指定选项 /S 以递归方式下载该共享中的所有文件。If the specified source is an Azure file share, then you must either specify the exact file name, (e.g. abc.txt) to download a single file, or specify option /S to download all files in the share recursively. 尝试同时指定文件模式和选项 /S 将导致错误。Attempting to specify both a file pattern and option /S together results in an error.

下载目录中的所有文件Download all files in a directory

AzCopy /Source:https://myaccount.file.core.chinacloudapi.cn/myfileshare/ /Dest:C:\myfolder /SourceKey:key /S

请注意,不会下载空文件夹。Note that empty folders are not downloaded.

将文件上传到 Azure 文件共享Upload files to an Azure file share

让我们了解使用 AzCopy 上传文件的多种方式。Let's look at several ways to upload files using AzCopy.

上传单个文件Upload a single file

AzCopy /Source:C:\myfolder /Dest:https://myaccount.file.core.chinacloudapi.cn/myfileshare/ /DestKey:key /Pattern:abc.txt

上传文件夹中的所有文件Upload all files in a folder

AzCopy /Source:C:\myfolder /Dest:https://myaccount.file.core.chinacloudapi.cn/myfileshare/ /DestKey:key /S

请注意,不会上传空文件夹。Note that empty folders are not uploaded.

上传与特定模式匹配的文件Upload files matching a specific pattern

AzCopy /Source:C:\myfolder /Dest:https://myaccount.file.core.chinacloudapi.cn/myfileshare/ /DestKey:key /Pattern:ab* /S

复制文件存储中的文件Copy files in File storage

让我们了解使用 AzCopy 复制 Azure 文件共享中的文件的多种方式。Let's look at several ways to copy files in an Azure file share using AzCopy.

从一个文件共享复制到另一个文件共享Copy from one file share to another

AzCopy /Source:https://myaccount1.file.core.chinacloudapi.cn/myfileshare1/ /Dest:https://myaccount2.file.core.chinacloudapi.cn/myfileshare2/ /SourceKey:key1 /DestKey:key2 /S

跨文件共享复制某个文件时,将执行服务器端复制操作。When you copy a file across file shares, a server-side copy operation is performed.

从 Azure 文件共享复制到 Blob 存储Copy from an Azure file share to Blob storage

AzCopy /Source:https://myaccount1.file.core.chinacloudapi.cn/myfileshare/ /Dest:https://myaccount2.blob.core.chinacloudapi.cn/mycontainer/ /SourceKey:key1 /DestKey:key2 /S

将文件从文件共享复制到 Blob 时,将执行服务器端复制操作。When you copy a file from file share to blob, a server-side copy operation is performed.

将 Blob 从 Blob 存储复制到 Azure 文件共享Copy a blob from Blob storage to an Azure file share

AzCopy /Source:https://myaccount1.blob.core.chinacloudapi.cn/mycontainer/ /Dest:https://myaccount2.file.core.chinacloudapi.cn/myfileshare/ /SourceKey:key1 /DestKey:key2 /S

将文件从 Blob 复制到文件共享时,会执行服务器端复制操作。When you copy a file from a blob to a file share, a server-side copy operation is performed.

同步复制文件Synchronously copy files

可以指定选项 /SyncCopy,以从文件存储到文件存储、从文件存储到 Blob 存储以及从 Blob 存储到文件存储同步复制数据,AzCopy 通过将源数据下载到本地内存并再将其上传到目标以实现此同步操作。You can specify the /SyncCopy option to copy data from File Storage to File Storage, from File Storage to Blob Storage and from Blob Storage to File Storage synchronously, AzCopy does this by downloading the source data to local memory and upload it again to destination. 将应用标准传出费用。Standard egress cost applies.

AzCopy /Source:https://myaccount1.file.core.chinacloudapi.cn/myfileshare1/ /Dest:https://myaccount2.file.core.chinacloudapi.cn/myfileshare2/ /SourceKey:key1 /DestKey:key2 /S /SyncCopy

从文件存储复制到 Blob 存储时,默认的 Blob 类型是块 Blob;用户可以指定选项 /BlobType:page 以更改目标 Blob 类型。When copying from File storage to Blob storage, the default blob type is block blob; the user can specify the option /BlobType:page to change the destination blob type.

请注意,/SyncCopy 可能产生额外的数据传出费用,而异步复制则不会。Note that /SyncCopy might generate additional egress costs compared to asynchronous copy. 在与源存储帐户所在的同一区域的 Azure VM 中,建议使用此选项,避免产生数据传出费用。The recommended approach is to use this option in the Azure VM which is in the same region as your source storage account to avoid egress cost.

从表存储导出数据Export data from Table storage

让我们了解如何使用 AzCopy 从 Azure 表存储导出数据。Let's take a look at exporting data from Azure Table storage using AzCopy.

导出表Export a table

AzCopy /Source:https://myaccount.table.core.chinacloudapi.cn/myTable/ /Dest:C:\myfolder\ /SourceKey:key

AzCopy 将一个清单文件写入到指定的目标文件夹。AzCopy writes a manifest file to the specified destination folder. 在导入过程中使用该清单文件查找必要的数据文件并执行数据验证。The manifest file is used in the import process to locate the necessary data files and perform data validation. 默认情况下,清单文件使用以下命名约定:The manifest file uses the following naming convention by default:

<account name>_<table name>_<timestamp>.manifest

用户还可以指定选项 /Manifest:<manifest file name> 以设置清单文件名。User can also specify the option /Manifest:<manifest file name> to set the manifest file name.

AzCopy /Source:https://myaccount.table.core.chinacloudapi.cn/myTable/ /Dest:C:\myfolder\ /SourceKey:key /Manifest:abc.manifest

将表存储的导出拆分为多个文件Split an export from Table storage into multiple files

AzCopy /Source:https://myaccount.table.core.chinacloudapi.cn/mytable/ /Dest:C:\myfolder /SourceKey:key /S /SplitSize:100

AzCopy 在已拆分的数据文件名称中使用 卷索引 来区分多个文件。AzCopy uses a volume index in the split data file names to distinguish multiple files. 卷索引由两个部分组成:分区键范围索引拆分文件索引The volume index consists of two parts, a partition key range index and a split file index. 两个索引都是从零开始。Both indexes are zero-based.

如果用户未指定选项 /PKRS,则分区键范围索引是 0。The partition key range index is 0 if the user does not specify option /PKRS.

例如,假设 AzCopy 在用户指定选项 /SplitSize后生成了两个数据文件。For instance, suppose AzCopy generates two data files after the user specifies option /SplitSize. 生成的数据文件名称可能是:The resulting data file names might be:

myaccount_mytable_20140903T051850.8128447Z_0_0_C3040FE8.json
myaccount_mytable_20140903T051850.8128447Z_0_1_0AB9AC20.json

请注意,选项 /SplitSize 的最小可能值为 32 MB。Note that the minimum possible value for option /SplitSize is 32MB. 如果指定的目标是 Blob 存储,无论用户是否指定了选项 /SplitSize,AzCopy 会在数据文件的大小达到 blob 的大小限制 (200GB) 时拆分数据文件。If the specified destination is Blob storage, AzCopy splits the data file once its sizes reaches the blob size limitation (200GB), regardless of whether option /SplitSize has been specified by the user.

将表导出为 JSON 或 CSV 数据文件格式Export a table to JSON or CSV data file format

默认情况下,AzCopy 会将表导出为 JSON 数据文件。By default, AzCopy exports tables to JSON data files. 可以指定选项 /PayloadFormat:JSON|CSV,将表导出为 JSON 或 CSV。You can specify the option /PayloadFormat:JSON|CSV to export the tables as JSON or CSV.

AzCopy /Source:https://myaccount.table.core.chinacloudapi.cn/myTable/ /Dest:C:\myfolder\ /SourceKey:key /PayloadFormat:CSV

指定 CSV 有效负载格式时,AzCopy 还会为每个数据文件生成文件扩展名为 .schema.csv 的架构文件。When specifying the CSV payload format, AzCopy also generates a schema file with file extension .schema.csv for each data file.

并发导出表实体Export table entities concurrently

AzCopy /Source:https://myaccount.table.core.chinacloudapi.cn/myTable/ /Dest:C:\myfolder\ /SourceKey:key /PKRS:"aa#bb"

当用户指定了选项 /PKRS 时,AzCopy 会启动并发操作来导出实体。AzCopy starts concurrent operations to export entities when the user specifies option /PKRS. 每个操作导出一个分区键范围。Each operation exports one partition key range.

请注意,并发操作的数量还受选项 /NC的控制。Note that the number of concurrent operations is also controlled by option /NC. 当复制表实体时,AzCopy 使用核心处理器的数量作为 /NC 的默认值,即使未指定 /NC 也是如此。AzCopy uses the number of core processors as the default value of /NC when copying table entities, even if /NC was not specified. 当用户指定了选项 /PKRS时,AzCopy 使用以下两个值中的较小者(分区键范围和隐式或显式指定的并发操作数量)来确定要启动的并发操作的数量。When the user specifies option /PKRS, AzCopy uses the smaller of the two values - partition key ranges versus implicitly or explicitly specified concurrent operations - to determine the number of concurrent operations to start. 有关详细信息,请在命令行中键入 AzCopy /?:NCFor more details, type AzCopy /?:NC at the command line.

将表导出到 Blob 存储Export a table to Blob storage

AzCopy /Source:https://myaccount.table.core.chinacloudapi.cn/myTable/ /Dest:https://myaccount.blob.core.chinacloudapi.cn/mycontainer/ /SourceKey:key1 /Destkey:key2

AzCopy 使用以下命名约定在 blob 容器中生成一个 JSON 数据文件:AzCopy generates a JSON data file into the blob container with following naming convention:

<account name>_<table name>_<timestamp>_<volume index>_<CRC>.json

生成的 JSON 数据文件遵循最小元数据的负载格式。The generated JSON data file follows the payload format for minimal metadata. 有关此负载格式的详细信息,请参阅 Payload Format for Table Service Operations(表服务操作的有效负载格式)。For details on this payload format, see Payload Format for Table Service Operations.

请注意,将表导出到 blob 中时,AzCopy 会将表实体下载到本地临时数据文件,再将这些实体上传到 blob。Note that when exporting tables to blobs, AzCopy downloads the Table entities to local temporary data files and then uploads those entities to the blob. 这些临时数据文件会放入默认路径为“%LocalAppData%\Microsoft\Azure\AzCopy”的日志文件文件夹中,可指定选项 /Z:[journal-file-folder] 以更改日志文件文件夹的位置,从而更改临时数据文件的位置。These temporary data files are put into the journal file folder with the default path "%LocalAppData%\Microsoft\Azure\AzCopy", you can specify option /Z:[journal-file-folder] to change the journal file folder location and thus change the temporary data files location. 临时数据文件的大小由表实体的大小和使用选项 /SplitSize 指定的大小所决定,尽管本地磁盘中的临时数据文件在上传到 blob 后会被立即删除,但请确保在删除之前,拥有足够的本地磁盘空间来存储这些临时数据文件。The temporary data files' size is decided by your table entities' size and the size you specified with the option /SplitSize, although the temporary data file in local disk is deleted instantly once it has been uploaded to the blob, please make sure you have enough local disk space to store these temporary data files before they are deleted.

将数据导入表存储Import data into Table storage

让我们了解如何使用 AzCopy 将数据导入 Azure 表存储。Let's take a look at importing data into Azure Table storage using AzCopy.

导入表Import a table

AzCopy /Source:C:\myfolder\ /Dest:https://myaccount.table.core.chinacloudapi.cn/mytable1/ /DestKey:key /Manifest:"myaccount_mytable_20140103T112020.manifest" /EntityOperation:InsertOrReplace

选项 /EntityOperation 指示如何将实体插入到表中。The option /EntityOperation indicates how to insert entities into the table. 可能的值包括:Possible values are:

  • InsertOrSkip:跳过现有实体,或者插入新实体(如果它不存在于表中)。InsertOrSkip: Skips an existing entity or inserts a new entity if it does not exist in the table.
  • InsertOrMerge:合并现有实体,或者插入新实体(如果它不存在于表中)。InsertOrMerge: Merges an existing entity or inserts a new entity if it does not exist in the table.
  • InsertOrReplace:替换现有实体,或者插入新实体(如果它不存在于表中)。InsertOrReplace: Replaces an existing entity or inserts a new entity if it does not exist in the table.

请注意,在导入方案中不能指定选项 /PKRSNote that you cannot specify option /PKRS in the import scenario. 与导出方案不同(在导出方案中必须指定 /PKRS 选项才会启动并发操作),在导入表时,AzCopy 会默认启动并发操作。Unlike the export scenario, in which you must specify option /PKRS to start concurrent operations, AzCopy starts concurrent operations by default when you import a table. 启动的并发操作的默认数量与核心处理器的数量相等;但是,可以通过选项 /NC指定一个不同的并发数量。The default number of concurrent operations started is equal to the number of core processors; however, you can specify a different number of concurrent with option /NC. 有关详细信息,请在命令行中键入 AzCopy /?:NCFor more details, type AzCopy /?:NC at the command line.

请注意,AzCopy 仅支持导入 JSON 文件,不支持导入 CSV 文件。Note that AzCopy only supports importing for JSON, not CSV. AzCopy 不支持来自用户创建的 JSON 和清单文件的表导入。AzCopy does not support table imports from user-created JSON and manifest files. 这两类文件必须来自 AzCopy 表导出。Both of these files must come from an AzCopy table export. 若要避免错误,请不要修改导出的 JSON 或清单文件。To avoid errors, please do not modify the exported JSON or manifest file.

将实体从 Blob 存储导入表中Import entities into a table from Blob storage

假定 Blob 容器包含如下内容:表示 Azure 表的 JSON 文件及其随附的清单文件。Assume a Blob container contains the following: A JSON file representing an Azure Table and its accompanying manifest file.

myaccount_mytable_20140103T112020.manifest
myaccount_mytable_20140103T112020_0_0_0AF395F1DC42E952.json

可以使用 blob 容器中的清单文件运行以下命令将实体导入表中:You can run the following command to import entities into a table using the manifest file in that blob container:

AzCopy /Source:https://myaccount.blob.core.chinacloudapi.cn/mycontainer /Dest:https://myaccount.table.core.chinacloudapi.cn/mytable /SourceKey:key1 /DestKey:key2 /Manifest:"myaccount_mytable_20140103T112020.manifest" /EntityOperation:"InsertOrReplace"

AzCopy 的其他功能Other AzCopy features

让我们了解 AzCopy 的其他一些功能。Let's take a look at some other AzCopy features.

仅复制目标中不存在的数据Only copy data that doesn't exist in the destination

/XO/XN 参数分别用于阻止复制较早或较新的源资源。The /XO and /XN parameters allow you to exclude older or newer source resources from being copied, respectively. 如果只想复制目标中不存在的源资源,可以在 AzCopy 命令中指定这两个参数:If you only want to copy source resources that don't exist in the destination, you can specify both parameters in the AzCopy command:

/Source:http://myaccount.blob.core.chinacloudapi.cn/mycontainer /Dest:C:\myfolder /SourceKey: /S /XO /XN/Source:http://myaccount.blob.core.chinacloudapi.cn/mycontainer /Dest:C:\myfolder /SourceKey: /S /XO /XN

/Source:C:\myfolder /Dest:http://myaccount.file.core.chinacloudapi.cn/myfileshare /DestKey: /S /XO /XN/Source:C:\myfolder /Dest:http://myaccount.file.core.chinacloudapi.cn/myfileshare /DestKey: /S /XO /XN

/Source:http://myaccount.blob.core.chinacloudapi.cn/mycontainer /Dest:http://myaccount.blob.core.chinacloudapi.cn/mycontainer1 /SourceKey: /DestKey: /S /XO /XN/Source:http://myaccount.blob.core.chinacloudapi.cn/mycontainer /Dest:http://myaccount.blob.core.chinacloudapi.cn/mycontainer1 /SourceKey: /DestKey: /S /XO /XN

注意,当源或目标为表时,则不支持此操作。Note that this is not supported when either the source or destination is a table.

使用响应文件指定命令行参数Use a response file to specify command-line parameters

AzCopy /@:"C:\responsefiles\copyoperation.txt"

可以在响应文件中包括任何 AzCopy 命令行参数。You can include any AzCopy command-line parameters in a response file. AzCopy 会像处理在命令行上指定的参数一样处理该文件中的参数,使用该文件的内容执行直接替换。AzCopy processes the parameters in the file as if they had been specified on the command line, performing a direct substitution with the contents of the file.

假定有一个名为 copyoperation.txt 的响应文件,其中包含以下行:Assume a response file named copyoperation.txt, that contains the following lines. 可以在同一行或多行中指定Each AzCopy parameter can be specified on a single line

/Source:http://myaccount.blob.core.chinacloudapi.cn/mycontainer /Dest:C:\myfolder /SourceKey: /S /Y/Source:http://myaccount.blob.core.chinacloudapi.cn/mycontainer /Dest:C:\myfolder /SourceKey: /S /Y

每个 AzCopy 参数:or on separate lines:

/Source:http://myaccount.blob.core.chinacloudapi.cn/mycontainer
/Dest:C:\myfolder
/SourceKey:<sourcekey>
/S
/Y

如果将参数拆分到两行(如此处所示的 /sourcekey 参数),AzCopy 将会失败:AzCopy fails if you split the parameter across two lines, as shown here for the /sourcekey parameter:

http://myaccount.blob.core.chinacloudapi.cn/mycontainer C:\myfolder /sourcekey: http://myaccount.blob.core.chinacloudapi.cn/mycontainer C:\myfolder /sourcekey: /S /Y/S /Y

使用多个响应文件指定命令行参数Use multiple response files to specify command-line parameters

假定有一个名为 source.txt 的响应文件,该文件指定了一个源容器:Assume a response file named source.txt that specifies a source container:

/Source:http://myaccount.blob.core.chinacloudapi.cn/mycontainer/Source:http://myaccount.blob.core.chinacloudapi.cn/mycontainer

有一个名为 dest.txt 的响应文件,该文件在文件系统中指定了一个目标文件夹:And a response file named dest.txt that specifies a destination folder in the file system:

/Dest:C:\myfolder

并且有一个名为 options.txt 的响应文件,该文件指定了 AzCopy 的选项:And a response file named options.txt that specifies options for AzCopy:

/S /Y

要使用这些响应文件(都位于目录 C:\responsefiles中)调用 AzCopy,请使用以下命令:To call AzCopy with these response files, all of which reside in a directory C:\responsefiles, use this command:

AzCopy /@:"C:\responsefiles\source.txt" /@:"C:\responsefiles\dest.txt" /SourceKey:<sourcekey> /@:"C:\responsefiles\options.txt"   

AzCopy 会像在命令行上包括了所有单个参数一样来处理此命令:AzCopy processes this command just as it would if you included all of the individual parameters on the command line:

AzCopy /Source:http://myaccount.blob.core.chinacloudapi.cn/mycontainer /Dest:C:\myfolder /SourceKey:<sourcekey> /S /Y

指定共享访问签名 (SAS)Specify a shared access signature (SAS)

AzCopy /Source:https://myaccount.blob.core.chinacloudapi.cn/mycontainer1 /Dest:https://myaccount.blob.core.chinacloudapi.cn/mycontainer2 /SourceSAS:SAS1 /DestSAS:SAS2 /Pattern:abc.txt

此外,还可以在容器 URI 上指定一个 SAS:You can also specify a SAS on the container URI:

AzCopy /Source:https://myaccount.blob.core.chinacloudapi.cn/mycontainer1/?SourceSASToken /Dest:C:\myfolder /S

日志文件文件夹Journal file folder

每次向 AzCopy 发出命令时,它都会检查默认文件夹中是否存在日志文件,或者通过此选项指定的文件夹中是否存在日志文件。Each time you issue a command to AzCopy, it checks whether a journal file exists in the default folder, or whether it exists in a folder that you specified via this option. 如果这两个位置中都不存在日志文件,AzCopy 则会将操作视为新操作并生成一个新的日志文件。If the journal file does not exist in either place, AzCopy treats the operation as new and generates a new journal file.

如果存在日志文件,AzCopy 会检查输入的命令行是否与该日志文件中的命令行相匹配。If the journal file does exist, AzCopy checks whether the command line that you input matches the command line in the journal file. 如果两个命令行相匹配,AzCopy 会恢复未完成的操作。If the two command lines match, AzCopy resumes the incomplete operation. 如果它们不匹配,系统会提示用户是选择覆盖该日志文件以启动新操作,还是取消当前操作。If they do not match, you are prompted to either overwrite the journal file to start a new operation, or to cancel the current operation.

如果想要为日志文件使用默认位置:If you want to use the default location for the journal file:

AzCopy /Source:C:\myfolder /Dest:https://myaccount.blob.core.chinacloudapi.cn/mycontainer /DestKey:key /Z

如果省略了选项 /Z,或者指定了选项 /Z 但未指定文件夹路径(如上所示),AzCopy 则会在默认位置中创建日志文件,默认位置为 %SystemDrive%\Users\%username%\AppData\Local\Microsoft\Azure\AzCopyIf you omit option /Z, or specify option /Z without the folder path, as shown above, AzCopy creates the journal file in the default location, which is %SystemDrive%\Users\%username%\AppData\Local\Microsoft\Azure\AzCopy. 如果日志文件已存在,AzCopy 则将继续根据日志文件恢复操作。If the journal file already exists, then AzCopy resumes the operation based on the journal file.

如果想要为日志文件指定自定义位置:If you want to specify a custom location for the journal file:

AzCopy /Source:C:\myfolder /Dest:https://myaccount.blob.core.chinacloudapi.cn/mycontainer /DestKey:key /Z:C:\journalfolder\

如果日志文件尚不存在,此示例将创建日志文件。This example creates the journal file if it does not already exist. 如果它已存在,AzCopy 则根据该日志文件恢复操作。If it does exist, then AzCopy resumes the operation based on the journal file.

如果想要恢复 AzCopy 操作:If you want to resume an AzCopy operation:

AzCopy /Z:C:\journalfolder\

此示例将恢复可能没有完成的上一操作。This example resumes the last operation, which may have failed to complete.

生成日志文件Generate a log file

AzCopy /Source:C:\myfolder /Dest:https://myaccount.blob.core.chinacloudapi.cn/mycontainer /DestKey:key /V

如果指定了选项 /V 但未提供详细日志的文件路径,AzCopy 则将在默认位置中创建日志文件,默认位置为 %SystemDrive%\Users\%username%\AppData\Local\Microsoft\Azure\AzCopyIf you specify option /V without providing a file path to the verbose log, then AzCopy creates the log file in the default location, which is %SystemDrive%\Users\%username%\AppData\Local\Microsoft\Azure\AzCopy.

或者,可以在自定义位置中创建日志文件:Otherwise, you can create an log file in a custom location:

AzCopy /Source:C:\myfolder /Dest:https://myaccount.blob.core.chinacloudapi.cn/mycontainer /DestKey:key /V:C:\myfolder\azcopy1.log

请注意,如果在选项 /V 后指定了相对路径,例如 /V:test/azcopy1.log,则会在当前工作目录中名为 test 的子文件夹内创建详细日志。Note that if you specify a relative path following option /V, such as /V:test/azcopy1.log, then the verbose log is created in the current working directory within a subfolder named test.

指定要启动的并发操作的数量Specify the number of concurrent operations to start

选项 /NC 指定并发复制操作的数量。Option /NC specifies the number of concurrent copy operations. 默认情况下,AzCopy 会启动一定数量的并发操作以提高数据传输吞吐量。By default, AzCopy starts a certain number of concurrent operations to increase the data transfer throughput. 对于表操作,并发操作的数量与所拥有的处理器数相等。For Table operations, the number of concurrent operations is equal to the number of processors you have. 对于 Blob 和文件操作,并发操作数等于所拥有的处理器数的 8 倍。For Blob and File operations, the number of concurrent operations is equal 8 times the number of processors you have. 如果正在低带宽网络中运行 AzCopy,则可为 /NC 指定较低的数量以避免由于资源争用所导致的故障。If you are running AzCopy across a low-bandwidth network, you can specify a lower number for /NC to avoid failure caused by resource competition.

针对 Azure 存储模拟器运行 AzCopyRun AzCopy against the Azure Storage Emulator

可针对 Blob 的 Azure 存储模拟器运行 AzCopy:You can run AzCopy against the Azure Storage Emulator for blobs:

AzCopy /Source:https://127.0.0.1:10000/myaccount/mycontainer/ /Dest:C:\myfolder /SourceKey:key /SourceType:Blob /S

还可以针对表运行 AzCopy:You can also run it for tables:

AzCopy /Source:https://127.0.0.1:10002/myaccount/mytable/ /Dest:C:\myfolder /SourceKey:key /SourceType:Table

自动确定 Blob 的内容类型Automatically determine Content Type of a Blob

AzCopy 根据将内容类型存储到文件扩展名映射的 JSON 文件确定 blob 的内容类型。AzCopy determines content type of a blob based on a JSON file that stores content type to file extension mapping. 此 JSON 文件命名为 AzCopyConfig.json,并且位于 AzCopy 目录中。This JSON file is named AzCopyConfig.json, and is located in the AzCopy directory. 如果你的文件类型不在列表中,可以将映射追加到 JSON 文件中:If you have a file type that is not in the list you can append the mapping to the JSON file:

{
  "MIMETypeMapping": {
    ".myext": "text/mycustomtype",
    .
    .
  }
}

AzCopy 参数AzCopy Parameters

以下描述了 AzCopy 的参数。Parameters for AzCopy are described below. 还可以从命令行键入下列命令之一以获取如何使用 AzCopy 的帮助信息:You can also type one of the following commands from the command line for help in using AzCopy:

  • 若要获取 AzCopy 的详细命令行帮助信息,请键入: AzCopy /?For detailed command-line help for AzCopy: AzCopy /?
  • 若要获取任何 AzCopy 参数的详细帮助信息,请键入: AzCopy /?:SourceKeyFor detailed help with any AzCopy parameter: AzCopy /?:SourceKey
  • 若要获取命令行示例,请键入: AzCopy /?:SampleFor command-line examples: AzCopy /?:Sample

/Source:"source"/Source:"source"

指定要从中复制数据的源。Specifies the source data from which to copy. 源可以是文件系统目录、blob 容器、blob 虚拟目录、存储文件共享、存储文件目录或 Azure 表。The source can be a file system directory, a blob container, a blob virtual directory, a storage file share, a storage file directory, or an Azure table.

适用于: Blob、文件、表Applicable to: Blobs, Files, Tables

/Dest:"destination"/Dest:"destination"

指定要复制到的目标。Specifies the destination to copy to. 目标可以是文件系统目录、blob 容器、blob 虚拟目录、存储文件共享、存储文件目录或 Azure 表。The destination can be a file system directory, a blob container, a blob virtual directory, a storage file share, a storage file directory, or an Azure table.

适用于: Blob、文件、表Applicable to: Blobs, Files, Tables

/Pattern:"file-pattern"/Pattern:"file-pattern"

指定文件模式,它指示要复制哪些文件。Specifies a file pattern that indicates which files to copy. /Pattern 参数的行为是由源数据的位置以及是否存在递归模式选项决定的。The behavior of the /Pattern parameter is determined by the location of the source data, and the presence of the recursive mode option. 递归模式是通过选项 /S 指定的。Recursive mode is specified via option /S.

如果指定的源是文件系统中的一个目录,则标准通配符将生效,并且会将该目录中的文件与提供的文件模式进行匹配。If the specified source is a directory in the file system, then standard wildcards are in effect, and the file pattern provided is matched against files within the directory. 如果指定了选项 /S,则 AzCopy 还会将该目录下的任何子文件夹中的所有文件与指定模式进行匹配。If option /S is specified, then AzCopy also matches the specified pattern against all files in any subfolders beneath the directory.

如果指定的源是一个 blob 容器或虚拟目录,则不会应用通配符。If the specified source is a blob container or virtual directory, then wildcards are not applied. 如果指定了选项 /S,则 AzCopy 会将指定的文件模式解释为 blob 前缀。If option /S is specified, then AzCopy interprets the specified file pattern as a blob prefix. 如果未指定选项 /S,则 AzCopy 会将确切的 blob 名称与文件模式进行匹配。If option /S is not specified, then AzCopy matches the file pattern against exact blob names.

如果指定的源是 Azure 文件共享,则必须指定确切的文件名(如 abc.txt)以复制单个文件,或指定选项 /S 以递归方式复制该共享中的所有文件。If the specified source is an Azure file share, then you must either specify the exact file name, (e.g. abc.txt) to copy a single file, or specify option /S to copy all files in the share recursively. 尝试同时指定文件模式和选项 /S 会导致错误。Attempting to specify both a file pattern and option /S together results in an error.

当 /Source 是 blob 容器或 blob 虚拟目录时,AzCopy 使用区分大小写匹配,而在所有其他情况下则使用不区分大小写匹配。AzCopy uses case-sensitive matching when the /Source is a blob container or blob virtual directory, and uses case-insensitive matching in all the other cases.

未指定文件模式时使用的默认文件模式为 The default file pattern used when no file pattern is specified is . (对于文件系统位置)或空前缀(对于 Azure 存储位置)。for a file system location or an empty prefix for an Azure Storage location. 不支持指定多个文件模式。Specifying multiple file patterns is not supported.

适用于: Blob、文件Applicable to: Blobs, Files

/DestKey:"storage-key"/DestKey:"storage-key"

指定目标资源的存储帐户密钥。Specifies the storage account key for the destination resource.

适用于: Blob、文件、表Applicable to: Blobs, Files, Tables

/DestSAS:"sas-token"/DestSAS:"sas-token"

指定对目标具有读写权限的共享访问签名 (SAS)(如果适用)。Specifies a Shared Access Signature (SAS) with READ and WRITE permissions for the destination (if applicable). 请将 SAS 用双引号括起来,因为它可能包含特殊的命令行字符。Surround the SAS with double quotes, as it may contains special command-line characters.

如果目标资源是 blob 容器、文件共享或表,则可以指定此选项,后跟 SAS 令牌,或者可以将 SAS 指定为目标 blob 容器、文件共享或表 URI 的一部分,而不使用此选项。If the destination resource is a blob container, file share or table, you can either specify this option followed by the SAS token, or you can specify the SAS as part of the destination blob container, file share or table's URI, without this option.

如果源和目标都是 blob,则目标 blob 必须与源 blob 位于同一个存储帐户中。If the source and destination are both blobs, then the destination blob must reside within the same storage account as the source blob.

适用于: Blob、文件、表Applicable to: Blobs, Files, Tables

/SourceKey:"storage-key"/SourceKey:"storage-key"

指定源资源的存储帐户密钥。Specifies the storage account key for the source resource.

适用于: Blob、文件、表Applicable to: Blobs, Files, Tables

/SourceSAS:"sas-token"/SourceSAS:"sas-token"

指定对源具有“读取”和“列出”权限的共享访问签名(如果适用)。Specifies a Shared Access Signature with READ and LIST permissions for the source (if applicable). 请将 SAS 用双引号括起来,因为它可能包含特殊的命令行字符。Surround the SAS with double quotes, as it may contains special command-line characters.

如果源资源是 blob 容器,并且既未提供密钥又未提供 SAS,则可以通过匿名访问读取 blob 容器。If the source resource is a blob container, and neither a key nor a SAS is provided, then the blob container is read via anonymous access.

如果源是文件共享或表,必须提供一个键或某一 SAS。If the source is a file share or table, a key or a SAS must be provided.

适用于: Blob、文件、表Applicable to: Blobs, Files, Tables

/S/S

指定复制操作的递归模式。Specifies recursive mode for copy operations. 在递归模式下,AzCopy 会复制与指定的文件模式相匹配的所有 blob 或文件,包括子文件夹中的对象。In recursive mode, AzCopy copies all blobs or files that match the specified file pattern, including those in subfolders.

适用于: Blob、文件Applicable to: Blobs, Files

/BlobType:"block" | "page" | "append"/BlobType:"block" | "page" | "append"

指定目标 Blob 是块 Blob、页 Blob 还是追加 Blob。Specifies whether the destination blob is a block blob, a page blob, or an append blob. 仅在要上传 Blob 时,此选项才适用。This option is applicable only when you are uploading a blob. 否则会发生错误。Otherwise, an error is generated. 如果目标是一个 Blob 并且未指定此选项,则默认情况下 AzCopy 会创建块 Blob。If the destination is a blob and this option is not specified, by default, AzCopy creates a block blob.

适用于: BlobApplicable to: Blobs

/CheckMD5/CheckMD5

计算已下载的数据的 MD5 哈希,并验证存储在 blob 或文件的 Content-MD5 属性中的 MD5 哈希是否与计算得到的哈希匹配。Calculates an MD5 hash for downloaded data and verifies that the MD5 hash stored in the blob or file's Content-MD5 property matches the calculated hash. 如果值不匹配,AzCopy 将无法下载数据。If the values do not match, AzCopy will fail to download the data. 默认情况下,MD5 检查处于关闭状态,因此,必须指定此选项以在下载数据时执行 MD5 检查。The MD5 check is turned off by default, so you must specify this option to perform the MD5 check when downloading data.

请注意,Azure 存储不保证为 blob 或文件所存储的 MD5 哈希是最新的。Note that Azure Storage doesn't guarantee that the MD5 hash stored for the blob or file is up-to-date. 每当 blob 或文件被修改时,客户端都需要负责对 MD5 进行更新。It is client's responsibility to update the MD5 whenever the blob or file is modified. 对于磁盘映像(托管或非托管磁盘),Azure VM 不会随磁盘内容的更改更新 MD5 值,因此,在下载磁盘映像时,/CheckMD5 将引发错误。In the case of disk images (managed or unmanaged disks), Azure VMs do not update the MD5 value as the disk contents change, hence /CheckMD5 will throw an error when downloading disk images.

在将 Azure blob 或文件上传到服务后,AzCopy v8 始终会为其设置 Content-MD5 属性。AzCopy v8 always sets the Content-MD5 property for an Azure blob or file after uploading it to the service.

适用于: Blob、文件Applicable to: Blobs, Files

/Snapshot/Snapshot

指示是否传输快照。Indicates whether to transfer snapshots. 只有当源是 blob 时,此选项才有效。This option is only valid when the source is a blob.

传输的 Blob 快照会按以下格式重命名:blob-name (snapshot-time).extensionThe transferred blob snapshots are renamed in this format: blob-name (snapshot-time).extension

默认情况下,不会复制快照。By default, snapshots are not copied.

适用于: BlobApplicable to: Blobs

/V:[verbose-log-file]/V:[verbose-log-file]

将详细的状态消息输出到日志文件中。Outputs verbose status messages into a log file.

默认情况下,详细日志文件在 %LocalAppData%\Microsoft\Azure\AzCopy中会被命名为 AzCopyVerbose.log。By default, the verbose log file is named AzCopyVerbose.log in %LocalAppData%\Microsoft\Azure\AzCopy. 如果为此选项指定了现有的文件位置,详细日志会追加到该文件中。If you specify an existing file location for this option, the verbose log is appended to that file.

适用于: Blob、文件、表Applicable to: Blobs, Files, Tables

/Z:[journal-file-folder]/Z:[journal-file-folder]

指定用于恢复某一操作的日志文件文件夹。Specifies a journal file folder for resuming an operation.

AzCopy 始终支持对被中断的操作进行恢复。AzCopy always supports resuming if an operation has been interrupted.

如果未指定此选项,或者未指定其文件夹路径,AzCopy 则会在默认位置中创建日志文件,默认位置为 %LocalAppData%\Microsoft\Azure\AzCopy。If this option is not specified, or it is specified without a folder path, then AzCopy creates the journal file in the default location, which is %LocalAppData%\Microsoft\Azure\AzCopy.

每次向 AzCopy 发出命令时,它都会检查默认文件夹中是否存在日志文件,或者通过此选项指定的文件夹中是否存在日志文件。Each time you issue a command to AzCopy, it checks whether a journal file exists in the default folder, or whether it exists in a folder that you specified via this option. 如果这两个位置中都不存在日志文件,AzCopy 则会将操作视为新操作并生成一个新的日志文件。If the journal file does not exist in either place, AzCopy treats the operation as new and generates a new journal file.

如果存在日志文件,AzCopy 会检查输入的命令行是否与该日志文件中的命令行相匹配。If the journal file does exist, AzCopy checks whether the command line that you input matches the command line in the journal file. 如果两个命令行相匹配,AzCopy 会恢复未完成的操作。If the two command lines match, AzCopy resumes the incomplete operation. 如果它们不匹配,系统会提示用户是选择覆盖该日志文件以启动新操作,还是取消当前操作。If they do not match, you are prompted to either overwrite the journal file to start a new operation, or to cancel the current operation.

成功完成操作后,会删除该日志文件。The journal file is deleted upon successful completion of the operation.

请注意,不支持通过由以前版本的 AzCopy 创建的日志文件来恢复操作。Note that resuming an operation from a journal file created by a previous version of AzCopy is not supported.

适用于: Blob、文件、表Applicable to: Blobs, Files, Tables

/@:"parameter-file"/@:"parameter-file"

指定包含参数的文件。Specifies a file that contains parameters. AzCopy 会像处理在命令行上指定参数一样处理文件中的参数。AzCopy processes the parameters in the file just as if they had been specified on the command line.

在响应文件中,可以在单个行上指定多个参数,也可以将每个参数指定在其单独的行上。In a response file, you can either specify multiple parameters on a single line, or specify each parameter on its own line. 请注意,单个参数不能跨多个行。Note that an individual parameter cannot span multiple lines.

响应文件可包括以 # 符号开头的命令行。Response files can include comments lines that begin with the # symbol.

可以指定多个响应文件。You can specify multiple response files. 但请注意,AzCopy 不支持嵌套的响应文件。However, note that AzCopy does not support nested response files.

适用于: Blob、文件、表Applicable to: Blobs, Files, Tables

/Y/Y

取消所有的 AzCopy 确认提示。Suppresses all AzCopy confirmation prompts. 未指定 /XO 和 /XN 时,此选项还允许只写 SAS 令牌用于数据上传方案。This option also allows the use of write-only SAS tokens for data upload scenarios, when /XO and /XN are not specified.

适用于: Blob、文件、表Applicable to: Blobs, Files, Tables

/L/L

仅指定列出操作;不复制任何数据。Specifies a listing operation only; no data is copied.

AzCopy 使用此选项解释为在没有此选项 /L 的情况下,模拟运行命令行,并对复制的对象数量进行计数,可以同时指定选项 /V 以检查哪些对象要复制到详细日志中。AzCopy interprets the using of this option as a simulation for running the command line without this option /L and counts how many objects are copied, you can specify option /V at the same time to check which objects are copied in the verbose log.

此选项的行为也由源数据的位置、是否存在递归模式选项 /S 以及文件模式选项 /Pattern 所决定。The behavior of this option is also determined by the location of the source data and the presence of the recursive mode option /S and file pattern option /Pattern.

使用此选项时,AzCopy 需要此源位置的列出和读取权限。AzCopy requires LIST and READ permission of this source location when using this option.

适用于: Blob、文件Applicable to: Blobs, Files

/MT/MT

将下载的文件的上次修改时间设置为与源 blob 或文件的上次修改时间相同。Sets the downloaded file's last-modified time to be the same as the source blob or file's.

适用于: Blob、文件Applicable to: Blobs, Files

/XN/XN

排除较新的源资源。Excludes a newer source resource. 如果源的上次修改时间同于或晚于目标,不会复制该资源。The resource is not copied if the last modified time of the source is the same or newer than destination.

适用于: Blob、文件Applicable to: Blobs, Files

/XO/XO

排除较旧的源资源。Excludes an older source resource. 如果源的上次修改时间同于或早于目标,不会复制该资源。The resource is not copied if the last modified time of the source is the same or older than destination.

适用于: Blob、文件Applicable to: Blobs, Files

/A/A

仅上传设置了存档属性的文件。Uploads only files that have the Archive attribute set.

适用于: Blob、文件Applicable to: Blobs, Files

/IA:[RASHCNETOI]/IA:[RASHCNETOI]

仅上传设置了任何指定属性的文件。Uploads only files that have any of the specified attributes set.

可用的属性包括:Available attributes include:

  • R 表示只读文件R = Read-only files
  • A 表示用于存档的文件A = Files ready for archiving
  • S 表示系统文件S = System files
  • H 表示隐藏文件H = Hidden files
  • C 表示压缩文件C = Compressed files
  • N 表示普通文件N = Normal files
  • E 表示加密文件E = Encrypted files
  • T 表示临时文件T = Temporary files
  • O 表示脱机文件O = Offline files
  • I 表示未编制索引的文件I = Non-indexed files

适用于: Blob、文件Applicable to: Blobs, Files

/XA:[RASHCNETOI]/XA:[RASHCNETOI]

排除设置了任何指定属性的文件。Excludes files that have any of the specified attributes set.

可用的属性包括:Available attributes include:

  • R 表示只读文件R = Read-only files
  • A 表示用于存档的文件A = Files ready for archiving
  • S 表示系统文件S = System files
  • H 表示隐藏文件H = Hidden files
  • C 表示压缩文件C = Compressed files
  • N 表示普通文件N = Normal files
  • E 表示加密文件E = Encrypted files
  • T 表示临时文件T = Temporary files
  • O 表示脱机文件O = Offline files
  • I 表示未编制索引的文件I = Non-indexed files

适用于: Blob、文件Applicable to: Blobs, Files

/Delimiter:"delimiter"/Delimiter:"delimiter"

指示用于分隔 blob 名称中的虚拟目录的分隔符字符。Indicates the delimiter character used to delimit virtual directories in a blob name.

默认情况下,AzCopy 使用 / 作为分隔符字符。By default, AzCopy uses / as the delimiter character. 不过,AzCopy 支持使用任何常见字符(例如 @、# 或 %)作为分隔符。However, AzCopy supports using any common character (such as @, #, or %) as a delimiter. 如果需要在命令行上包括这些特殊字符之一,请将文件名用双引号引起来。If you need to include one of these special characters on the command line, enclose the file name with double quotes.

此选项仅适用于下载 blob。This option is only applicable for downloading blobs.

适用于: BlobApplicable to: Blobs

/NC:"number-of-concurrent-operations"/NC:"number-of-concurrent-operations"

指定并发操作的数量。Specifies the number of concurrent operations.

默认情况下,AzCopy 会启动一定数量的并发操作以提高数据传输吞吐量。AzCopy by default starts a certain number of concurrent operations to increase the data transfer throughput. 请注意,在低带宽环境中,大量的并发操作可能会压垮网络连接,并且会阻碍操作彻底完成。Note that large number of concurrent operations in a low-bandwidth environment may overwhelm the network connection and prevent the operations from fully completing. 请根据实际可用的网络带宽限制并发操作。Throttle concurrent operations based on actual available network bandwidth.

并发操作的上限为 512。The upper limit for concurrent operations is 512.

适用于: Blob、文件、表Applicable to: Blobs, Files, Tables

/SourceType:"Blob" | "Table"/SourceType:"Blob" | "Table"

指定 source 资源是本地开发环境中可用的一个 Blob,在存储模拟器中运行。Specifies that the source resource is a blob available in the local development environment, running in the storage emulator.

适用于: Blob、表Applicable to: Blobs, Tables

/DestType:"Blob" | "Table"/DestType:"Blob" | "Table"

指定 destination 资源是本地开发环境中可用的一个 Blob,在存储模拟器中运行。Specifies that the destination resource is a blob available in the local development environment, running in the storage emulator.

适用于: Blob、表Applicable to: Blobs, Tables

/PKRS:"key1#key2#key3#..."/PKRS:"key1#key2#key3#..."

对分区键范围进行拆分以便并行导出表数据,这可以提高导出操作的速度。Splits the partition key range to enable exporting table data in parallel, which increases the speed of the export operation.

如果未指定此选项,AzCopy 将使用单个线程来导出表实体。If this option is not specified, then AzCopy uses a single thread to export table entities. 例如,如果用户指定了 /PKRS:"aa#bb",AzCopy 则将启动三个并发操作。For example, if the user specifies /PKRS:"aa#bb", then AzCopy starts three concurrent operations.

每个操作将导出三个分区键范围中的一个,如下所示:Each operation exports one of three partition key ranges, as shown below:

[first-partition-key, aa)[first-partition-key, aa)

[aa, bb)[aa, bb)

[bb, last-partition-key][bb, last-partition-key]

适用于:Applicable to: Tables

/SplitSize:"file-size"/SplitSize:"file-size"

指定已导出文件的拆分大小(单位为 MB),允许的最小值为 32。Specifies the exported file split size in MB, the minimal value allowed is 32.

如果未指定此选项,AzCopy 会将表数据导出到单个文件。If this option is not specified, AzCopy exports table data to a single file.

如果将表数据导出到一个 blob,并且已导出文件的大小达到了 200 GB 的 blob 大小限制,AzCopy 会拆分导出的文件,即使未指定此选项也是如此。If the table data is exported to a blob, and the exported file size reaches the 200 GB limit for blob size, then AzCopy splits the exported file, even if this option is not specified.

适用于:Applicable to: Tables

/EntityOperation:"InsertOrSkip" | "InsertOrMerge" | "InsertOrReplace"/EntityOperation:"InsertOrSkip" | "InsertOrMerge" | "InsertOrReplace"

指定表数据导入行为。Specifies the table data import behavior.

  • InsertOrSkip - 跳过现有实体,或者插入新实体(如果它不存在于表中)。InsertOrSkip - Skips an existing entity or inserts a new entity if it does not exist in the table.
  • InsertOrMerge - 合并现有实体,或者插入新实体(如果它不存在于表中)。InsertOrMerge - Merges an existing entity or inserts a new entity if it does not exist in the table.
  • InsertOrReplace - 替换现有实体,或者插入新实体(如果它不存在于表中)。InsertOrReplace - Replaces an existing entity or inserts a new entity if it does not exist in the table.

适用于:Applicable to: Tables

/Manifest:"manifest-file"/Manifest:"manifest-file"

指定表导出和导入操作的清单文件。Specifies the manifest file for the table export and import operation.

此选项在导出操作过程中是可选的,如果未指定此选项,AzCopy 会生成具有预定义名称的清单文件。This option is optional during the export operation, AzCopy generates a manifest file with predefined name if this option is not specified.

在导入操作期间用于定位数据文件,此选项是必要的。This option is required during the import operation for locating the data files.

适用于:Applicable to: Tables

/SyncCopy/SyncCopy

指示是否要以同步方式在两个 Azure 存储终结点之间复制 blob 或文件。Indicates whether to synchronously copy blobs or files between two Azure Storage endpoints.

AzCopy 默认情况下使用服务器端的异步复制。AzCopy by default uses server-side asynchronous copy. 指定此选项以执行同步复制,可将 blob 或文件下载到本地内存,并将其上传到 Azure 存储。Specify this option to perform a synchronous copy, which downloads blobs or files to local memory and then uploads them to Azure Storage.

在 Blob 存储内复制文件、文件存储内复制文件或者从 Bolb 存储将文件复制到文件存储时,可使用此选项,反之亦然。You can use this option when copying files within Blob storage, within File storage, or from Blob storage to File storage or vice versa.

适用于: Blob、文件Applicable to: Blobs, Files

/SetContentType:"content-type"/SetContentType:"content-type"

指定目标 blob 或文件的 MIME 内容类型。Specifies the MIME content type for destination blobs or files.

默认情况下,AzCopy 将 blob 或文件的内容类型设置为 application/octet-stream。AzCopy sets the content type for a blob or file to application/octet-stream by default. 通过显式指定此选项的值,可设置所有 blob 或文件的内容类型。You can set the content type for all blobs or files by explicitly specifying a value for this option.

如果指定此选项不带值,AzCopy 会根据 blod 或文件扩展名设置每个 blob 或文件的内容类型。If you specify this option without a value, then AzCopy sets each blob or file's content type according to its file extension.

适用于: Blob、文件Applicable to: Blobs, Files

/PayloadFormat:"JSON" | "CSV"/PayloadFormat:"JSON" | "CSV"

指定表导出数据文件的格式。Specifies the format of the table exported data file.

如果未指定此选项,则默认情况下,AzCopy 以 JSON 格式导出表数据文件。If this option is not specified, by default AzCopy exports table data file in JSON format.

适用于:Applicable to: Tables

已知问题和最佳实践Known Issues and Best Practices

让我们了解一些已知问题和最佳做法。Let's take a look at some of the known issues and best practices.

限制复制数据时的并发写入Limit concurrent writes while copying data

在使用 AzCopy 复制 blob 或文件时,请记住,在复制数据时其他应用程序可能正在修改该数据。When you copy blobs or files with AzCopy, keep in mind that another application may be modifying the data while you are copying it. 如果可能,请确保要复制的数据在复制操作期间不会被修改。If possible, ensure that the data you are copying is not being modified during the copy operation. 例如,当复制与 Azure 虚拟机关联的 VHD 时,请确保当前没有其他应用程序正在向该 VHD 进行写入。For example, when copying a VHD associated with an Azure virtual machine, make sure that no other applications are currently writing to the VHD. 执行此操作的一个好方法是租用要复制的资源。A good way to do this is by leasing the resource to be copied. 另外,还可以先创建 VHD 的快照,然后复制该快照。Alternately, you can create a snapshot of the VHD first and then copy the snapshot.

如果在复制 blob 或文件时无法阻止其他应用程序向其进行写入,请记住,在作业完成时,复制的资源可能不再与源资源完全相同。If you cannot prevent other applications from writing to blobs or files while they are being copied, then keep in mind that by the time the job finishes, the copied resources may no longer have full parity with the source resources.

当进行“使用适用于加密、哈希和签名的 FIPS 兼容算法”时,请启用适用于 AzCopy、与 FIPS 兼容的 MD5 算法。Enable FIPS-compliant MD5 algorithms for AzCopy when you "Use FIPS-compliant algorithms for encryption, hashing and signing."

默认情况下,在复制对象时,如有需要 AzCopy 启动 FIPS 兼容的 MD5 设置的某些安全需求时,AzCopy 则会使用 .NET MD5 实现来计算 MD5。AzCopy by default uses .NET MD5 implementation to calculate the MD5 when copying objects, but there are some security requirements that need AzCopy to enable FIPS-compliant MD5 setting.

可以创建属性为 AzureStorageUseV1MD5 的 app.config 文件 AzCopy.exe.config,并将其与 AzCopy.exe 分开放。You can create an app.config file AzCopy.exe.config with property AzureStorageUseV1MD5 and put it aside with AzCopy.exe.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="AzureStorageUseV1MD5" value="false"/>
  </appSettings>
</configuration>

对于属性“AzureStorageUseV1MD5”:For property "AzureStorageUseV1MD5":

  • 如果值为 True(默认值),AzCopy 会使用 .NET MD5 实现。True - The default value, AzCopy uses .NET MD5 implementation.
  • 如果值为 False,AzCopy 会使用 FIPS 兼容的 MD5 算法。False – AzCopy uses FIPS-compliant MD5 algorithm.

Windows 中默认已禁用 FIPS 兼容的算法。FIPS-compliant algorithms are disabled by default on Windows. 可在计算机上更改此策略设置。You can change this policy setting on your machine. 在“运行”窗口(按 Windows 键 + R 键)中键入 secpol.msc 打开“本地安全策略”窗口。 In the Run window (Windows+R), type secpol.msc to open the Local Security Policy window. 在“安全设置”窗口中,导航到“安全设置” > “本地策略” > “安全选项”。 In the Security Settings window, navigate to Security Settings > Local Policies > Security Options. 找到“系统加密:将 FIPS 兼容算法用于加密、哈希和签名”策略。Locate the System cryptography: Use FIPS-compliant algorithms for encryption, hashing and signing policy. 双击该策略,查看“安全设置”列中显示的值。 Double-click on the policy to see the value displayed in the Security Setting column.

后续步骤Next steps

有关 Azure 存储和 AzCopy 的更多信息,请参阅以下资源:For more information about Azure Storage and AzCopy, see the following resources:

Azure 存储文档:Azure Storage documentation:

Azure 存储博客文章:Azure Storage blog posts: