在 Azure Stack Hub 存储中使用数据传输工具Use data transfer tools in Azure Stack Hub Storage

Azure Stack Hub 提供一组存储服务,适用于磁盘、Blob、表、队列以及帐户管理功能。Azure Stack Hub provides a set of storage services for disks, blobs, tables, queues, and account management functions. 如果需要通过 Azure Stack Hub 存储管理或移动数据,可以使用一些 Azure 存储工具。Some Azure Storage tools are available if you want to manage or move data to or from Azure Stack Hub Storage. 本文概述了可用的工具。This article provides an overview of the available tools.

你的需求决定了以下哪些工具最适合你:Your requirements determine which of the following tools works best for you:

  • AzCopyAzCopy

    一个特定于存储的命令行实用工具,下载后即可在存储帐户中将数据从一个对象复制到另一个对象,或者在存储帐户之间复制。A storage-specific, command-line utility that you can download to copy data from one object to another object within or between your storage accounts.

  • Azure PowerShellAzure PowerShell

    一种基于任务的命令行 Shell 和脚本语言,专为系统管理而设计。A task-based, command-line shell and scripting language designed especially for system administration.

  • Azure CLIAzure CLI

    一种开源的跨平台工具,提供了一组适用于 Azure 和 Azure Stack Hub 平台的命令。An open-source, cross-platform tool that provides a set of commands for working with the Azure and Azure Stack Hub platforms.

  • Microsoft Azure 存储资源管理器Microsoft Azure Storage Explorer

    一个易于使用的独立应用,带有用户界面。An easy-to-use stand-alone app with a user interface.

  • BlobfuseBlobfuse

    一个适用于 Azure Blob 存储的虚拟文件系统驱动程序,用于通过 Linux 文件系统访问存储帐户中的现有块 Blob 数据。A virtual file system driver for Azure Blob Storage, which allows you to access your existing block blob data in your storage account through the Linux file system.

由于 Azure 和 Azure Stack Hub 之间具有存储服务差异,因此,以下部分中描述的每个工具可能存在一些特定的要求。Because of storage services differences between Azure and Azure Stack Hub, there might be some specific requirements for each tool described in the following sections. 若要了解 Azure Stack Hub 存储和 Azure 存储之间的比较情况,请参阅 Azure Stack Hub 存储:差异和注意事项For a comparison between Azure Stack Hub Storage and Azure Storage, see Azure Stack Hub Storage: Differences and considerations.

AzCopyAzCopy

AzCopy 是一个命令行实用程序,专用于通过简单的可以优化性能的命令将数据复制到 Azure Blob、表存储以及从这些位置复制数据。AzCopy is a command-line utility designed to copy data to and from Azure blob and table storage using simple commands with optimal performance. 可在存储帐户中将数据从一个对象复制到另一个对象,或者在存储帐户之间复制。You can copy data from one object to another within or between your storage accounts.

下载并安装 AzCopyDownload and install AzCopy

AzCopy 10.1 配置和限制AzCopy 10.1 configuration and limits

AzCopy 10.1 现在可以配置为使用旧版 API。AzCopy 10.1 is now able to be configured to use older API versions. 这样就可以为 Azure Stack Hub 提供(有限的)支持。This enables (limited) support for Azure Stack Hub. 若要将 AzCopy 的 API 版本配置为支持 Azure Stack Hub,请将 AZCOPY_DEFAULT_SERVICE_API_VERSION 环境变量设置为 2017-11-09To configure the API version for AzCopy to support Azure Stack Hub, set the AZCOPY_DEFAULT_SERVICE_API_VERSION environment variable to 2017-11-09.

操作系统Operating system 命令Command
WindowsWindows 在命令提示符处使用 set AZCOPY_DEFAULT_SERVICE_API_VERSION=2017-11-09In a command prompt use: set AZCOPY_DEFAULT_SERVICE_API_VERSION=2017-11-09
在 PowerShell 中使用 $env:AZCOPY_DEFAULT_SERVICE_API_VERSION="2017-11-09"In PowerShell use: $env:AZCOPY_DEFAULT_SERVICE_API_VERSION="2017-11-09"
LinuxLinux export AZCOPY_DEFAULT_SERVICE_API_VERSION=2017-11-09
MacOSMacOS export AZCOPY_DEFAULT_SERVICE_API_VERSION=2017-11-09

在 AzCopy 10.1 中,支持适用于 Azure Stack Hub 的以下功能:In AzCopy 10.1, the following features are supported for Azure Stack Hub:

功能Feature 支持的操作Supported actions
管理容器Manage container 创建容器Create a container
列出容器的内容List contents of containers
管理作业Manage job 显示作业Display jobs
恢复作业Resume a job
删除 BlobRemove blob 删除单个 BlobRemove a single blob
删除整个或部分虚拟目录Remove entire or partial virtual directory
上传文件Upload file 上传文件Upload a file
上传目录Upload a directory
上传目录的内容Upload the contents of a directory
下载文件Download file 下载文件Download a file
下载目录Download a directory
下载目录的内容Download the contents of a directory
同步文件Synchronize file 将容器同步到本地文件系统Synchronize a container to a local file system
将本地文件系统同步到容器Synchronize a local file system to a container

备注

  • Azure Stack Hub 不支持使用 Azure Active Directory (AD) 向 AzCopy 提供授权凭据。Azure Stack Hub doesn't support providing authorization credentials to AzCopy by using Azure Active Directory (AD). 必须使用共享访问签名 (SAS) 令牌访问 Azure Stack Hub 上的存储对象。You must access storage objects on Azure Stack Hub using a Shared Access Signature (SAS) token.
  • Azure Stack Hub 不支持在两个 Azure Stack Hub Blob 位置之间以及 Azure 存储和 Azure Stack Hub 之间进行同步数据传输。Azure Stack Hub doesn't support synchronous data transfer between two Azure Stack Hub blob locations, and between Azure Storage and Azure Stack Hub. 不能直接在 AzCopy 10.1 中使用“azcopy cp”将数据从 Azure Stack Hub 移到 Azure 存储(反之亦然)。You can't use "azcopy cp" to move data from Azure Stack Hub to Azure Storage (or the other way around) directly with AzCopy 10.1.

针对数据传输的 AzCopy 命令示例AzCopy command examples for data transfer

以下示例展示了将数据复制到 Azure Stack Hub Blob 以及从这些位置复制数据的典型方案。The following examples follow typical scenarios for copying data to and from Azure Stack Hub blobs. 若要了解详细信息,请参阅 AzCopy 入门To learn more, see Get started with AzCopy.

将所有 Blob 下载到本地磁盘Download all blobs to a local disk

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

将单个文件上传到虚拟目录Upload single file to virtual directory

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

AzCopy 已知问题AzCopy known issues

  • 在文件存储上执行的任何 AzCopy 操作都不可用,因为文件存储在 Azure Stack Hub 中不可用。Any AzCopy operation on a file storage isn't available because file storage isn't yet available in Azure Stack Hub.
  • 若要使用 AzCopy 10.1 在两个 Azure Stack Hub Blob 位置之间或 Azure Stack Hub 和 Azure 存储之间传输数据,需先将数据下载到本地位置,然后将数据重新上传到 Azure Stack Hub 或 Azure 存储上的目标目录。If you want to transfer data between two Azure Stack Hub blob locations-or between Azure Stack Hub and Azure Storage by using AzCopy 10.1-you need to download the data to a local location first, and then reupload to the target directory on Azure Stack Hub or Azure Storage. 也可使用 AzCopy 7.1 通过 /SyncCopy 选项来指定传输,以便复制数据。Or you can use AzCopy 7.1, and specify the transfer with the /SyncCopy option to copy the data.
  • AzCopy 的 Linux 版本仅支持 1802 更新或更高版本,不支持表服务。The Linux version of AzCopy only supports the 1802 update or later versions and it doesn't support Table service.
  • 如果要向/从 Azure 表存储服务复制数据,则安装 AzCopy 版本 7.3.0If you want to copy data to and from your Azure Table storage service, then install AzCopy version 7.3.0

Azure PowerShellAzure PowerShell

Azure PowerShell 是一个模块,它提供的 cmdlet 用于管理 Azure 和 Azure Stack Hub 上的服务。Azure PowerShell is a module that provides cmdlets for managing services on both Azure and Azure Stack Hub. 这是一种基于任务的命令行 Shell 和脚本语言,专为系统管理而设计。It's a task-based, command-line shell and scripting language designed especially for system administration.

安装和配置适用于 Azure Stack Hub 的 PowerShellInstall and Configure PowerShell for Azure Stack Hub

需要安装与 Azure Stack Hub 兼容的 Azure PowerShell 模块才能使用 Azure Stack Hub。Azure Stack Hub compatible Azure PowerShell modules are required to work with Azure Stack Hub. 有关详细信息,请参阅安装适用于 Azure Stack Hub 的 PowerShell配置 Azure Stack Hub 用户的 PowerShell 环境For more information, see Install PowerShell for Azure Stack Hub and Configure the Azure Stack Hub user's PowerShell environment.

