azcopy syncazcopy sync

将源位置复制到目标位置。Replicates the source location to the destination location.

摘要Synopsis

上次修改时间用于比较。The last modified times are used for comparison. 如果目标中的上次修改时间与当前时间更近,则会跳过文件。The file is skipped if the last modified time in the destination is more recent.

支持的配对包括:The supported pairs are:

  • 本地 <-> Azure Blob(可以使用 SAS 或 OAuth 身份验证)local <-> Azure Blob (either SAS or OAuth authentication can be used)
  • Azure Blob <-> Azure Blob(源必须包含 SAS 或可公开访问;可将 SAS 或 OAuth 身份验证用于目标)Azure Blob <-> Azure Blob (Source must include a SAS or is publicly accessible; either SAS or OAuth authentication can be used for destination)
  • Azure 文件 <-> Azure 文件(源必须包含 SAS 或可公开访问;应将 SAS 身份验证用于目标)Azure File <-> Azure File (Source must include a SAS or is publicly accessible; SAS authentication should be used for destination)

sync 命令与 copy 命令的不同之处体现在以下几个方面:The sync command differs from the copy command in several ways:

  1. 默认情况下,递归标志为 true,sync 会复制所有子目录。By default, the recursive flag is true and sync copies all subdirectories. 如果递归标志为 false,则 sync 只复制目录中的顶级文件。Sync only copies the top-level files inside a directory if the recursive flag is false.
  2. 在虚拟目录之间同步时,如果存在与某个虚拟目录同名的 Blob,则在路径中添加一个尾随斜杠(参考示例)。When syncing between virtual directories, add a trailing slash to the path (refer to examples) if there's a blob with the same name as one of the virtual directories.
  3. 如果将 deleteDestination 标志设置为 true 或 prompt,则 sync 将删除目标中存在的,但在源中不存在的文件和 Blob。If the deleteDestination flag is set to true or prompt, then sync will delete files and blobs at the destination that are not present at the source.

高级Advanced

如果未指定文件扩展名,从本地磁盘上传时,AzCopy 会根据文件扩展名或内容自动检测文件的内容类型。If you don't specify a file extension, AzCopy automatically detects the content type of the files when uploading from the local disk, based on the file extension or content (if no extension is specified).

内置的查找表较小,但在 Unix 上,已通过采用以下一个或多个名称的本地系统 mime.types 文件(如果可用)扩充了该查找表:The built-in lookup table is small, but on Unix, it's augmented by the local system's mime.types file(s) if available under one or more of these names:

  • /etc/mime.types/etc/mime.types
  • /etc/apache2/mime.types/etc/apache2/mime.types
  • /etc/apache/mime.types/etc/apache/mime.types

在 Windows 上,MIME 类型是从注册表提取的。On Windows, MIME types are extracted from the registry.

azcopy sync <source> <destination> [flags]

示例Examples

同步单个文件:Sync a single file:

azcopy sync "/path/to/file.txt" "https://[account].blob.core.chinacloudapi.cn/[container]/[path/to/blob]"

与前面的示例相同,但还会计算文件内容的 MD5 哈希,然后将该 MD5 哈希另存为 Blob 的 Content-MD5 属性。Same as above, but also compute an MD5 hash of the file content, and then save that MD5 hash as the blob's Content-MD5 property.

azcopy sync "/path/to/file.txt" "https://[account].blob.core.chinacloudapi.cn/[container]/[path/to/blob]" --put-md5

同步整个目录,包括其子目录(请注意,默认已启用递归):Sync an entire directory including its subdirectories (note that recursive is by default on):

azcopy sync "/path/to/dir" "https://[account].blob.core.chinacloudapi.cn/[container]/[path/to/virtual/dir]"

or

azcopy sync "/path/to/dir" "https://[account].blob.core.chinacloudapi.cn/[container]/[path/to/virtual/dir]" --put-md5

仅同步目录内的文件,但不同步子目录或子目录中的文件:Sync only the files inside of a directory but not subdirectories or the files inside of subdirectories:

azcopy sync "/path/to/dir" "https://[account].blob.core.chinacloudapi.cn/[container]/[path/to/virtual/dir]" --recursive=false

同步目录中的一部分文件(例如:仅同步 jpg 和 pdf 文件,或者同步文件名为 exactName 的文件):Sync a subset of files in a directory (For example: only jpg and pdf files, or if the file name is exactName):

azcopy sync "/path/to/dir" "https://[account].blob.core.chinacloudapi.cn/[container]/[path/to/virtual/dir]" --include-pattern="*.jpg;*.pdf;exactName"

