使用 AzCopy 和文件存储传输数据Transfer data with AzCopy and file storage

AzCopy 是一个命令行实用工具,可用于向/从存储帐户复制 Blob 或文件。AzCopy is a command-line utility that you can use to copy blobs or files to or from a storage account. 本文包含适用于 Azure 文件存储的示例命令。This article contains example commands that work with Azure Files.

在开始之前,请参阅 AzCopy 入门一文下载 AzCopy 并熟悉该工具。Before you begin, see the Get started with AzCopy article to download AzCopy and familiarize yourself with the tool.

提示

本文中的示例将路径参数括在单引号 ('') 中。The examples in this article 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 ('').

创建文件共享Create file shares

可以使用 azcopy make 命令创建文件共享。You can use the azcopy make command to create a file share. 本部分中的示例将创建名为 myfileshare 的文件共享。The example in this section creates a file share named myfileshare.

语法Syntax azcopy make 'https://<storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>?<SAS-token>'
示例Example azcopy make 'https://mystorageaccount.file.core.chinacloudapi.cn/myfileshare?sv=2018-03-28&ss=bjqt&srs=sco&sp=rjklhjup&se=2019-05-10T04:37:48Z&st=2019-05-09T20:37:48Z&spr=https&sig=%2FSOVEFfsKDqRry4bk3qz1vAQFwY5DDzp2%2B%2F3Eykf%2FJLs%3D'

有关详细参考文档,请参阅 azcopy makeFor detailed reference docs, see azcopy make.

上传文件Upload files

可以使用 azcopy copy 命令从本地计算机上传文件和目录。You can use the azcopy copy command to upload files and directories from your local computer.

本部分包含以下示例:This section contains the following examples:

  • 上传文件Upload a file
  • 上传目录Upload a directory
  • 上传目录的内容Upload the contents of a directory
  • 上传特定的文件Upload a specific file

提示

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

方案Scenario 标志Flag
将访问控制列表 (ACL) 与文件一起复制。Copy access control lists (ACLs) along with the files. --preserve-smb-permissions=[true|false]--preserve-smb-permissions=[true|false]
将 SMB 属性信息与文件一起复制。Copy SMB property information along with the files. --preserve-smb-info=[true|false]--preserve-smb-info=[true|false]
将文件作为追加 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.

备注

AzCopy 不会自动计算和存储文件的 MD5 哈希代码。AzCopy doesn't automatically calculate and store the file's md5 hash code. 如果你希望 AzCopy 执行此操作,请将 --put-md5 标志追加到每个 copy 命令。If you want AzCopy to do that, then append the --put-md5 flag to each copy command. 这样,在下载文件后,AzCopy 将计算已下载的数据的 MD5 哈希,并验证存储在该文件的 Content-md5 属性中的 MD5 哈希是否与计算出的哈希相匹配。That way, when the file is downloaded, AzCopy calculates an MD5 hash for downloaded data and verifies that the MD5 hash stored in the file's Content-md5 property matches the calculated hash.

上传文件Upload a file

语法Syntax azcopy copy '<local-file-path>' 'https://<storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>/<file-name>?<SAS-token>'
示例Example azcopy copy 'C:\myDirectory\myTextFile.txt' 'https://mystorageaccount.file.core.chinacloudapi.cn/myfileshare/myTextFile.txt?sv=2018-03-28&ss=bjqt&srs=sco&sp=rjklhjup&se=2019-05-10T04:37:48Z&st=2019-05-09T20:37:48Z&spr=https&sig=%2FSOVEFfsKDqRry4bk3qz1vAQFwY5DDzp2%2B%2F3Eykf%2FJLs%3D'

还可以在文件路径或文件名中的任意位置使用通配符 (*) 来上传文件。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

此示例将某个目录(以及该目录中的所有文件)复制到文件共享。This example copies a directory (and all of the files in that directory) to a file share. 结果是该文件共享中出现一个同名的目录。The result is a directory in the file share by the same name.

语法Syntax azcopy copy '<local-directory-path>' 'https://<storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>?<SAS-token>' --recursive
示例Example azcopy copy 'C:\myDirectory' 'https://mystorageaccount.file.core.chinacloudapi.cn/myfileshare?sv=2018-03-28&ss=bjqt&srs=sco&sp=rjklhjup&se=2019-05-10T04:37:48Z&st=2019-05-09T20:37:48Z&spr=https&sig=%2FSOVEFfsKDqRry4bk3qz1vAQFwY5DDzp2%2B%2F3Eykf%2FJLs%3D' --recursive

