Reputation: 35
I need to programatically restore an SQL Azure database from a .NET Core 2.1 C# function. On Recover an Azure SQL database using automated database backups article shows how to do it with PowerShell or REST API. What I found in C# does not work on .NET Core.
Do you have any suggestion?
Thank you.
Upvotes: 1
Views: 656
Reputation: 15571
You can call the REST API and use PointInTimeRestore
as the CreateMode.
PointInTimeRestore: Creates a database by restoring a point in time backup of an existing database. sourceDatabaseId must be specified as the resource ID of the existing database, and restorePointInTime must be specified.
More info to be found here: Databases - Create Or Update. And be sure to take a look at the examples
For instance, this would create a database from PointInTimeRestore:
Request:
PUT https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/servers/testsvr/databases/dbpitr?api-version=2017-10-01-preview
Body:
{
"location": "southeastasia",
"sku": {
"name": "S0",
"tier": "Standard"
},
"properties": {
"createMode": "PointInTimeRestore",
"sourceDatabaseId": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/servers/testsvr/databases/testdb",
"restorePointInTime": "2017-07-14T05:35:31.503Z"
}
}
Edit:
You could try the Microsoft.Azure.Management.SQL NuGet package. Supported frameworks are .NET Framework 4.5.2 and Netstandard 1.4, based on the NetCore framework.
Edit 2:
Since the Microsoft.Azure.Management.SQL NuGet package is a prerelease version, please make sure you have the checkbox 'Include prerelease' checked.
Worked for me:
Upvotes: 3