使用 AzCopy v10 与 Azure Blob 存储同步Synchronize with Azure Blob storage by using AzCopy v10

可以使用 AzCopy v10 命令行实用程序将本地存储与 Azure Blob 存储同步。You can synchronize local storage with Azure Blob storage by using the AzCopy v10 command-line utility.

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

备注

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

若要查看其他类型任务(如上传文件、下载 blob 或在帐户之间复制 Blob)的示例,请参阅本文的后续步骤部分中提供的链接。To see examples for other types of tasks such as uploading files, downloading blobs, 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>'.ken>'`。For example: 'https://<storage-account-name>.blob.core.chinacloudapi.cn/<container-name><SAS-token>'.ken>'`.

指南Guidelines

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

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

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

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

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

提示

此示例将路径参数括在单引号 ('') 内。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 sync '<local-directory-path>' 'https://<storage-account-name>.blob.core.chinacloudapi.cn/<container-name>' --recursive
示例Example azcopy sync 'C:\myDirectory' 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer' --recursive

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

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

提示

此示例将路径参数括在单引号 ('') 内。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 sync 'https://<storage-account-name>.blob.core.chinacloudapi.cn/<container-name>' 'C:\myDirectory' --recursive
示例Example azcopy sync 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer' 'C:\myDirectory' --recursive

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

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

提示

此示例将路径参数括在单引号 ('') 内。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 sync 'https://<source-storage-account-name>.blob.core.chinacloudapi.cn/<container-name>' 'https://<destination-storage-account-name>.blob.core.chinacloudapi.cn/<container-name>' --recursive
示例Example azcopy sync 'https://mysourceaccount.blob.core.chinacloudapi.cn/mycontainer' 'https://mydestinationaccount.blob.core.chinacloudapi.cn/mycontainer' --recursive

使用对另一个容器中的目录所做的更改来更新一个目录Update a directory with changes to a directory in another container

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

提示

此示例将路径参数括在单引号 ('') 内。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 sync 'https://<source-storage-account-name>.blob.core.chinacloudapi.cn/<container-name>/<directory-name>' 'https://<destination-storage-account-name>.blob.core.chinacloudapi.cn/<container-name>/<directory-name>' --recursive
示例Example azcopy sync 'https://mysourceaccount.blob.core.chinacloudapi.cn/<container-name>/myDirectory' 'https://mydestinationaccount.blob.core.chinacloudapi.cn/mycontainer/myDirectory' --recursive

使用可选标志同步Synchronize with optional flags

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

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

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

后续步骤Next steps

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