适用于 Azure Stack Hub 的 PowerShell 示例脚本PowerShell Sample script for Azure Stack Hub

此示例假定你已成功安装了适用于 Azure Stack Hub 的 PowerShellThis sample assumes you have successfully Installed PowerShell for Azure Stack Hub. 此脚本会帮助你完成配置,然后要求你提供 Azure Stack Hub 租户凭据,以便将你的帐户添加到本地 PowerShell 环境。This script will help you complete the configuration and ask your Azure Stack Hub tenant credentials to add your account to the local PowerShell environment. 然后,该脚本会设置默认的 Azure 订阅、在 Azure 中创建新的存储帐户、在此新的存储帐户中创建新容器,并将现有图像文件 (Blob) 上传到该容器。The script will then set the default Azure subscription, create a new storage account in Azure, create a new container in this new storage account, and upload an existing image file (blob) to that container. 在脚本列出该容器中的所有 Blob 后,它会在本地计算机中创建新的目标目录,并下载图像文件。After the script lists all blobs in that container, it will create a new destination directory on your local computer and download the image file.

  1. 安装 Azure Stack Hub 兼容的 Azure PowerShell 模块Install Azure Stack Hub-compatible Azure PowerShell modules.
  2. 下载使用 Azure Stack Hub 所需的工具Download the tools required to work with Azure Stack Hub.
  3. 打开 Windows PowerShell ISE,选择“以管理员身份运行”, 然后单击“文件” > “新建”以创建新的脚本文件。Open Windows PowerShell ISE and Run as Administrator, then click File > New to create a new script file.
  4. 复制下面的脚本并将其粘贴到新的脚本文件。Copy the script below and paste it to the new script file.
  5. 根据配置设置更新脚本变量。Update the script variables based on your configuration settings.

    备注

    此脚本必须在 AzureStack_Tools 的根目录中运行。This script has to be run at the root directory for AzureStack_Tools.

# begin

$ARMEvnName = "AzureStackUser" # set AzureStackUser as your Azure Stack Hub environment name
$ARMEndPoint = "https://management.local.azurestack.external" 
$GraphAudience = "https://graph.chinacloudapi.cn/" 
$AADTenantName = "<myDirectoryTenantName>.partner.onmschina.cn" 

$SubscriptionName = "basic" # Update with the name of your subscription.
$ResourceGroupName = "myTestRG" # Give a name to your new resource group.
$StorageAccountName = "azsblobcontainer" # Give a name to your new storage account. It must be lowercase.
$Location = "Local" # Choose "Local" as an example.
$ContainerName = "photo" # Give a name to your new container.
$ImageToUpload = "C:\temp\Hello.jpg" # Prepare an image file and a source directory in your local computer.
$DestinationFolder = "C:\temp\download" # A destination directory in your local computer.

# Import the Connect PowerShell module"
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
Import-Module .\Connect\AzureStack.Connect.psm1

# Configure the PowerShell environment
# Register an AzureRM environment that targets your Azure Stack Hub instance
Add-AzureRmEnvironment -Name $ARMEvnName -ARMEndpoint $ARMEndPoint 

# Login
$TenantID = Get-AzsDirectoryTenantId -AADTenantName $AADTenantName -EnvironmentName $ARMEvnName
Add-AzureRmAccount -EnvironmentName $ARMEvnName -TenantId $TenantID 

# Set a default Azure subscription.
Select-AzureRmSubscription -SubscriptionName $SubscriptionName

# Create a new Resource Group 
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location

# Create a new storage account.
New-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageAccountName -Location $Location -Type Standard_LRS

# Set a default storage account.
Set-AzureRmCurrentStorageAccount -StorageAccountName $StorageAccountName -ResourceGroupName $ResourceGroupName 

# Create a new container.
New-AzureStorageContainer -Name $ContainerName -Permission Off

# Upload a blob into a container.
Set-AzureStorageBlobContent -Container $ContainerName -File $ImageToUpload

# List all blobs in a container.
Get-AzureStorageBlob -Container $ContainerName

# Download blobs from the container:
# Get a reference to a list of all blobs in a container.
$blobs = Get-AzureStorageBlob -Container $ContainerName

# Create the destination directory.
New-Item -Path $DestinationFolder -ItemType Directory -Force  

# Download blobs into the local destination directory.
$blobs | Get-AzureStorageBlobContent -Destination $DestinationFolder

# end

PowerShell 已知问题PowerShell known issues

目前兼容的 Azure Stack Hub 的 Azure PowerShell 模块版本为 1.2.11,用于用户操作。The current compatible Azure PowerShell module version for Azure Stack Hub is 1.2.11 for the user operations. 它不同于最新版本的 Azure PowerShell。It's different from the latest version of Azure PowerShell. 这种差异以下述方式影响存储服务操作:This difference impacts storage services operation in the following way:

