可以使用Azure ARM SqlManagementClient从时间点还原创建新数据库吗?

习俗

专门寻找一种方法来执行时间点还原到新数据库,保留原始数据库;使用托管API而不是REST API或模板

我到目前为止的代码:

    public async Task CreateDatabaseFromRestorePointAsync(
       string resourceGroupName, string serverName, 
       string databaseName, DateTime time) {

        using (SqlManagementClient sqlMgmtClient = GetSqlManagementClient())
        {
            DatabaseInner myDb = await sqlMgmtClient.Databases.GetAsync(
               resourceGroupName, serverName, databaseName);            

            var newDb = new DatabaseInner
            {
                Location = myDb.Location,
                CreateMode = CreateMode.PointInTimeRestore,
                // RestorePointInTime = time; 
                Edition = "Basic",
                SourceDatabaseId = myDb.Id                   
            };

            var result = await sqlMgmtClient.Databases.CreateOrUpdateAsync(
               resourceGroupName, serverName, "BackUpRestoreTestDb", newDb);               

            // Throws "The point in time was not specified for restoring live database...'"
        }
    }

发现以下内容:

并且相同的链接引用anew Database而不是DatabaseInner无法找到数据库对象的名称空间。

编辑1:专门从Brando Zhang的答案尝试了恢复方法,但是名称空间显然有所更改。我正在使用:

  • .Net 4.6.1

  • Microsoft.Azure.Management.Sql 1.6.0版预览

  • Microsoft.Azure.Management.Sql.Models

  • Microsoft.Azure.Management.Sql.Fluent 版本1.2.0

  • Microsoft.Azure.Management.Sql.Fluent.Models

获取命名空间找不到DatabaseCreateOrUpdateParametersDatabaseCreateOrUpdatePropertiesDatabaseCreateModeDatabaseCreateOrUpdateResponse

SqlManagementClient..sql..slq.fluent名称空间中都存在,它们.server在行中都找不到名称空间sqlMgmtClient.Servers.Get(resourceGroupName, serverName).Server;

搜索Microsoft的Azure管理命名空间时不走运。

但是google在西班牙MSDN网站上找到了DatabaseCreateOrUpdateParameters及其名称空间,该网站链接到上面。

贾里德·摩尔(Jared Moore)

这里的困惑是因为有3种不同的API:

  1. Microsoft.Azure.Management.Sql 版本<1.0
  2. Microsoft.Azure.Management.Sql版本> = 1.0(API参考:https//docs.microsoft.com/zh-cn/dotnet/api/microsoft.azure.management.sql?view = azure- dotnet
  3. Microsoft.Azure.Management.Sql.Fluent,它基于Microsoft.Azure.Management.Sql版本> = 1.0,旨在提供更人性化的设计,但不具备基本.Sql库的功能支持。(API参考:https : //docs.microsoft.com/zh-cn/dotnet/api/microsoft.azure.management.sql.fluent?view=azure-dotnet

白兰度的答案是针对#1 API的。要更新新API(#2)的代码,它应如下所示:

    // Create a database: configure create or update parameters and properties explicitly
    Database newDatabaseParameters = new Database()
    {
        Location = currentServer.Location,
        CreateMode = DatabaseCreateMode.PointInTimeRestore,
        Edition = databaseEdition,
        SourceDatabaseId = "/subscriptions/{yoursubscriptionid}/resourceGroups/{yourgroupid}/providers/Microsoft.Sql/servers/{sqlservername}/databases/{sqldatabasename}",
        RestorePointInTime = DateTime.Parse("2017-09-22T02:32:08Z"),//Restore Point time
    };

    Database db = sqlMgmtClient.Databases.CreateOrUpdate(resourceGroupName, serverName, databaseName, newDatabaseParameters);
    return db;

主要区别在于:

  1. 不再有单独的类一样DatabaseCreateOrUpdateParametersDatabaseCreateOrUpdatePropertiesDatabaseCreateOrUpdateResponse只有一堂课Database
  2. 的属性Database是“扁平化的”,因此没有内部Properties设置。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

是否可以使用ARM模板或脚本创建Azure Blob存储连接器?

是否可以使用 ARM 模板创建 CosmosDB?

AZURE - 是否可以使用 ARM 模板从备份中恢复

是否可以使用 arm 模板使用新的 lb 规则或运行状况探测更新现有的 azure 负载平衡器

用于在 Azure 虚拟机中创建新 sql 数据库的 Arm 模板

如何使用Azure ARM API复制数据库?

可以使用 sdk 创建 azure 数据块吗

是否可以使用ARM模板或Powershell部署Azure AD B2C服务?

是否可以使用 ARM 模板为 Azure Active Directory 应用程序配置 api 权限

使用ARM模板创建Azure存储队列

使用 ARM 模板创建 Azure IoThub 端点?

使用ARM模板部署Azure数据工厂

是否可以使用Azure文件存储创建Azure CDN?

Kubernetes-您可以使用x86上的主节点和arm上的工作节点构建集群吗?

有什么方法可以使用AVR指令集来完成ARM的“ STMIA”或“ LDMIA”功能吗?

使用ARM模板创建时如何设置VM操作系统以使其自动更新-Azure

通过ARM启用Azure SQL数据库自动调整

可以在ARM模板中获取Azure Function系统密钥吗?

可以开发非嵌套的azure arm firewallrules吗?

是否可以在ARM模板中创建documentDB数据库和帐户

可以使用Python编写Azure函数吗?

Azure WebJobs-我可以使用异步方法吗?

ARM 使用 NSG 创建子网

我可以使用ARM的LDR指令访问什么地址

有什么方法可以使用 ARM 模板完全自动化基于 QnAMaker 的 Azure Bot

使用私有端点创建 SQL 数据库的 ARM 模板

无法使用 Visual Studio 访问 Azure SQL 数据库,但可以使用 SSMS

Azure SQL:是否可以使用其他数据库中的视图?

可以使用 Python 作为数据库语言吗?