若要复制到文件共享中的某个目录,只需在命令字符串中指定该目录的名称。To copy to a directory within the file share, just specify the name of that directory in your command string.

示例Example azcopy copy 'C:\myDirectory' 'https://mystorageaccount.file.core.chinacloudapi.cn/myfileshare/myFileShareDirectory?sv=2018-03-28&ss=bjqt&srs=sco&sp=rjklhjup&se=2019-05-10T04:37:48Z&st=2019-05-09T20:37:48Z&spr=https&sig=%2FSOVEFfsKDqRry4bk3qz1vAQFwY5DDzp2%2B%2F3Eykf%2FJLs%3D' --recursive

如果指定的目录名称在文件共享中不存在,AzCopy 将以该名称创建一个新目录。If you specify the name of a directory that does not exist in the file share, AzCopy creates a new directory by that name.

上传目录的内容Upload the contents of a directory

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

语法Syntax azcopy copy '<local-directory-path>/*' 'https://<storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>/<directory-path>?<SAS-token>
示例Example azcopy copy 'C:\myDirectory\*' 'https://mystorageaccount.file.core.chinacloudapi.cn/myfileshare/myFileShareDirectory?sv=2018-03-28&ss=bjqt&srs=sco&sp=rjklhjup&se=2019-05-10T04:37:48Z&st=2019-05-09T20:37:48Z&spr=https&sig=%2FSOVEFfsKDqRry4bk3qz1vAQFwY5DDzp2%2B%2F3Eykf%2FJLs%3D"

备注

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

上传特定的文件Upload specific files

可以使用完整的文件名、包含通配符 (*) 的部分名称或者日期和时间来上传特定文件。You can upload specific files by using complete file names, partial names with wildcard characters (*), or by using dates and times.

指定多个完整文件名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>.file.core.chinacloudapi.cn/<file-share-or-directory-name>?<SAS-token>' --include-path <semicolon-separated-file-list>
示例Example azcopy copy 'C:\myDirectory' 'https://mystorageaccount.file.core.chinacloudapi.cn/myfileshare?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' --include-path 'photos;documents\myFile.txt'

在此示例中,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 目录中的所有文件。You need to 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 semicolon (;).

语法Syntax azcopy copy '<local-directory-path>' 'https://<storage-account-name>.file.core.chinacloudapi.cn/<file-share-or-directory-name>?<SAS-token>' --include-pattern <semicolon-separated-file-list-with-wildcard-characters>
示例Example azcopy copy 'C:\myDirectory' 'https://mystorageaccount.file.core.chinacloudapi.cn/myfileshare?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' --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 after a date and time

结合 --include-after 选项使用 azcopy copy 命令。Use the azcopy copy command with the --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).

语法Syntax azcopy copy '<local-directory-path>\*' 'https://<storage-account-name>.file.core.chinacloudapi.cn/<file-share-or-directory-name>?<SAS-token>' --include-after <Date-Time-in-ISO-8601-format>
示例Example azcopy copy 'C:\myDirectory\*' 'https://mystorageaccount.file.core.chinacloudapi.cn/myfileshare?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' --include-after '2020-08-19T15:04:00Z'

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

下载文件Download files

可以使用 azcopy copy 命令将文件、目录和文件共享下载到本地计算机。You can use the azcopy copy command to download files, directories, and file shares to your local computer.

本部分包含以下示例:This section contains the following examples:

  • 下载文件Download a file
  • 下载目录Download a directory
  • 下载目录的内容Download the contents of a directory
  • 下载特定的文件Download specific files

提示

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

方案Scenario 标志Flag
将访问控制列表 (ACL) 与文件一起复制。Copy access control lists (ACLs) along with the files. --preserve-smb-permissions=[true|false]--preserve-smb-permissions=[true|false]
将 SMB 属性信息与文件一起复制。Copy SMB property information along with the files. --preserve-smb-info=[true|false]--preserve-smb-info=[true|false]
自动解压缩文件。Automatically decompress files. --decompress--decompress

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

备注

