azure - 将 Azure 表存储迁移到 Cosmos DB

标签 azure azure-table-storage azure-data-factory azure-cosmosdb

是否有任何工具可用于将 Azure 表存储迁移到 Cosmos DB 以使用表 API 进行访问?我发现Data Migration Tool但仅支持通过Document API访问表存储。

更新:我尝试了数据工厂复制数据功能,将表存储复制到文档数据库(我猜现在是 cosomosDb)。但它没有将任何数据复制到 Cosmos DB,尽管数据工厂管道表示它复制了如此多的数据,但我在 objective-c osmos Db 表中没有看到任何实体。

迁移到 Cosmos DB 并使用表 API 的最佳方式是什么?

最佳答案

What is the best way to migrate to Cosmos DB and use Table APIs ?

如果我理解正确的话,您希望将 Azure 表存储迁移到 Cosmos 表 API DB。如果是这种情况并且程序可行,我们可以使用 Azure 提供的 Windows Azure Storage Premium Table 来做到这一点SDK。它是预览版本。以下是我的演示代码,它可以正常工作。

1.我们需要实现TableEntity并添加我们的自定义属性。属性区分大小写

    public class CustomerEntity : TableEntity
    {

        public CustomerEntity() { }
        public Type tableEntityProperty { get; set; } 
        ...
    }

2.添加获取云表功能

public static CloudTable GetTable(string connectionstring,string tableName)
        {
            CloudStorageAccount destStorageAccount = CloudStorageAccount.Parse(connectionstring);
            CloudTableClient destTableClient = destStorageAccount.CreateCloudTableClient();
            CloudTable destTable = destTableClient.GetTableReference(tableName);
            destTable.CreateIfNotExists();
            return destTable;
        }

3.尝试从Azure存储表中查询表实体并将其添加到Azure cosmos表中。

  var sourceConnectionString = "DefaultEndpointsProtocol=https;AccountName=storageName;AccountKey=yourkey;EndpointSuffix=core.windows.net";
  var destConnectionstring = "DefaultEndpointsProtocol=https;AccountName=cosmostableAPIAccount;AccountKey=yourkey;TableEndpoint=https://tomtableapi.documents.azure.com";

  CloudTable sourceTable = GetTable(sourceConnectionString, "source table");
  CloudTable destTable = GetTable(destConnectionstring, "dest table");
  TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>();

     foreach (CustomerEntity entity in sourceTable.ExecuteQuery(query))
     {
          TableOperation insertOperation = TableOperation.Insert(entity);
          // Execute the insert operation.
          destTable.Execute(insertOperation);
     }

包.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.Azure.DocumentDB" version="1.14.0" targetFramework="net462" />
  <package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.Data.Edm" version="5.8.2" targetFramework="net462" />
  <package id="Microsoft.Data.OData" version="5.8.2" targetFramework="net462" />
  <package id="Microsoft.Data.Services.Client" version="5.8.2" targetFramework="net462" />
  <package id="Microsoft.OData.Core" version="7.2.0" targetFramework="net462" />
  <package id="Microsoft.OData.Edm" version="7.2.0" targetFramework="net462" />
  <package id="Microsoft.Spatial" version="7.2.0" targetFramework="net462" />
  <package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.3" targetFramework="net462" />
  <package id="Newtonsoft.Json" version="6.0.8" targetFramework="net462" />
  <package id="System.ComponentModel.EventBasedAsync" version="4.0.11" targetFramework="net462" />
  <package id="System.Dynamic.Runtime" version="4.0.0" targetFramework="net462" />
  <package id="System.Linq.Queryable" version="4.0.0" targetFramework="net462" />
  <package id="System.Net.Requests" version="4.0.11" targetFramework="net462" />
  <package id="System.Spatial" version="5.8.2" targetFramework="net462" />
  <package id="WindowsAzure.Storage-PremiumTable" version="0.1.0-preview" targetFramework="net462" />
</packages>

关于azure - 将 Azure 表存储迁移到 Cosmos DB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44460758/

相关文章:

powershell - Azure:使用 Powershell 从 Azure 存储中删除所有 *test.zip blob

c# - 从代码创建 Azure 数据库登录会引发 SqlException

javascript - 在 Azure 中处理多个异步请求?

c# - 如何在C#中获取Azure表存储中的所有行?

c# - WebJob 极大地减慢了我的网站速度

node.js - 测量 websocket 性能的工具

c# - 删除azure表存储行而不检查是否存在

azure - 失败的数据工厂管道在重新运行时是否保留其原始输入?

azure - 如何在 Azure DevOps 中等待 Azure 数据工厂管道完成?

excel - 如何在Azure数据工厂中读取扩展名为.xlsx和.xls的文件?