同步整个目录,但从同步范围中排除某些文件(例如:以 foo 开头或以 bar 结尾的每个文件):Sync an entire directory but exclude certain files from the scope (For example: every file that starts with foo or ends with bar):

azcopy sync "/path/to/dir" "https://[account].blob.core.chinacloudapi.cn/[container]/[path/to/virtual/dir]" --exclude-pattern="foo*;*bar"

同步单个 Blob:Sync a single blob:

azcopy sync "https://[account].blob.core.chinacloudapi.cn/[container]/[path/to/blob]?[SAS]" "https://[account].blob.core.chinacloudapi.cn/[container]/[path/to/blob]"

同步虚拟目录:Sync a virtual directory:

azcopy sync "https://[account].blob.core.chinacloudapi.cn/[container]/[path/to/virtual/dir]?[SAS]" "https://[account].blob.core.chinacloudapi.cn/[container]/[path/to/virtual/dir]" --recursive=true

同步与 Blob 同名的虚拟目录(在路径中添加尾随斜杠以消除歧义):Sync a virtual directory that has the same name as a blob (add a trailing slash to the path in order to disambiguate):

azcopy sync "https://[account].blob.core.chinacloudapi.cn/[container]/[path/to/virtual/dir]/?[SAS]" "https://[account].blob.core.chinacloudapi.cn/[container]/[path/to/virtual/dir]/" --recursive=true

同步 Azure 文件目录(语法与 Blob 相同):Sync an Azure File directory (same syntax as Blob):

azcopy sync "https://[account].file.core.chinacloudapi.cn/[share]/[path/to/dir]?[SAS]" "https://[account].file.core.chinacloudapi.cn/[share]/[path/to/dir]" --recursive=true

备注

如果同时使用 include/exclude 标志,只会查找与 include 模式匹配的文件,而始终忽略与 exclude 模式匹配的文件。If include/exclude flags are used together, only files matching the include patterns would be looked at, but those matching the exclude patterns would be always be ignored.

选项Options

--block-size-mb 浮点数 - 在上传到 Azure 存储或从 Azure 存储下载时使用此块大小(以 MiB 为单位)。--block-size-mb float Use this block size (specified in MiB) when uploading to Azure Storage or downloading from Azure Storage. 默认值根据文件大小自动计算。Default is automatically calculated based on file size. 允许使用小数(例如:0.25)。Decimal fractions are allowed (For example: 0.25).