在版本 1.2.11 中,Get-AzureRmStorageAccountKey 的返回值格式有两个属性:Key1Key2,而当前的 Azure 版本返回的数组包含所有帐户密钥。The return value format of Get-AzureRmStorageAccountKey in version 1.2.11 has two properties: Key1 and Key2, while the current Azure version returns an array containing all the account keys.

# This command gets a specific key for a storage account, 
# and works for Azure PowerShell version 1.4, and later versions.
(Get-AzureRmStorageAccountKey -ResourceGroupName "RG01" `
-AccountName "MyStorageAccount").Value[0]

# This command gets a specific key for a storage account, 
# and works for Azure PowerShell version 1.3.2, and previous versions.
(Get-AzureRmStorageAccountKey -ResourceGroupName "RG01" `
-AccountName "MyStorageAccount").Key1

有关详细信息,请参阅 Get-AzureRmStorageAccountKeyFor more information, see Get-AzureRmStorageAccountKey.

Azure CLIAzure CLI

Azure CLI 是 Azure 的命令行体验,用于管理 Azure 资源。The Azure CLI is Azure's command-line experience for managing Azure resources. 可以将其安装在 macOS、Linux 和 Windows 上,然后从命令行运行。You can install it on macOS, Linux, and Windows and run it from the command line.

Azure CLI 经过优化,可用于从命令行管理 Azure 资源,以及生成可以针对 Azure 资源管理器运行的自动化脚本。Azure CLI is optimized for managing and administering Azure resources from the command line, and for building automation scripts that work against the Azure Resource Manager. 它提供 Azure Stack Hub 门户所提供的许多功能,包括各种数据访问功能。It provides many of the same functions found in the Azure Stack Hub portal, including rich data access.

Azure Stack Hub 需要 Azure CLI 2.0 版或更高版本。Azure Stack Hub requires Azure CLI version 2.0 or later. 若要详细了解如何通过 Azure Stack Hub 来安装和配置 Azure CLI,请参阅安装和配置 Azure Stack Hub CLIFor more information about installing and configuring Azure CLI with Azure Stack Hub, see Install and configure Azure Stack Hub CLI. 若要详细了解如何使用 Azure CLI 执行多个可利用 Azure Stack Hub 存储帐户中资源的任务,请参阅将 Azure CLI 与 Azure 存储配合使用For more information about how to use the Azure CLI to perform several tasks working with resources in your Azure Stack Hub storage account, see Using the Azure CLI with Azure storage

适用于 Azure Stack Hub 的 Azure CLI 示例脚本Azure CLI sample script for Azure Stack Hub

完成 CLI 安装和配置后,可尝试以下步骤,使用一个小的 shell 示例脚本来与 Azure Stack Hub 存储资源交互。Once you complete the CLI installation and configuration, you can try the following steps to work with a small shell sample script to interact with Azure Stack Hub storage resources. 此脚本完成以下操作:The script completes the following actions:

  • 在存储帐户中创建一个新容器。Creates a new container in your storage account.
  • 将一个现有文件(作为 Blob)上传到该容器。Uploads an existing file (as a blob) to the container.
  • 列出该容器中的所有 Blob。Lists all blobs in the container.
  • 将文件下载到本地计算机上的指定目标。Downloads the file to a destination on your local computer that you specify.

运行此脚本之前,请确保可以成功连接并登录到目标 Azure Stack Hub。Before you run this script, make sure that you can successfully connect and sign in to the target Azure Stack Hub.

  1. 打开偏好的文本编辑器,将前面的脚本复制并粘贴到编辑器中。Open your favorite text editor, then copy and paste the preceding script into the editor.
  2. 更新脚本的变量,使之反映配置设置。Update the script's variables to reflect your configuration settings.
  3. 更新所需的变量后,保存脚本并退出编辑器。After you've updated the necessary variables, save the script, and exit your editor. 后续步骤假定已将脚本命名为 my_storage_sample.sh 。The next steps assume you've named your script my_storage_sample.sh.
  4. 如果需要,请将脚本标记为可执行文件:chmod +x my_storage_sample.shMark the script as executable, if necessary: chmod +x my_storage_sample.sh
  5. 执行该脚本。Execute the script. 例如,在 Bash 中: ./my_storage_sample.shFor example, in Bash: ./my_storage_sample.sh
#!/bin/bash
# A simple Azure Stack Hub storage example script