如果文件的 Content-md5 属性值包含哈希,AzCopy 将计算已下载的数据的 MD5 哈希,并验证存储在该文件的 Content-md5 属性中的 MD5 哈希是否与计算出的哈希相匹配。If the Content-md5 property value of a file contains a hash, AzCopy calculates an MD5 hash for downloaded data and verifies that the MD5 hash stored in the file's Content-md5 property matches the calculated hash. 如果这些值不匹配,除非通过将 --check-md5=NoCheck--check-md5=LogOnly 追加到 copy 命令来重写此行为,否则下载将会失败。If these values don't match, the download fails unless you override this behavior by appending --check-md5=NoCheck or --check-md5=LogOnly to the copy command.

下载文件Download a file

语法Syntax azcopy copy 'https://<storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>/<file-path>?<SAS-token>' '<local-file-path>'
示例Example azcopy copy 'https://mystorageaccount.file.core.chinacloudapi.cn/myfileshare/myTextFile.txt?sv=2018-03-28&ss=bjqt&srs=sco&sp=rjklhjup&se=2019-05-10T04:37:48Z&st=2019-05-09T20:37:48Z&spr=https&sig=%2FSOVEFfsKDqRry4bk3qz1vAQFwY5DDzp2%2B%2F3Eykf%2FJLs%3D' 'C:\myDirectory\myTextFile.txt'

下载目录Download a directory

语法Syntax azcopy copy 'https://<storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>/<directory-path>?<SAS-token>' '<local-directory-path>' --recursive
示例Example azcopy copy 'https://mystorageaccount.file.core.chinacloudapi.cn/myfileshare/myFileShareDirectory?sv=2018-03-28&ss=bjqt&srs=sco&sp=rjklhjup&se=2019-05-10T04:37:48Z&st=2019-05-09T20:37:48Z&spr=https&sig=%2FSOVEFfsKDqRry4bk3qz1vAQFwY5DDzp2%2B%2F3Eykf%2FJLs%3D' 'C:\myDirectory' --recursive

此示例将生成名为 C:\myDirectory\myFileShareDirectory 的目录,其中包含所有已下载的文件。This example results in a directory named C:\myDirectory\myFileShareDirectory that contains all of the downloaded files.

下载目录的内容Download the contents of a directory

可以使用通配符 (*) 下载目录的内容,而无需复制包含的目录本身。You can download the contents of a directory without copying the containing directory itself by using the wildcard symbol (*).

语法Syntax azcopy copy 'https://<storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>/*?<SAS-token>' '<local-directory-path>/'
示例Example azcopy copy 'https://mystorageaccount.file.core.chinacloudapi.cn/myfileshare/myFileShareDirectory/*?sv=2018-03-28&ss=bjqt&srs=sco&sp=rjklhjup&se=2019-05-10T04:37:48Z&st=2019-05-09T20:37:48Z&spr=https&sig=%2FSOVEFfsKDqRry4bk3qz1vAQFwY5DDzp2%2B%2F3Eykf%2FJLs%3D' 'C:\myDirectory'

备注

追加 --recursive 标志可以下载所有子目录中的文件。Append the --recursive flag to download files in all sub-directories.

下载特定的文件Download specific files

可以使用完整的文件名、包含通配符 (*) 的部分名称或者日期和时间来下载特定文件。You can download specific files by using complete file names, partial names with wildcard characters (*), or by using dates and times.

指定多个完整文件名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 'https://<storage-account-name>.file.core.chinacloudapi.cn/<file-share-or-directory-name>?<SAS-token>' '<local-directory-path>' --include-path <semicolon-separated-file-list>
示例Example azcopy copy 'https://mystorageaccount.file.core.chinacloudapi.cn/myFileShare/myDirectory?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' 'C:\myDirectory' --include-path 'photos;documents\myFile.txt' --recursive

在此示例中,AzCopy 将传输 https://mystorageaccount.file.core.chinacloudapi.cn/myFileShare/myDirectory/photos 目录和 https://mystorageaccount.file.core.chinacloudapi.cn/myFileShare/myDirectory/documents/myFile.txt 文件。In this example, AzCopy transfers the https://mystorageaccount.file.core.chinacloudapi.cn/myFileShare/myDirectory/photos directory and the https://mystorageaccount.file.core.chinacloudapi.cn/myFileShare/myDirectory/documents/myFile.txt file. 需要包含 --recursive 选项才能传输 https://mystorageaccount.file.core.chinacloudapi.cn/myFileShare/myDirectory/photos 目录中的所有文件。You need to include the --recursive option to transfer all files in the https://mystorageaccount.file.core.chinacloudapi.cn/myFileShare/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 semicolon (;).