--check-md5 字符串 - 指定下载时验证 MD5 哈希的严格程度。--check-md5 string Specifies how strictly MD5 hashes should be validated when downloading. 此选项仅在下载时可用。This option is only available when downloading. 可用的值包括 NoCheckLogOnlyFailIfDifferentFailIfDifferentOrMissingAvailable values include: NoCheck, LogOnly, FailIfDifferent, FailIfDifferentOrMissing. (默认值为 FailIfDifferent)。(default FailIfDifferent). (默认值为 FailIfDifferent(default FailIfDifferent)

--delete-destination 字符串 定义是否从目标中删除不在源中的多余文件。--delete-destination string Defines whether to delete extra files from the destination that are not present at the source. 可设置为 truefalsepromptCould be set to true, false, or prompt. 如果设置为 prompt,则在计划要删除的文件和 Blob 之前,系统会向用户提问。If set to prompt, the user will be asked a question before scheduling files and blobs for deletion. (默认值为 false)。(default false). (默认值为 false(default false)

--exclude-attributes 字符串 -(仅限 Windows)排除其属性与属性列表相匹配的文件。--exclude-attributes string (Windows only) Excludes files whose attributes match the attribute list. 例如:A;S;RFor example: A;S;R

--exclude-path 字符串 - 将源与目标进行比较时,排除这些路径。--exclude-path string Exclude these paths when comparing the source against the destination. 此选项不支持通配符 (*)。This option does not support wildcard characters (*). 检查相对路径前缀(例如:myFolder;myFolder/subDirName/file.pdf)。Checks relative path prefix(For example: myFolder;myFolder/subDirName/file.pdf).

--exclude-pattern 字符串 排除名称与模式列表相匹配的文件。--exclude-pattern string Exclude files where the name matches the pattern list. 例如:*.jpg;*.pdf;exactNameFor example: *.jpg;*.pdf;exactName

--help - 关于同步的帮助。--help help for sync.

--include-attributes 字符串 -(仅限 Windows)仅包括其属性与属性列表相匹配的文件。--include-attributes string (Windows only) Includes only files whose attributes match the attribute list. 例如:A;S;RFor example: A;S;R

--include-pattern 字符串 仅包括名称与模式列表相匹配的文件。--include-pattern string Include only files where the name matches the pattern list. 例如:*.jpg;*.pdf;exactNameFor example: *.jpg;*.pdf;exactName

--log-level 字符串 - 定义日志文件的日志详细程度,可用级别:INFO(所有请求和响应)、WARNING(缓慢响的应)、ERROR(仅限失败的请求)和 NONE(无输出日志)。--log-level string Define the log verbosity for the log file, available levels: INFO(all requests and responses), WARNING(slow responses), ERROR(only failed requests), and NONE(no output logs). (默认值为 INFO)。(default INFO).

--preserve-smb-info - 默认值为 False。--preserve-smb-info False by default. 保留 SMB 感知资源(Windows 和 Azure 文件存储)之间的 SMB 属性信息(上次写入时间、创建时间、属性位)。Preserves SMB property info (last write time, creation time, attribute bits) between SMB-aware resources (Windows and Azure Files). 此标志同时适用于文件和文件夹,除非指定了“仅文件”筛选器(例如包含模式)。This flag applies to both files and folders, unless a file-only filter is specified (for example, include-pattern). 为文件夹传输的信息与为文件传输的信息几乎相同,只是“上次写入时间”除外,不会为文件夹保留该信息。The info transferred for folders is the same as that for files, except for Last Write Time that is not preserved for folders.

--preserve-smb-permissions - 默认值为 False。--preserve-smb-permissions False by default. 保留感知资源(Windows 和 Azure 文件存储)之间的 SMB ACl。Preserves SMB ACLs between aware resources (Windows and Azure Files). 此标志同时适用于文件和文件夹,除非指定了“仅文件”筛选器(例如 include-pattern)。This flag applies to both files and folders, unless a file-only filter is specified (for example, include-pattern).

--put-md5 - 创建每个文件的 MD5 哈希,并将该哈希另存为目标 Blob 或文件的 Content-MD5 属性。--put-md5 Create an MD5 hash of each file, and save the hash as the Content-MD5 property of the destination blob or file. (默认不会创建哈希。)仅在上传时可用。(By default the hash is NOT created.) Only available when uploading.

--recursive - 默认值为 True,即,在目录之间同步时,将以递归方式查看子目录。--recursive True by default, look into subdirectories recursively when syncing between directories. (默认值为 True)。(default True).

--s2s-preserve-access-tier - 在服务之间复制过程中保留访问层。--s2s-preserve-access-tier Preserve access tier during service to service copy. 请参阅 Azure Blob 存储:热、冷和存档访问层,确保目标存储帐户支持设置访问层。Refer to Azure Blob storage: hot, cool, and archive access tiers to ensure destination storage account supports setting access tier. 如果不支持设置访问层,请使用 s2sPreserveAccessTier=false 来绕过访问层的复制。In the cases that setting access tier is not supported, please use s2sPreserveAccessTier=false to bypass copying access tier. (默认值为 true)。(default true).

从父命令继承的选项Options inherited from parent commands

选项Option 说明Description
--cap-mbps uint32--cap-mbps uint32 以兆位/秒为单位限制传输速率。Caps the transfer rate, in megabits per second. 瞬间吞吐量可能与上限略有不同。Moment-by-moment throughput might vary slightly from the cap. 如果此选项设置为零,或者省略,则吞吐量不受限制。If this option is set to zero, or it is omitted, the throughput isn't capped.
--output-type string--output-type string 命令输出的格式。Format of the command's output. 选项包括:text、json。The choices include: text, json. 默认值为“text”。The default value is "text".
--trusted-microsoft-suffixes 字符串--trusted-microsoft-suffixes string 指定可在其中发送 Azure Active Directory 登录令牌的其他域后缀。Specifies additional domain suffixes where Azure Active Directory login tokens may be sent. 默认值为“.core.windows.net;.core.chinacloudapi.cn;.core.cloudapi.de;.core.usgovcloudapi.net” 。The default is '.core.windows.net;.core.chinacloudapi.cn;.core.cloudapi.de;.core.usgovcloudapi.net'. 此处列出的任何内容都会添加到默认值。Any listed here are added to the default. 为安全起见,应只在此处放置 Azure 域。For security, you should only put Azure domains here. 用分号分隔多个条目。Separate multiple entries with semi-colons.

另请参阅See also