SQL Server Automate the Upload of a .bak file to Azure

vxf3dgd4  于 2023-08-02  发布在  其他
关注(0)|答案(1)|浏览(98)

I'm very new to Azure and have been tasked with automating the process of taking an existing version of our database, converting it to the newer version and then uploading that to Azure.

The conversion is done, that parts easy, what I'm struggling with is getting a .bacpac file from SSMS using PowerShell. I know I can use the Export Data Tier Application function in SSMS to do this but I need it to be automated. From there I can use something like the following to actually upload the database:

https://blogs.msdn.microsoft.com/brunoterkaly/2013/09/26/how-to-export-an-on-premises-sql-server-database-to-windows-azure-storage/

I have looked around and cannot find a solution to this, or even know where to start.

sr4lhrrt

sr4lhrrt1#

You can create bacpac of your on-premises databases and locate them on a local folder (c:\MyBacpacs) using SQLPackage .

sqlpackage.exe /Action:Export /SourceServerName:. /sdn:"DB_Foo" /tf:"c:\MyBacpacs\DB_Foo.bacpac"

You can then use AzCopy to upload bacpacs to Azure BLOB storage

AzCopy /Source:"c:\MyBacpacs" /Dest:"https://exampleaccount.blob.core.windows.net/bacpacs" /DestKey:storageaccountkey /Pattern:*.bacpac

相关问题