语法Syntax azcopy copy 'https://<storage-account-name>.<blob or dfs>.core.chinacloudapi.cn/<container-or-directory-name>?<SAS-token>' '<local-directory-path>' --include-pattern <semicolon-separated-file-list-with-wildcard-characters>
示例Example azcopy copy 'https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer/FileDirectory?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' 'C:\myDirectory' --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.

下载在某个日期和时间之后修改的文件Download files that were modified after a date and time

结合 --include-after 选项使用 azcopy copy 命令。Use the azcopy copy command with the --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).

语法Syntax azcopy copy 'https://<storage-account-name>.file.core.chinacloudapi.cn/<file-share-or-directory-name>/*<SAS-token>' '<local-directory-path>' --include-after <Date-Time-in-ISO-8601-format>
示例Example azcopy copy 'https://mystorageaccount.file.core.chinacloudapi.cn/myfileshare/*?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' 'C:\myDirectory' --include-after '2020-08-19T15:04:00Z'

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

在存储帐户之间复制文件Copy files between storage accounts

可以使用 AzCopy 将文件复制到其他存储帐户。You can use AzCopy to copy files to other storage accounts. 复制操作是同步的,因此,当命令返回时,表示已复制所有文件。The copy operation is synchronous so when the command returns, that indicates that all files have been copied.

AzCopy 使用服务器到服务器 API,因此,数据会直接在存储服务器之间复制。AzCopy uses server-to-server APIs, so data is copied directly between storage servers. 这些复制操作不会占用计算机的网络带宽。These copy operations don't use the network bandwidth of your computer. 可以通过设置 AZCOPY_CONCURRENCY_VALUE 环境变量的值来提高这些操作的吞吐量。You can increase the throughput of these operations by setting the value of the AZCOPY_CONCURRENCY_VALUE environment variable. 有关详细信息,请参阅优化吞吐量To learn more, see Optimize throughput.

本部分包含以下示例:This section contains the following examples:

  • 将文件复制到另一个存储帐户Copy a file to another storage account
  • 将目录复制到另一个存储帐户Copy a directory to another storage account
  • 将文件共享复制到另一个存储帐户Copy a file share to another storage account
  • 将所有文件共享、目录和文件复制到另一个存储帐户Copy all file shares, directories, and files to another storage account

提示

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

方案Scenario 标志Flag
将访问控制列表 (ACL) 与文件一起复制。Copy access control lists (ACLs) along with the files. --preserve-smb-permissions=[true|false]--preserve-smb-permissions=[true|false]
将 SMB 属性信息与文件一起复制。Copy SMB property information along with the files. --preserve-smb-info=[true|false]--preserve-smb-info=[true|false]
将文件复制为追加 Blob 或页 Blob。Copy files as Append Blobs or Page Blobs. --blob-type=[BlockBlob|PageBlob|AppendBlob]--blob-type=[BlockBlob|PageBlob|AppendBlob]
复制到特定访问层(如存档层)。Copy 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.

将文件复制到另一个存储帐户Copy a file to another storage account

语法Syntax azcopy copy 'https://<source-storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>/<file-path>?<SAS-token>' 'https://<destination-storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>/<file-path>?<SAS-token>'
示例Example azcopy copy 'https://mysourceaccount.file.core.chinacloudapi.cn/mycontainer/myTextFile.txt?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' 'https://mydestinationaccount.file.core.chinacloudapi.cn/mycontainer/myTextFile.txt?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D'

将目录复制到另一个存储帐户Copy a directory to another storage account

语法Syntax azcopy copy 'https://<source-storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>/<directory-path>?<SAS-token>' 'https://<destination-storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>?<SAS-token>' --recursive
示例Example azcopy copy 'https://mysourceaccount.file.core.chinacloudapi.cn/mycontainer/myBlobDirectory?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' 'https://mydestinationaccount.file.core.chinacloudapi.cn/mycontainer?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' --recursive

将文件共享复制到另一个存储帐户Copy a file share to another storage account

