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?
Asked
Active
Viewed 1,591 times
1
-
this looks similar: https://stackoverflow.com/questions/23464034/converting-a-blob-bacpac-to-bacpac-file-to-import-database-to-sql-server-azu?rq=1, probably if you create a blob trigger and use the DacServices.ImportBacpac() it should work. – hujtomi May 20 '19 at 21:16
-
you can also use the Azure REST api: https://learn.microsoft.com/en-us/rest/api/sql/databases%20-%20import%20export/createimportoperation – hujtomi May 20 '19 at 21:32
-
Thanks, guys. Looks like the first solution with DacServices works! – Arsen Aghajanyan May 21 '19 at 07:28
-
1@TamásHuj please consider posting this as an answer so people can upvote/mark as verified. – PerfectlyPanda May 21 '19 at 14:51
-
@SamaraSoucy-MSFT ok, I did it, thanks. – hujtomi May 21 '19 at 20:39
1 Answers
1
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."

hujtomi
- 1,540
- 2
- 17
- 23
-
Maybe you can answer this one as well: https://stackoverflow.com/questions/66311105/creating-azure-db-with-huge-backpac-files – CodeMonkey Feb 22 '21 at 08:51