简体   繁体   English

如何将 Azure 存储帐户内容(表、队列、blob)复制到其他存储帐户

[英]How to copy Azure storage account contents (tables, queues, blobs) to other storage account

I'm using Azure Durable Functions and I want to make a copy of the "production data" storage account to another storage account, to test out some things (such as data migration strategies, performance and other issues).我正在使用 Azure Durable Functions,我想将“生产数据”存储帐户复制到另一个存储帐户,以测试一些东西(例如数据迁移策略、性能和其他问题)。

For that, I was hoping to find the easiest and most out of the box way, to just copy the full contents of an Azure Storage Account to another Storage Account.为此,我希望找到最简单和最开箱即用的方法,将 Azure 存储帐户的全部内容复制到另一个存储帐户。

Is there something out there?外面有东西吗? Or maybe a PowerShell script that can perform this?或者可以执行此操作的 PowerShell 脚本?

(replication only works for blob objects) (复制仅适用于 blob 对象)

Best regards最好的祝福

Azure Storage accounts are made up of 4 different types of storage: blobs, fileshares, queues and tables. Azure 存储帐户由 4 种不同类型的存储组成:blob、文件共享、队列和表。 Different methods and/or strategies will be required to copy each type to a new storage account.将每种类型复制到新的存储帐户需要不同的方法和/或策略。

There are many tools you could use to automate the process including the Az PowerShell module, the az cli and the Azure REST API. Not all tools provide methods for working with all 4 types of storage.您可以使用许多工具来自动化该过程,包括 Az PowerShell 模块、az cli 和 Azure REST API。并非所有工具都提供处理所有 4 种存储类型的方法。

First you will need to create a new storage account to copy your data to.首先,您需要创建一个新的存储帐户以将数据复制到其中。 Be aware that account names are globally unique not just unique within your tenant, are limited to 24 characters in length and can only be made up of lowercase letters and numbers.请注意,帐户名称在全球范围内是唯一的,而不仅仅是在您的租户内唯一,长度限制为 24 个字符,并且只能由小写字母和数字组成。 You could use the New-AzStorageAccount PowerShell cmdlet to create the new account.您可以使用New-AzStorageAccount PowerShell cmdlet 创建新帐户。

Blobs斑点

Blob storage is made up of containers that hold blobs in a flat file structure. Blob 存储由以平面文件结构保存 Blob 的容器组成。 You will need to recreate each container from your source account, this could be done using the PowerShell cmdlet New-AzStorageContainer .您将需要从您的源帐户重新创建每个容器,这可以使用 PowerShell cmdlet New-AzStorageContainer来完成。 Once the containers have been created you can use Start-AzStorageBlobCopy to copy the blobs from the container in your source account to the container in your new account.创建容器后,您可以使用Start-AzStorageBlobCopy将 blob 从源帐户中的容器复制到新帐户中的容器。

Fileshares文件共享

The storage account can contain multiple fileshares each containing a nested folder structure of varying depth.存储帐户可以包含多个文件共享,每个文件共享包含不同深度的嵌套文件夹结构。 You can create a new file share in your destination account using New-AzStorageShare .可以使用New-AzStorageShare在目标帐户中创建新的文件共享。 Once you've recreated your fileshares you'll need to recurse through the folder structure in each share to get all the files.重新创建文件共享后,您需要递归遍历每个共享中的文件夹结构以获取所有文件。 You can then use New-AzStorageDirectory to recreate the folder structure and Start-AzStorageFileCopy to copy the files into the new fileshare.然后可以使用New-AzStorageDirectory重新创建文件夹结构,并使用Start-AzStorageFileCopy将文件复制到新的文件共享中。

Queues队列

As queues use a publisher subscriber model and the data is transient it may be easiest to recreate the queue and use a variation on the method your current publisher uses to populate the new queue with data.由于队列使用发布者订阅者 model 并且数据是瞬态的,因此重新创建队列并使用当前发布者使用数据填充新队列的方法的变体可能是最简单的方法。 You can use New-AzStorageQueue to create the new queue.可以使用New-AzStorageQueue创建新队列。 Alternatively you could create the new queue and repoint the publisher to it and only repoint the subscripers once the old queue is drained.或者,您可以创建新队列并将发布者重新指向它,并且仅在旧队列耗尽后才重新指向订阅者。 For your use case the first approach may be more suitable.对于您的用例,第一种方法可能更合适。

Tables

The storage account can contain multiple tables each containing multiple rows of data.存储帐户可以包含多个表,每个表包含多行数据。 You can use New-AzStorageTable to recreate the tables but this will not copy over the data they contain.您可以使用New-AzStorageTable重新创建表,但这不会复制它们包含的数据。 Unfortunately there isn't a cmdlet in the Az module to do this but the AzTable module contains the Get-AzTableRow and Add-AzTableRow cmdlets which should allow you to copy the rows to the new table.不幸的是,Az 模块中没有执行此操作的 cmdlet,但AzTable 模块包含Get-AzTableRowAdd-AzTableRow cmdlet,它们应该允许您将行复制到新表。

Summary概括

In practice implementing all this will require quite a lengthy script which will only grow if you need the process to handle large volumes of data and handle errors to ensure an accurate copy.在实践中,实现所有这些将需要相当长的脚本,只有当您需要该过程处理大量数据并处理错误以确保准确复制时,该脚本才会增长。 I've developed a script that handles blobs and fileshares which was sufficiently robust and quick enough for the hobby project I needed it for.我已经开发了一个处理 blob 和文件共享的脚本,它对于我需要它的业余项目来说足够强大和快速。 However, it took several hours to copy around 10 accounts the largest of which contained less than 1Gb of data so probably won't scale well to a commercial environment.然而,复制大约 10 个帐户需要几个小时,其中最大的帐户包含不到 1Gb 的数据,因此可能无法很好地扩展到商业环境。 The script can be found here if you wish to use it as a starting point.如果您希望将其用作起点,可以在此处找到该脚本。

Potentially you can try azcopy functionality, have a look here :您可能可以尝试 azcopy 功能,请看这里

azcopy copy 'https://mysourceaccount.blob.core.windows.net/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.blob.core.windows.net/mycontainer' --recursive

The example above copies the whole container from one account to another.上面的示例将整个容器从一个帐户复制到另一个帐户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM