首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用.NET的Azure管理库将Azure SQL数据库还原为点对点

如何使用.NET的Azure管理库将Azure SQL数据库还原为点对点
EN

Stack Overflow用户
提问于 2017-06-28 03:10:01
回答 2查看 1.1K关注 0票数 2

下面是使用Azure管理库创建数据库的方法,我想知道如何将现有数据库恢复为Azure上的实时数据库。

代码语言:javascript
复制
// Crate Authenticate
var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal("{clientId}", "{client-secret}", "{teantId}", AzureEnvironment.AzureGlobalCloud);

// Connect Azure
var azure = Azure
            .Configure()
            .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
            .Authenticate(credentials)
            .WithDefaultSubscription();

// Create TestDB
var sqlServer = azure.SqlServers.GetById("{sql-server-Id}");
sqlServer.Databases.Define("TestDB").Create();

// Point-in-time restore ???
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-06-28 06:33:41

解决了我自己。使用Microsoft.Azure.Management.Sql而不是Microsoft.Azure.Management.Sql.Fluent。

代码语言:javascript
复制
using Microsoft.Azure.Management.Sql.Models;
using Microsoft.Azure.Management.Sql;
using Microsoft.IdentityModel.Clients.ActiveDirectory;

private void RestoreToPointInTime()
{
    var token = GetToken("{tenantId}", "{applicationId}", "{appliactionSecret}");
    var sqlMgmtClient = new SqlManagementClient(new Microsoft.Rest.TokenCredentials(token.AccessToken)) { SubscriptionId = "{SubscriptionId}" };

    var myDb = sqlMgmtClient.Databases.Get("RestoreTest", "testsqlserver", "TestDB");

    var newDb = new Database
    {
        Location = myDb.Location,
        CreateMode = CreateMode.PointInTimeRestore,
        RestorePointInTime = myDb.EarliestRestoreDate.Value,
        SourceDatabaseId = myDb.Id
    };

    sqlMgmtClient.Databases.CreateOrUpdate("RestoreTest", "testsqlserver", "TestNewDB", newDb);
}

private static AuthenticationResult GetToken(string tenantId, string applicationId, string applicationSecret)
{
    AuthenticationContext authContext = new AuthenticationContext("https://login.windows.net/" + tenantId);
    return authContext.AcquireToken("https://management.core.windows.net/", new ClientCredential(applicationId, applicationSecret));
}
票数 6
EN

Stack Overflow用户

发布于 2017-06-28 05:30:40

您愿意使用REST吗?

https://learn.microsoft.com/es-es/rest/api/sql/databases%20-%20restore%20points

希望这能有所帮助。

致以敬意,

阿尔贝托·莫里洛

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44793003

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档