可以使用Azure ARM SqlManagementClient从时间点还原创建新数据库吗? [英] Possible to create new Database from Point In Time Restore using Azure ARMs SqlManagementClient?
问题描述
专门寻找一种方法来执行时间点还原到新数据库,保留原始数据库; 使用托管API而不是REST API或模板 .
Specifically looking for a way to perform point in time restore to a new Database, preserve the original database; using Managed API instead of REST API or Templates.
我到目前为止的代码:
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...'"
}
}
发现以下内容:
- 此SO链接同一链接引用了
new Database
而不是DatabaseInner
.无法找到数据库对象的名称空间.And same link references a
new Database
instead of aDatabaseInner
. Cant find Database objects namespace.- Databases - Create or Update
- Microsoft.Sql/servers/databases template reference.
Edit 1: Tried the restore method specifically from Brando Zhang's answer but there are apparently namespace changes. I'm using:
-
.Net 4.6.1
.Net 4.6.1
Microsoft.Azure.Management.Sql
1.6.0版预览Microsoft.Azure.Management.Sql.Models
Microsoft.Azure.Management.Sql.Fluent
版本1.2.0Microsoft.Azure.Management.Sql.Fluent.Models
找不到
DatabaseCreateOrUpdateParameters
,DatabaseCreateOrUpdateProperties
,DatabaseCreateMode
,DatabaseCreateOrUpdateResponse
的名称空间.Getting the namespace could not be found for
DatabaseCreateOrUpdateParameters
,DatabaseCreateOrUpdateProperties
,DatabaseCreateMode
,DatabaseCreateOrUpdateResponse
.SqlManagementClient
同时存在于..sql
和..slq.fluent
命名空间中,它们都没有在sqlMgmtClient.Servers.Get(resourceGroupName, serverName).Server;
SqlManagementClient
exists in both..sql
and..slq.fluent
namespaces both of which do not find namespace for.server
in the linesqlMgmtClient.Servers.Get(resourceGroupName, serverName).Server;
搜索了 Microsoft的Azure管理命名空间,没有运气.
但是Google在西班牙语的MSDN网站,该链接指向上方.
But google found DatabaseCreateOrUpdateParameters and its namespace on a spanish MSDN site, which links to above.
推荐答案
此处的困惑是因为存在3种不同的API:
The confusion here is because there are 3 different API's:
-
Microsoft.Azure.Management.Sql
版本< 1.0 -
Microsoft.Azure.Management.Sql
版本> = 1.0(API参考: https://docs.microsoft.com/zh-cn/dotnet/api/microsoft.azure.management.sql.fluent?view=azure-dotnet )
Microsoft.Azure.Management.Sql
version < 1.0Microsoft.Azure.Management.Sql
version >= 1.0 (API reference: https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.management.sql?view=azure-dotnet)Microsoft.Azure.Management.Sql.Fluent
, which is based onMicrosoft.Azure.Management.Sql
version >= 1.0 and is intended to be a more human-friendly design but does not have as much feature support as the base .Sql library. (API reference: https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.management.sql.fluent?view=azure-dotnet)
Brando的答案是针对#1 API的.要更新新API(#2)的代码,它应如下所示:
Brando's answer is for the #1 API. To update the code for the new API (#2), it should look like this:
// 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;
主要区别在于:
- 不再有单独的类,例如
DatabaseCreateOrUpdateParameters
,DatabaseCreateOrUpdateProperties
,DatabaseCreateOrUpdateResponse
.只有一个类Database
. -
Database
的属性被拉平",因此没有内部Properties
可以设置.
- There is no longer separate classes like
DatabaseCreateOrUpdateParameters
,DatabaseCreateOrUpdateProperties
,DatabaseCreateOrUpdateResponse
. There is just one classDatabase
. - The properties of
Database
are "flattened" so there is no innerProperties
to set.
这篇关于可以使用Azure ARM SqlManagementClient从时间点还原创建新数据库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!