Arsen Aghajanyan
Arsen Aghajanyan

Reputation: 31

Is it possible to programmatically restore bacpac/bak from blob storage into azure sql with C#

Is it possible to somehow create an azure function which will restore an azure sql database whenever a new bacpac/bak file is created in the blob storage?

Upvotes: 1

Views: 2026

Answers (1)

hujtomi
hujtomi

Reputation: 1570

You can create an azure function with a blob trigger and in your C# code you can us the DacServices.ImportBacpac method. Here is a similar question: converting a blob (.bacpac) to .bacpac file to import database to SQL Server Azure?

And here is the MS docs: https://learn.microsoft.com/en-us/dotnet/api/microsoft.sqlserver.dac.dacservices.importbacpac?view=sql-dacfx-140.3881.1

As an alternative solution you can also make an Azure REST API call. https://learn.microsoft.com/en-us/rest/api/sql/databases%20-%20import%20export/createimportoperation "Creates an import operation that imports a bacpac into an existing database. The existing database must be empty."

Upvotes: 2

Related Questions