语法Syntax azcopy copy 'https://<source-storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>?<SAS-token>' 'https://<destination-storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>?<SAS-token>' --recursive
示例Example azcopy copy 'https://mysourceaccount.file.core.chinacloudapi.cn/mycontainer?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' 'https://mydestinationaccount.file.core.chinacloudapi.cn/mycontainer?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' --recursive

将所有文件共享、目录和文件复制到另一个存储帐户Copy all file shares, directories, and files to another storage account

语法Syntax azcopy copy 'https://<source-storage-account-name>.file.core.chinacloudapi.cn/?<SAS-token>' 'https://<destination-storage-account-name>.file.core.chinacloudapi.cn/?<SAS-token>' --recursive'
示例Example azcopy copy 'https://mysourceaccount.file.core.chinacloudapi.cn?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' 'https://mydestinationaccount.file.core.chinacloudapi.cn?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' --recursive

同步文件Synchronize files

可将一个文件共享的内容与另一个文件共享同步。You can synchronize the contents of a file share with another file share. 还可将一个文件共享中的目录内容,与位于另一个文件共享中的目录内容同步。You can also synchronize the contents of a directory in a file share with the contents of a directory that is located in another file share. 同步是单向的。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.

备注

目前,只有不使用分层命名空间的帐户才支持此方案。Currently, this scenario is supported only for accounts that don't have a hierarchical namespace. 当前版本的 AzCopy 不会在 Azure 文件存储与 Blob 存储之间同步。The current release of AzCopy doesn't synchronize between Azure Files and Blob Storage.

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.

提示

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

方案Scenario 标志Flag
将访问控制列表 (ACL) 与文件一起复制。Copy access control lists (ACLs) along with the files. --preserve-smb-permissions=[true|false]--preserve-smb-permissions=[true|false]
将 SMB 属性信息与文件一起复制。Copy SMB property information along with the files. --preserve-smb-info=[true|false]--preserve-smb-info=[true|false]
基于模式排除文件。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.

使用对一个文件共享所做的更改来更新另一个文件共享Update a file share with changes to another file share

此命令中显示的第一个文件共享是源。The first file share that appears in this command is the source. 第二个文件共享是目标。The second one is the destination.

语法Syntax azcopy sync 'https://<source-storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>?<SAS-token>' 'https://<destination-storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>?<SAS-token>' --recursive
示例Example azcopy sync 'https://mysourceaccount.file.core.chinacloudapi.cn/myfileShare?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' 'https://mydestinationaccount.file.core.chinacloudapi.cn/myfileshare?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' --recursive

使用对另一个文件共享中的目录所做的更改来更新某个目录Update a directory with changes to a directory in another file share

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

语法Syntax azcopy sync 'https://<source-storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>/<directory-name>?<SAS-token>' 'https://<destination-storage-account-name>.file.core.chinacloudapi.cn/<file-share-name>/<directory-name>?<SAS-token>' --recursive
示例Example azcopy sync 'https://mysourceaccount.file.core.chinacloudapi.cn/myFileShare/myDirectory?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' 'https://mydestinationaccount.file.core.chinacloudapi.cn/myFileShare/myDirectory?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' --recursive

更新文件共享,使之与共享快照的内容匹配Update a file share to match the contents of a share snapshot

此命令中显示的第一个文件共享是源。The first file share that appears in this command is the source. 在 URI 的末尾追加字符串 &sharesnapshot=,后跟快照的 DateTime 值。At the end of the URI, append the string &sharesnapshot= followed by the DateTime value of the snapshot.

语法Syntax azcopy sync 'https://<source-storage-account-name>.file.core.chinacloudapi.cn/<file-share-name><SAS-token>&sharesnapsot<snapshot-ID>' 'https://<destination-storage-account-name>.file.core.chinacloudapi.cn/<file-share-name><SAS-token>' --recursive
示例Example azcopy sync 'https://mysourceaccount.file.core.chinacloudapi.cn/myfileShare?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D&sharesnapshot=2020-03-03T20%3A24%3A13.0000000Z' 'https://mydestinationaccount.file.core.chinacloudapi.cn/myfileshare?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' --recursive

若要详细了解共享快照,请参阅 Azure 文件存储的共享快照概述To learn more about share snapshots, see Overview of share snapshots for Azure Files.

后续步骤Next steps

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