export AZURESTACK_RESOURCE_GROUP=<resource_group_name>
export AZURESTACK_RG_LOCATION="local"
export AZURESTACK_STORAGE_ACCOUNT_NAME=<storage_account_name>
export AZURESTACK_STORAGE_CONTAINER_NAME=<container_name>
export AZURESTACK_STORAGE_BLOB_NAME=<blob_name>
export FILE_TO_UPLOAD=<file_to_upload>
export DESTINATION_FILE=<destination_file>

echo "Creating the resource group..."
az group create --name $AZURESTACK_RESOURCE_GROUP --location $AZURESTACK_RG_LOCATION

echo "Creating the storage account..."
az storage account create --name $AZURESTACK_STORAGE_ACCOUNT_NAME --resource-group $AZURESTACK_RESOURCE_GROUP --account-type Standard_LRS

echo "Creating the blob container..."
az storage container create --name $AZURESTACK_STORAGE_CONTAINER_NAME --account-name $AZURESTACK_STORAGE_ACCOUNT_NAME

echo "Uploading the file..."
az storage blob upload --container-name $AZURESTACK_STORAGE_CONTAINER_NAME --file $FILE_TO_UPLOAD --name $AZURESTACK_STORAGE_BLOB_NAME --account-name $AZURESTACK_STORAGE_ACCOUNT_NAME

echo "Listing the blobs..."
az storage blob list --container-name $AZURESTACK_STORAGE_CONTAINER_NAME --account-name $AZURESTACK_STORAGE_ACCOUNT_NAME --output table

echo "Downloading the file..."
az storage blob download --container-name $AZURESTACK_STORAGE_CONTAINER_NAME --account-name $AZURESTACK_STORAGE_ACCOUNT_NAME --name $AZURESTACK_STORAGE_BLOB_NAME --file $DESTINATION_FILE --output table

echo "Done"

Microsoft Azure 存储资源管理器Microsoft Azure Storage Explorer

Azure 存储资源管理器是 Microsoft 提供的独立应用,Azure Storage Explorer is a standalone app from Microsoft. 它可用来在 Windows、macOS 和 Linux 计算机上轻松处理 Azure 存储和 Azure Stack Hub 存储数据。It allows you to easily work with both Azure Storage and Azure Stack Hub Storage data on Windows, macOS, and Linux computers. 如果希望通过某种方式轻松管理 Azure Stack Hub 存储数据,请考虑使用 Microsoft Azure 存储资源管理器。If you want an easy way to manage your Azure Stack Hub Storage data, then consider using Microsoft Azure Storage Explorer.

BlobfuseBlobfuse

Blobfuse 是适用于 Azure Blob 存储的虚拟文件系统驱动程序,用于通过 Linux 文件系统访问存储帐户中的现有块 Blob 数据。Blobfuse is a virtual file system driver for Azure Blob Storage, which allows you to access your existing block blob data in your storage account through the Linux file system. Azure Blob 存储是一项对象存储服务,因此没有分层命名空间。Azure Blob Storage is an object storage service and therefore doesn't have a hierarchical namespace. Blobfuse 使用虚拟目录方案提供这种命名空间,并使用正斜杠“/”作为分隔符。Blobfuse provides this namespace using the virtual directory scheme with the use of forward-slash / as a delimiter.

对于 Azure Stack Hub,在配置存储帐户凭据时,除了 accountName、accountKey/sasToken、containerName 之外,还需要指定 blobEndpointFor Azure Stack Hub, blobEndpoint needs to be specified while configuring your storage account credentials along with accountName, accountKey/sasToken, and containerName.

在 Azure Stack 开发工具包 (ASDK) 中,blobEndpoint 应当为 myaccount.blob.local.azurestack.externalIn the Azure Stack Development Kit (ASDK), the blobEndpoint should be myaccount.blob.local.azurestack.external. 在 Azure Stack Hub 集成系统中,如果不确定你的终结点,请与云管理员联系。In Azure Stack Hub integrated system, contact your cloud admin if you're not sure about your endpoint.

accountKeysasToken 一次只能配置一个。accountKey and sasToken can only be configured one at a time. 提供存储帐户密钥时,凭据配置文件采用以下格式:When a storage account key is given, the credentials configuration file is in the following format:

accountName myaccount 
accountKey myaccesskey== 
containerName mycontainer 
blobEndpoint myaccount.blob.local.azurestack.external

提供共享访问密钥时,凭据配置文件采用以下格式:When a shared access token is given, the credentials configuration file is in the following format:

accountName myaccount 
sasToken ?mysastoken 
containerName mycontainer 
blobEndpoint myaccount.blob.local.azurestack.external

后续步骤Next steps